Add json_ml

This commit is contained in:
Alan Plum
2018-12-02 22:35:24 +01:00
parent 29794318e9
commit b5ca615a98
4 changed files with 49 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
// Type definitions for json_ml 0.0
// Project: https://github.com/59naga/json-ml
// Definitions by: Alan Plum <https://github.com/pluma>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="cheerio" />
export type Node = string | Element;
export type SimpleElement = [string, Attributes] | [string];
export interface NodeList extends Array<Node> {}
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;
+12
View File
@@ -0,0 +1,12 @@
/// <reference types="node" />
import { Attributes, Element, Node, parse, stringify } from "json_ml";
const nodes: Node[] = parse("<ul><li>hello</li></ul>");
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));
+16
View File
@@ -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"]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }