diff --git a/ltx/index.d.ts b/ltx/index.d.ts new file mode 100644 index 0000000000..c5794f12bb --- /dev/null +++ b/ltx/index.d.ts @@ -0,0 +1,17 @@ +// Type definitions for ltx 2.6 +// Project: github.com/node-xmpp/ltx/ +// Definitions by: PJakcson +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +export {Element} from './lib/Element' +export {nameEqual, attrsEqual, childrenEqual, equal} from './lib/equal'; +export {isNode, isElement, isText} from './lib/is'; +export {clone} from './lib/clone'; +export {createElement} from './lib/createElement'; +export {escapeXML, unescapeXML, escapeXMLText, unescapeXMLText} from './lib/escape'; +export {Parser} from './lib/Parser'; +export {parse} from './lib/parse'; +export {tag} from './lib/tag'; +export {tagString} from './lib/tagString'; +export {stringify} from './lib/stringify'; diff --git a/ltx/lib/Element.d.ts b/ltx/lib/Element.d.ts new file mode 100644 index 0000000000..d0f50ae783 --- /dev/null +++ b/ltx/lib/Element.d.ts @@ -0,0 +1,119 @@ +/** + * Element + * + * Attributes are in the element.attrs object. Children is a list of + * either other Elements or Strings for text content. + **/ +export declare class Element { + name: string; + parent: Element; + children: Element[]; + attrs: any; + + constructor(name: string, attrs?: any); + + /** + * if (element.is('message', 'jabber:client')) ... + **/ + is(name: string, xmlns?: any): boolean; + + /** + * without prefix. + */ + getName(): string; + + /** + * retrieves the namespace of the current element, upwards recursively + **/ + getNS(): any; + + /** + * find the namespace to the given prefix, upwards recursively + **/ + findNS(prefix: string): any; + + /** + * Recursiverly gets all xmlns defined, in the form of {url:prefix} + **/ + getXmlns(): any; + + setAttrs(attrs: any): void; + + /** + * xmlns can be null, returns the matching attribute. + **/ + getAttr(name: string, xmlns?: any): any; + + /** + * xmlns can be null + **/ + getChild(name: string, xmlns?: any): Element; + + /** + * xmlns can be null + **/ + getChildren(name: string, xmlns?: any): Element[]; + + /** + * xmlns and recursive can be null + **/ + getChildByAttr(attr: any, val: any, xmlns?: any, recursive?: any): Element; + + + /** + * xmlns and recursive can be null + **/ + getChildrenByAttr(attr: any, val: any, xmlns?: any, recursive?: any): Element[]; + + getText(): string; + + getChildText(name: string, xmlns: any): string; + + /** + * Return all direct descendents that are Elements. + * This differs from `getChildren` in that it will exclude text nodes, + * processing instructions, etc. + */ + getChildElements(): Element[]; + + /** returns uppermost parent */ + root(): Element; + + tree(): Element; + + /** just parent or itself */ + up(): Element; + + /** create child node and return it */ + c(name: string, attrs?: any): Element; + + /** add text node and return element */ + t(text: string): Element; + + /** + * Either: + * el.remove(childEl) + * el.remove('author', 'urn:...') + */ + remove(el: Element, xmlns?: any): Element; + + clone(): Element; + + text(val: string): string; + + attr(attr: any, val: any): any; + + toString(): string; + + toJSON(): any; + + write(writer: any): void; + + nameEquals(el: Element): boolean; + + attrsEquals(el: Element): boolean; + + childrenEquals(el: Element): boolean; + + equals(el: Element): boolean; +} diff --git a/ltx/lib/Parser.d.ts b/ltx/lib/Parser.d.ts new file mode 100644 index 0000000000..3af418d21f --- /dev/null +++ b/ltx/lib/Parser.d.ts @@ -0,0 +1,5 @@ +/// +import {EventEmitter} from 'events'; +export declare class Parser extends EventEmitter { + constructor(options?: any); +} diff --git a/ltx/lib/clone.d.ts b/ltx/lib/clone.d.ts new file mode 100644 index 0000000000..41193a3f40 --- /dev/null +++ b/ltx/lib/clone.d.ts @@ -0,0 +1 @@ +export declare function clone(el: any): any; diff --git a/ltx/lib/createElement.d.ts b/ltx/lib/createElement.d.ts new file mode 100644 index 0000000000..2deead1663 --- /dev/null +++ b/ltx/lib/createElement.d.ts @@ -0,0 +1,2 @@ +import {Element} from './Element'; +export declare function createElement(name: string, attrs: any): Element; diff --git a/ltx/lib/equal.d.ts b/ltx/lib/equal.d.ts new file mode 100644 index 0000000000..520555e098 --- /dev/null +++ b/ltx/lib/equal.d.ts @@ -0,0 +1,4 @@ +export declare function nameEqual(a: any, b: any): boolean; +export declare function attrsEqual(a: any, b: any): boolean; +export declare function childrenEqual(a: any, b: any): boolean; +export declare function equal(a: any, b: any): boolean; diff --git a/ltx/lib/escape.d.ts b/ltx/lib/escape.d.ts new file mode 100644 index 0000000000..4bc45c223a --- /dev/null +++ b/ltx/lib/escape.d.ts @@ -0,0 +1,4 @@ +export declare function escapeXML(s: string): string; +export declare function unescapeXML(s: string): string; +export declare function escapeXMLText(s: string): string; +export declare function unescapeXMLText(s: string): string; diff --git a/ltx/lib/is.d.ts b/ltx/lib/is.d.ts new file mode 100644 index 0000000000..6515d23f80 --- /dev/null +++ b/ltx/lib/is.d.ts @@ -0,0 +1,3 @@ +export declare function isNode(el: any): boolean; +export declare function isElement(el: any): boolean; +export declare function isText(el: any): boolean; diff --git a/ltx/lib/parse.d.ts b/ltx/lib/parse.d.ts new file mode 100644 index 0000000000..cc4073113a --- /dev/null +++ b/ltx/lib/parse.d.ts @@ -0,0 +1 @@ +export declare function parse(data: any, options?: any): any; diff --git a/ltx/lib/stringify.d.ts b/ltx/lib/stringify.d.ts new file mode 100644 index 0000000000..770f7d324f --- /dev/null +++ b/ltx/lib/stringify.d.ts @@ -0,0 +1 @@ +export declare function stringify(el: any, indent: any, level: any): string; diff --git a/ltx/lib/tag.d.ts b/ltx/lib/tag.d.ts new file mode 100644 index 0000000000..8bbcb6fe7b --- /dev/null +++ b/ltx/lib/tag.d.ts @@ -0,0 +1 @@ +export declare function tag(d: any): any; diff --git a/ltx/lib/tagString.d.ts b/ltx/lib/tagString.d.ts new file mode 100644 index 0000000000..44036ce037 --- /dev/null +++ b/ltx/lib/tagString.d.ts @@ -0,0 +1 @@ +export declare function tagString(d: any): string; diff --git a/ltx/ltx-tests.ts b/ltx/ltx-tests.ts new file mode 100644 index 0000000000..7ed19d606a --- /dev/null +++ b/ltx/ltx-tests.ts @@ -0,0 +1,19 @@ +import * as ltx from './index'; + +ltx.parse(''); + +let p = new ltx.Parser(); + +p.on('tree', function (ignored) { +}); + +p.on('error', function (ignored) { +}); + + +let el = new ltx.Element('root').c('children'); +el.c('child', {age: 5}).t('Hello').up() + .c('child', {age: 7}).t('Hello').up() + .c('child', {age: 99}).t('Hello').up(); + +el.root().toString(); diff --git a/ltx/tsconfig.json b/ltx/tsconfig.json new file mode 100644 index 0000000000..28beec26d4 --- /dev/null +++ b/ltx/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "ltx-tests.ts" + ] +} diff --git a/ltx/tslint.json b/ltx/tslint.json new file mode 100644 index 0000000000..ec365f164b --- /dev/null +++ b/ltx/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "../tslint.json" +}