Skip to content

Latest commit

 

History

History
 
 

jid

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

JID

XMPP identifiers (JID) for JavaScript

JID type local @ domain / resource usage
domain wonderland.net servers and components
bare alice @ wonderland.net users
full alice @ wonderland.net / rabbithole user resource (device)

https://en.wikipedia.org/wiki/XMPP#Decentralization_and_addressing

Install

npm install @xmpp/jid or yarn add @xmpp/jid

Usage

var jid = require('@xmpp/jid')

/*
 * All return an instance of jid.JID
 */
var addr = jid('[email protected]/rabbithole')
var addr = jid('alice', 'wonderland.net', 'rabbithole')

addr instanceof jid.JID // true

// domain JIDs are created passing the domain as the first argument
var addr = jid('wonderland.net')

/*
 * 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() // [email protected]/rabbithole
addr.bare() // returns a JID without resource

addr.equals(some_jid) // returns true if the two JIDs are equal, false otherwise
// same as
jid.equal(addr, some_jid)

Escaping

The XEP-0106 defines a method to escape and unescape characters that aren't allowed in the local part of the JID. This library fully implement it.

const addr = jid('[email protected]', 'xmpp.net')
addr.toString() // contact\[email protected]
// for display purpose only
addr.toString(true) // [email protected]@xmpp.net

For user input, use

jid('[email protected]', 'xmpp.net')
// over
jid('[email protected]@xmpp.net')

References

Deprecated