mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-05 07:17:04 +00:00
Add json_ml
This commit is contained in:
Vendored
+20
@@ -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;
|
||||
@@ -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));
|
||||
@@ -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"]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user