Added typings for stream-csv-as-json 1.0.

This commit is contained in:
Eugene Lazutkin
2018-06-25 19:39:32 -05:00
parent 7cc9924be7
commit 9e07aea598
4 changed files with 212 additions and 0 deletions

128
types/stream-csv-as-json/index.d.ts vendored Normal file
View File

@@ -0,0 +1,128 @@
// Type definitions for stream-csv-as-json 1.0
// Project: https://github.com/uhop/stream-csv-as-json#readme
// Definitions by: Eugene Lazutkin <https://github.com/uhop>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
declare module 'stream-csv-as-json' {
import * as Parser from 'stream-csv-as-json/Parser';
export = make;
function make(options?: Parser.ParserOptions): Parser;
type ParserClass = Parser;
type ParserType = typeof Parser;
namespace make {
type Parser = ParserClass;
const Parser: ParserType;
const parser: (options?: Parser.ParserOptions) => Parser;
}
}
declare module 'stream-csv-as-json/AsObjects' {
import { TransformOptions, Transform } from 'stream';
import * as Chain from 'stream-chain';
export = AsObjects;
class AsObjects extends Transform {
constructor(options?: AsObjects.AsObjectOptions);
}
namespace AsObjects {
interface AsObjectOptions extends TransformOptions {
packValues?: boolean;
packStrings?: boolean;
streamValues?: boolean;
streamStrings?: boolean;
useValues?: boolean;
useStringValues?: boolean;
fieldPrefix?: string;
}
function make(options?: AsObjects.AsObjectOptions): AsObjects;
namespace make {
type Constructor = AsObjects;
const Constructor: typeof AsObjects;
}
function asObjects(options?: AsObjects.AsObjectOptions): AsObjects;
namespace asObjects {
type Constructor = AsObjects;
const Constructor: typeof AsObjects;
}
function withParser(options?: AsObjects.AsObjectOptions): Chain;
}
}
declare module 'stream-csv-as-json/Parser' {
import { Transform, TransformOptions } from 'stream';
export = Parser;
class Parser extends Transform {
constructor(options?: Parser.ParserOptions);
}
namespace Parser {
interface ParserOptions extends TransformOptions {
packValues?: boolean;
packStrings?: boolean;
streamValues?: boolean;
streamStrings?: boolean;
separator?: string;
}
function make(options?: ParserOptions): Parser;
namespace make {
type Constructor = Parser;
const Constructor: typeof Parser;
}
function parser(options?: ParserOptions): Parser;
namespace parser {
type Constructor = Parser;
const Constructor: typeof Parser;
}
}
}
declare module 'stream-csv-as-json/Stringer' {
import { Transform, TransformOptions } from 'stream';
export = Stringer;
class Stringer extends Transform {
constructor(options?: Stringer.StringerOptions);
}
namespace Stringer {
interface StringerOptions extends TransformOptions {
useValues?: boolean;
useStringValues?: boolean;
separator?: string;
}
function make(options?: StringerOptions): Stringer;
namespace make {
type Constructor = Stringer;
const Constructor: typeof Stringer;
}
function stringer(options?: StringerOptions): Stringer;
namespace stringer {
type Constructor = Stringer;
const Constructor: typeof Stringer;
}
}
}

View File

@@ -0,0 +1,68 @@
import * as make from 'stream-csv-as-json';
import * as Parser from 'stream-csv-as-json/Parser';
import * as Stringer from 'stream-csv-as-json/Stringer';
import * as AsObjects from 'stream-csv-as-json/AsObjects';
const used = (array: any[]) => array.forEach(value => console.log(!!value));
{
// creating parser with the main module
const p1 = make();
const p2 = new make.Parser();
const p3 = make.parser();
const p4 = make({});
const p5 = new make.Parser({});
const p6 = make.parser({});
const p7: make.Parser = make();
const p8: make.Parser = new make.Parser();
const p9: make.Parser = make.parser();
used([p1, p2, p3, p4, p5, p6, p7, p8, p9]);
}
{
// Parser tests
const p1: Parser = new Parser({ packValues: false });
const p2: Parser = Parser.make({ separator: '/' });
const p3: Parser = Parser.parser({ streamValues: false });
const p4: Parser.make.Constructor = Parser.make({ packValues: false, packStrings: true });
const p5: Parser.parser.Constructor = Parser.parser({ packValues: false, packStrings: true, streamStrings: false });
used([p1, p2, p3, p4, p5]);
}
{
// Stringer tests
const s1: Stringer = new Stringer();
const s2: Stringer = Stringer.make({ useValues: true });
const s3: Stringer = Stringer.stringer({ useStringValues: true });
const s4: Stringer.make.Constructor = Stringer.make();
const s5: Stringer.stringer.Constructor = Stringer.stringer();
used([s1, s2, s3, s4, s5]);
}
{
// StreamValues tests
const parser: Parser = new Parser();
const s1: AsObjects = new AsObjects();
const s2: AsObjects = AsObjects.make();
const s3: AsObjects = AsObjects.asObjects();
const s4: AsObjects.make.Constructor = AsObjects.make();
const s5: AsObjects.asObjects.Constructor = AsObjects.asObjects();
used([s1, s2, s3, s4, s5]);
parser.pipe(new AsObjects({ fieldPrefix: 'x' }));
parser.pipe(AsObjects.make({ useStringValues: true }));
parser.pipe(AsObjects.asObjects());
AsObjects.withParser();
}

View File

@@ -0,0 +1,15 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": ["index.d.ts", "stream-csv-as-json-tests.ts"]
}

View File

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