diff --git a/types/ndjson/index.d.ts b/types/ndjson/index.d.ts new file mode 100644 index 0000000000..0fcf165940 --- /dev/null +++ b/types/ndjson/index.d.ts @@ -0,0 +1,19 @@ +// Type definitions for ndjson 1.5 +// Project: https://github.com/maxogden/ndjson +// Definitions by: Junxiao Shi +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +import { ThroughStream } from "through"; +import { DuplexOptions, Transform } from "stream"; + +export interface ParseOptions { + strict?: boolean; +} + +export function parse(opts?: ParseOptions): ThroughStream; + +export function serialize(opts?: DuplexOptions): Transform; + +export function stringify(opts?: DuplexOptions): Transform; diff --git a/types/ndjson/ndjson-tests.ts b/types/ndjson/ndjson-tests.ts new file mode 100644 index 0000000000..924a6dd428 --- /dev/null +++ b/types/ndjson/ndjson-tests.ts @@ -0,0 +1,15 @@ +import * as ndjson from "ndjson"; +import * as fs from "fs"; + +let parser = ndjson.parse(); +parser = ndjson.parse({ strict: true }); + +fs.createReadStream("data.txt") + .pipe(parser) + .on("data", (obj) => undefined); + +let serialize = ndjson.serialize(); +serialize = ndjson.stringify({ encoding: "ascii" }); +serialize.on("data", (line) => undefined); +serialize.write({ foo: "bar" }); +serialize.end(); diff --git a/types/ndjson/tsconfig.json b/types/ndjson/tsconfig.json new file mode 100644 index 0000000000..ee4376489f --- /dev/null +++ b/types/ndjson/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "ndjson-tests.ts" + ] +} diff --git a/types/ndjson/tslint.json b/types/ndjson/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/ndjson/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }