🤖 Merge PR #64133 Add type definition for binary-xml package by @ChemiAtlow

This commit is contained in:
Chemi Atlow
2023-01-29 17:23:24 +02:00
committed by GitHub
parent b5dd59517c
commit 7b5627006f
4 changed files with 87 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
import * as BinaryXML from 'binary-xml';
// @ts-expect-error
new BinaryXML();
// @ts-expect-error
new BinaryXML('non-buffer');
new BinaryXML(Buffer.from('buffer'));
new BinaryXML(Buffer.from('buffer'), {});
new BinaryXML(Buffer.from('buffer'), { debug: false });
new BinaryXML(Buffer.from('buffer'), { debug: true });
// $ExpectType BinaryXmlParser
const parser = new BinaryXML(Buffer.from('buffer'));
// $ExpectType Document
const doc = parser.parse();

46
types/binary-xml/index.d.ts vendored Normal file
View File

@@ -0,0 +1,46 @@
// Type definitions for binary-xml 0.0
// Project: https://github.com/song940/binary-xml#readme
// Definitions by: ChemiAtlow <https://github.com/ChemiAtlow>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
interface Options {
debug?: boolean;
}
interface Attribute {
namespaceURI: string;
nodeType: number;
nodeName: string;
name: string;
value: any;
typedValue: {
value: number; type: string; rawType: number;
};
}
interface ChildNode {
namespaceURI: string;
nodeType: number;
nodeName: string;
attributes: Attribute[];
childNodes: ChildNode[];
}
interface Document {
attributes: Attribute[];
childNodes: ChildNode[];
namespaceURI: string | null;
nodeName: string | null;
nodeType: number;
}
declare class BinaryXmlParser {
constructor(buffer: Buffer, options?: Options);
parse(): Document;
}
declare const BinaryXML: typeof BinaryXmlParser;
export = BinaryXML;

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",
"binary-xml-tests.ts"
]
}

View File

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