ndjson: initial definition (#43073)

This commit is contained in:
Junxiao Shi 2020-03-22 17:09:23 -04:00 committed by GitHub
parent 043b939aa2
commit 0fbd4beb75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 0 deletions

19
types/ndjson/index.d.ts vendored Normal file
View File

@ -0,0 +1,19 @@
// Type definitions for ndjson 1.5
// Project: https://github.com/maxogden/ndjson
// Definitions by: Junxiao Shi <https://github.com/yoursunny>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
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;

View File

@ -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();

View File

@ -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"
]
}

1
types/ndjson/tslint.json Normal file
View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }