diff --git a/types/json_ml/index.d.ts b/types/json_ml/index.d.ts new file mode 100644 index 0000000000..ba53b84cb4 --- /dev/null +++ b/types/json_ml/index.d.ts @@ -0,0 +1,20 @@ +// Type definitions for json_ml 0.0 +// Project: https://github.com/59naga/json-ml +// Definitions by: Alan Plum +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +export type Node = string | Element; +export type SimpleElement = [string, Attributes] | [string]; +export interface NodeList extends Array {} +export type Element = SimpleElement & NodeList; +export interface Attributes { + [key: string]: string; +} +export function parse(xml: string, trim?: boolean): Node[]; +export function stringify( + object: Node[], + replacer?: ((node: Cheerio) => any) | null, + indent?: number +): string; diff --git a/types/json_ml/json_ml-tests.ts b/types/json_ml/json_ml-tests.ts new file mode 100644 index 0000000000..ecc84d9d8b --- /dev/null +++ b/types/json_ml/json_ml-tests.ts @@ -0,0 +1,12 @@ +/// +import { Attributes, Element, Node, parse, stringify } from "json_ml"; + +const nodes: Node[] = parse("
  • hello
"); +const node1: Node = nodes[0]; +if (typeof node1 !== "string") { + const el: Element = node1; + const attrs = el[1] as Attributes; + console.log(el[0], attrs); +} + +console.log(stringify(nodes, el => (el.is("li") ? null : el), 2)); diff --git a/types/json_ml/tsconfig.json b/types/json_ml/tsconfig.json new file mode 100644 index 0000000000..951405762a --- /dev/null +++ b/types/json_ml/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": ["index.d.ts", "json_ml-tests.ts"] +} diff --git a/types/json_ml/tslint.json b/types/json_ml/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/json_ml/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }