From 4516213693a20f697704b0917add24785b7ce256 Mon Sep 17 00:00:00 2001 From: Marc Neumann Date: Fri, 17 Feb 2017 16:13:24 +0100 Subject: [PATCH 1/3] Added @xmpp/jid definitions. --- xmpp-jid/index.d.ts | 13 +++++++++++ xmpp-jid/lib/JID.d.ts | 46 ++++++++++++++++++++++++++++++++++++++ xmpp-jid/tsconfig.json | 22 ++++++++++++++++++ xmpp-jid/tslint.json | 3 +++ xmpp-jid/xmpp-jid-tests.ts | 40 +++++++++++++++++++++++++++++++++ 5 files changed, 124 insertions(+) create mode 100644 xmpp-jid/index.d.ts create mode 100644 xmpp-jid/lib/JID.d.ts create mode 100644 xmpp-jid/tsconfig.json create mode 100644 xmpp-jid/tslint.json create mode 100644 xmpp-jid/xmpp-jid-tests.ts diff --git a/xmpp-jid/index.d.ts b/xmpp-jid/index.d.ts new file mode 100644 index 0000000000..18b55b4f43 --- /dev/null +++ b/xmpp-jid/index.d.ts @@ -0,0 +1,13 @@ +// Type definitions for @xmpp/jid 0.0 +// Project: github.com/node-xmpp/node-xmpp/ +// Definitions by: PJakcson +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 +import {JID} from './lib/JID'; + +export declare function createJID(local: string, domain: string, resource: string); + +export {JID} from './lib/JID'; + +export declare function equal(a: JID, b: JID); +export declare function is(a: any); diff --git a/xmpp-jid/lib/JID.d.ts b/xmpp-jid/lib/JID.d.ts new file mode 100644 index 0000000000..a1d2558b30 --- /dev/null +++ b/xmpp-jid/lib/JID.d.ts @@ -0,0 +1,46 @@ +/** + * Created by marcneumann on 17.02.17. + */ + +export declare class JID { + local: string; + domain: string; + resource: string; + + constructor(local: string, domain?: string, resource?: string); + + parseJID(jid: string): void; + + toString(unescape?: any): string; + + /** + * Convenience method to distinguish users + **/ + bare(): JID; + + /** + * Comparison function + **/ + equals(other: JID): boolean; + + /** + * http://xmpp.org/rfcs/rfc6122.html#addressing-localpart + **/ + setLocal(local: string, escape?: any): void; + + getLocal(unescape?: any): string; + + /** + * http://xmpp.org/rfcs/rfc6122.html#addressing-domain + */ + setDomain(value: string): void; + + getDomain(): string; + + /** + * http://xmpp.org/rfcs/rfc6122.html#addressing-resourcepart + */ + setResource(value: string): void; + + getResource(): string; +} diff --git a/xmpp-jid/tsconfig.json b/xmpp-jid/tsconfig.json new file mode 100644 index 0000000000..f4d02187a2 --- /dev/null +++ b/xmpp-jid/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", + "xmpp-jid-tests.ts" + ] +} \ No newline at end of file diff --git a/xmpp-jid/tslint.json b/xmpp-jid/tslint.json new file mode 100644 index 0000000000..ec365f164b --- /dev/null +++ b/xmpp-jid/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "../tslint.json" +} diff --git a/xmpp-jid/xmpp-jid-tests.ts b/xmpp-jid/xmpp-jid-tests.ts new file mode 100644 index 0000000000..16d027b9bb --- /dev/null +++ b/xmpp-jid/xmpp-jid-tests.ts @@ -0,0 +1,40 @@ +import {JID} from './index'; + +/* + * All return an instance of JID.JID, the new operator is optional. + */ +let addr = new JID('alice@wonderland.net/rabbithole') // OK +addr = new JID('alice', 'wonderland.net', 'rabbithole') // BEST; see section on escaping below + +/* + * local + */ +addr.local = 'alice' +addr.local // alice +// same as +addr.setLocal('alice') +addr.getLocal() // alice + +/* + * domain + */ +addr.domain = 'wonderland.net' +addr.domain // wonderland.net +// same as +addr.setDomain('wonderland.net') +addr.getDomain() // wonderland.net + +/* + * resource + */ +addr.resource = 'rabbithole' +addr.resource // rabbithole +// same as +addr.setResource('rabbithole') +addr.getResource() // rabbithole + +addr.toString() // alice@wonderland.net/rabbithole +addr.bare() // returns a JID without resource + +let some_jid = new JID('is', 'a', 'test'); +addr.equals(some_jid) // returns true if the two JIDs are equal, false otherwise From 534c9568dcb09afd421316cced200bc50079b258 Mon Sep 17 00:00:00 2001 From: Marc Neumann Date: Fri, 17 Feb 2017 16:19:48 +0100 Subject: [PATCH 2/3] Cleaned up the tests. --- xmpp-jid/xmpp-jid-tests.ts | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/xmpp-jid/xmpp-jid-tests.ts b/xmpp-jid/xmpp-jid-tests.ts index 16d027b9bb..6b33b2c349 100644 --- a/xmpp-jid/xmpp-jid-tests.ts +++ b/xmpp-jid/xmpp-jid-tests.ts @@ -3,38 +3,38 @@ import {JID} from './index'; /* * All return an instance of JID.JID, the new operator is optional. */ -let addr = new JID('alice@wonderland.net/rabbithole') // OK -addr = new JID('alice', 'wonderland.net', 'rabbithole') // BEST; see section on escaping below +let addr = new JID('alice@wonderland.net/rabbithole'); // OK +addr = new JID('alice', 'wonderland.net', 'rabbithole'); // BEST; see section on escaping below /* * local */ -addr.local = 'alice' -addr.local // alice +addr.local = 'alice'; +addr.local; // alice // same as -addr.setLocal('alice') -addr.getLocal() // alice +addr.setLocal('alice'); +addr.getLocal(); // alice /* * domain */ -addr.domain = 'wonderland.net' -addr.domain // wonderland.net +addr.domain = 'wonderland.net'; +addr.domain; // wonderland.net // same as -addr.setDomain('wonderland.net') -addr.getDomain() // wonderland.net +addr.setDomain('wonderland.net'); +addr.getDomain(); // wonderland.net /* * resource */ -addr.resource = 'rabbithole' -addr.resource // rabbithole +addr.resource = 'rabbithole'; +addr.resource; // rabbithole // same as -addr.setResource('rabbithole') -addr.getResource() // rabbithole +addr.setResource('rabbithole'); +addr.getResource(); // rabbithole -addr.toString() // alice@wonderland.net/rabbithole -addr.bare() // returns a JID without resource +addr.toString(); // alice@wonderland.net/rabbithole +addr.bare(); // returns a JID without resource let some_jid = new JID('is', 'a', 'test'); -addr.equals(some_jid) // returns true if the two JIDs are equal, false otherwise +addr.equals(some_jid); // returns true if the two JIDs are equal, false otherwise From fe4f2b045e9202a9bf65df01386042af44d664bc Mon Sep 17 00:00:00 2001 From: Marc Neumann Date: Fri, 17 Feb 2017 16:24:47 +0100 Subject: [PATCH 3/3] Added missing return types. --- xmpp-jid/index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xmpp-jid/index.d.ts b/xmpp-jid/index.d.ts index 18b55b4f43..678e306abc 100644 --- a/xmpp-jid/index.d.ts +++ b/xmpp-jid/index.d.ts @@ -5,9 +5,9 @@ // TypeScript Version: 2.1 import {JID} from './lib/JID'; -export declare function createJID(local: string, domain: string, resource: string); +export declare function createJID(local: string, domain: string, resource: string): JID; export {JID} from './lib/JID'; -export declare function equal(a: JID, b: JID); -export declare function is(a: any); +export declare function equal(a: JID, b: JID): boolean; +export declare function is(a: any): boolean;