From 91df45dd75e6441306b2caaf6661285e42bc3974 Mon Sep 17 00:00:00 2001 From: Andy Date: Fri, 24 Mar 2017 09:32:36 -0700 Subject: [PATCH] Move types that were in `xmpp-jid` to `xmpp__jid`, since they are for `@xmpp/jid`, not `xmpp-jid`. (#15279) * Move types that were in `xmpp-jid` to `xmpp__jid`, since they are for `@xmpp/jid`, not `xmpp-jid`. * Update comment --- xmpp__jid/index.d.ts | 62 ++++++++++++++++++++++++++++++++++++ xmpp__jid/tsconfig.json | 22 +++++++++++++ xmpp__jid/tslint.json | 1 + xmpp__jid/xmpp__jid-tests.ts | 40 +++++++++++++++++++++++ 4 files changed, 125 insertions(+) create mode 100644 xmpp__jid/index.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..b132680c72 --- /dev/null +++ b/xmpp__jid/index.d.ts @@ -0,0 +1,62 @@ +// 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 + +// TODO: Once TS2.3 is released, +// https://github.com/Microsoft/TypeScript/issues/14819 should be fixed. +// Then, upgrade this package's typescript version to 2.3 and +// Remove the `declare module` wrapper. +// tslint:disable-next-line no-single-declare-module +declare module "@xmpp/jid" { + export function createJID(local: string, domain: string, resource: string): JID; + export function equal(a: JID, b: JID): boolean; + export function is(a: any): boolean; + + /** + * Created by marcneumann on 17.02.17. + */ + export 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..b9262f6dfb --- /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..2221e40e4a --- /dev/null +++ b/xmpp__jid/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } \ No newline at end of file diff --git a/xmpp__jid/xmpp__jid-tests.ts b/xmpp__jid/xmpp__jid-tests.ts new file mode 100644 index 0000000000..1652e054a7 --- /dev/null +++ b/xmpp__jid/xmpp__jid-tests.ts @@ -0,0 +1,40 @@ +import {JID} from '@xmpp/jid'; + +/* + * 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 + +const some_jid = new JID('is', 'a', 'test'); +addr.equals(some_jid); // returns true if the two JIDs are equal, false otherwise