Add types for sax-stream (#41339)

This commit is contained in:
Michael de Wit
2020-02-25 23:05:55 +01:00
committed by GitHub
parent 4d1c31b542
commit 2c00ac2a9a
4 changed files with 101 additions and 0 deletions

54
types/sax-stream/index.d.ts vendored Normal file
View File

@@ -0,0 +1,54 @@
// Type definitions for sax-stream 1.3
// Project: https://github.com/melitele/sax-stream
// Definitions by: Michael de Wit <https://github.com/mjwwit>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
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<string>;
/**
* 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 (&amp;, &apos;, &gt;, &lt;, and &quot;).
*/
strictEntities?: boolean;
}
}
declare function saxStream(options: saxStream.Options): stream.Transform;
export = saxStream;

View File

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

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",
"sax-stream-tests.ts"
]
}

View File

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