From 2c00ac2a9acd41b26b0bd66268d96a36d97f751a Mon Sep 17 00:00:00 2001 From: Michael de Wit Date: Tue, 25 Feb 2020 23:05:55 +0100 Subject: [PATCH] Add types for sax-stream (#41339) --- types/sax-stream/index.d.ts | 54 ++++++++++++++++++++++++++++ types/sax-stream/sax-stream-tests.ts | 23 ++++++++++++ types/sax-stream/tsconfig.json | 23 ++++++++++++ types/sax-stream/tslint.json | 1 + 4 files changed, 101 insertions(+) create mode 100644 types/sax-stream/index.d.ts create mode 100644 types/sax-stream/sax-stream-tests.ts create mode 100644 types/sax-stream/tsconfig.json create mode 100644 types/sax-stream/tslint.json diff --git a/types/sax-stream/index.d.ts b/types/sax-stream/index.d.ts new file mode 100644 index 0000000000..33cafba64d --- /dev/null +++ b/types/sax-stream/index.d.ts @@ -0,0 +1,54 @@ +// Type definitions for sax-stream 1.3 +// Project: https://github.com/melitele/sax-stream +// Definitions by: Michael de Wit +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +import stream = require("stream"); + +declare namespace saxStream { + interface Options { + /** + * Name of the tag to select objects from XML file, an Array of tag names can be used - + * when multiple tags are specified stream pushes `{ tag, record }` tuples. + */ + tag: string | ReadonlyArray; + /** + * Size of internal transform stream buffer - defaults to 350 objects. + */ + highWaterMark?: number; + /** + * Default to false, if true makes sax parser to accept valid XML only. + */ + strict?: boolean; + /** + * Whether or not to trim text and comment nodes. + */ + trim?: boolean; + /** + * If true, then turn any whitespace into a single space. + */ + normalize?: boolean; + /** + * If true, then lowercase tag names and attribute names in loose mode, rather than uppercasing them. + */ + lowercase?: boolean; + /** + * If true, then namespaces are supported. + */ + xmlns?: boolean; + /** + * If false, then don't track line/col/position. + */ + trackPosition?: boolean; + /** + * If true, only parse predefined XML entities (&, ', >, <, and "). + */ + strictEntities?: boolean; + } +} + +declare function saxStream(options: saxStream.Options): stream.Transform; + +export = saxStream; diff --git a/types/sax-stream/sax-stream-tests.ts b/types/sax-stream/sax-stream-tests.ts new file mode 100644 index 0000000000..750b5fbd9a --- /dev/null +++ b/types/sax-stream/sax-stream-tests.ts @@ -0,0 +1,23 @@ +import saxStream = require('sax-stream'); + +// $ExpectType Transform +saxStream({ tag: '' }); + +// $ExpectType Transform +saxStream({ + tag: '', + highWaterMark: 1, + strict: true, + trim: true, + normalize: true, + lowercase: true, + xmlns: true, + trackPosition: true, + strictEntities: true +}); + +// $ExpectError +saxStream({}); + +// $ExpectError +saxStream(); diff --git a/types/sax-stream/tsconfig.json b/types/sax-stream/tsconfig.json new file mode 100644 index 0000000000..7376b45f71 --- /dev/null +++ b/types/sax-stream/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", + "sax-stream-tests.ts" + ] +} diff --git a/types/sax-stream/tslint.json b/types/sax-stream/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/sax-stream/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }