Merge pull request #14702 from PJakcson/xmpp-jid

Added definitions for @xmpp/jid
This commit is contained in:
Zhengbo Li
2017-02-17 11:01:23 -08:00
committed by GitHub
5 changed files with 124 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
// Type definitions for @xmpp/jid 0.0
// Project: github.com/node-xmpp/node-xmpp/
// Definitions by: PJakcson <https://github.com/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): JID;
export {JID} from './lib/JID';
export declare function equal(a: JID, b: JID): boolean;
export declare function is(a: any): boolean;
+46
View File
@@ -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;
}
+22
View File
@@ -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"
]
}
+3
View File
@@ -0,0 +1,3 @@
{
"extends": "../tslint.json"
}
+40
View File
@@ -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