diff --git a/types/stream-csv-as-json/index.d.ts b/types/stream-csv-as-json/index.d.ts new file mode 100644 index 0000000000..8f9fb4d0ce --- /dev/null +++ b/types/stream-csv-as-json/index.d.ts @@ -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 +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +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; + } + } +} diff --git a/types/stream-csv-as-json/stream-csv-as-json-tests.ts b/types/stream-csv-as-json/stream-csv-as-json-tests.ts new file mode 100644 index 0000000000..6007d19205 --- /dev/null +++ b/types/stream-csv-as-json/stream-csv-as-json-tests.ts @@ -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(); +} diff --git a/types/stream-csv-as-json/tsconfig.json b/types/stream-csv-as-json/tsconfig.json new file mode 100644 index 0000000000..d705f46cca --- /dev/null +++ b/types/stream-csv-as-json/tsconfig.json @@ -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"] +} diff --git a/types/stream-csv-as-json/tslint.json b/types/stream-csv-as-json/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/stream-csv-as-json/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }