Merge pull request #30707 from BendingBender/xmpp-js-jid

Update types for @xmpp/jid
This commit is contained in:
Mine Starks
2018-12-02 16:35:45 -08:00
committed by GitHub
2 changed files with 73 additions and 66 deletions
+46 -38
View File
@@ -1,55 +1,63 @@
// Type definitions for @xmpp/jid 0.0
// Type definitions for @xmpp/jid 0.6
// Project: https://github.com/node-xmpp/node-xmpp/
// Definitions by: PJakcson <https://github.com/PJakcson>
// BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
export function createJID(local: string, domain: string, resource: string): JID;
export function equal(a: JID, b: JID): boolean;
export function is(a: any): boolean;
export = jid;
/**
* Created by marcneumann on 17.02.17.
*/
export class JID {
local: string;
domain: string;
resource: string;
declare function jid(address: string): jid.JID;
declare function jid(local: string | undefined, domain: string, resource?: string): jid.JID;
constructor(local: string, domain?: string, resource?: string);
declare namespace jid {
function jid(address: string): JID;
function jid(local: string | undefined, domain: string, resource?: string): JID;
parseJID(jid: string): void;
function createJID(local: string | undefined, domain: string, resource?: string): JID;
function equal(a: JID, b: JID): boolean;
function detectEscape(local?: string): boolean;
function escapeLocal(local: string): string;
function unescapeLocal(local: string): string;
function parse(s: string): JID;
toString(unescape?: any): string;
class JID {
local: string;
domain: string;
resource: string;
/**
* Convenience method to distinguish users
*/
bare(): JID;
constructor(local: string | undefined, domain: string, resource?: string);
/**
* Comparison function
*/
equals(other: JID): boolean;
toString(unescape?: boolean): string;
/**
* http://xmpp.org/rfcs/rfc6122.html#addressing-localpart
*/
setLocal(local: string, escape?: any): void;
/**
* Convenience method to distinguish users
*/
bare(): JID;
getLocal(unescape?: any): string;
/**
* Comparison function
*/
equals(other: JID): boolean;
/**
* http://xmpp.org/rfcs/rfc6122.html#addressing-domain
*/
setDomain(value: string): void;
/**
* http://xmpp.org/rfcs/rfc6122.html#addressing-localpart
*/
setLocal(local: string, escape?: boolean): void;
getDomain(): string;
getLocal(unescape?: boolean): string;
/**
* http://xmpp.org/rfcs/rfc6122.html#addressing-resourcepart
*/
setResource(value: string): void;
/**
* http://xmpp.org/rfcs/rfc6122.html#addressing-domain
*/
setDomain(value: string): void;
getResource(): string;
getDomain(): string;
/**
* http://xmpp.org/rfcs/rfc6122.html#addressing-resourcepart
*/
setResource(value: string): void;
getResource(): string;
}
}
+27 -28
View File
@@ -1,40 +1,39 @@
import { JID } from '@xmpp/jid';
import jid = require('@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
let addr: jid.JID;
let str: string;
let bool: boolean;
addr = jid('alice@wonderland.net/rabbithole');
addr = jid('alice', 'wonderland.net', 'rabbithole');
/*
* local
*/
addr.local = 'alice';
addr.local; // alice
// same as
str = addr.local;
addr.setLocal('alice');
addr.getLocal(); // alice
addr.setLocal('alice', true);
str = addr.getLocal();
/*
* domain
*/
addr.domain = 'wonderland.net';
addr.domain; // wonderland.net
// same as
str = addr.domain;
addr.setDomain('wonderland.net');
addr.getDomain(); // wonderland.net
str = addr.getDomain();
/*
* resource
*/
addr.resource = 'rabbithole';
addr.resource; // rabbithole
// same as
str = addr.resource;
addr.setResource('rabbithole');
addr.getResource(); // rabbithole
str = addr.getResource();
addr.toString(); // alice@wonderland.net/rabbithole
addr.bare(); // returns a JID without resource
str = addr.toString();
str = addr.toString(true);
addr = addr.bare();
const some_jid = new JID('is', 'a', 'test');
addr.equals(some_jid); // returns true if the two JIDs are equal, false otherwise
bool = addr.equals(addr);
bool = jid.equal(addr, addr);
addr = jid.createJID('my', 'homies');
bool = jid.equal(addr, addr);
bool = jid.detectEscape('homies');
str = jid.escapeLocal('homies');
str = jid.unescapeLocal('homies');
addr = jid.parse('homies');