npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

xmpp-jid

v1.3.0

Published

Parse XMPP URIs

Downloads

4,934

Readme

XMPP-JID

Parse and Create XMPP JIDs

What is this?

The xmpp-jid module is for both parsing and creating XMPP addresses, which are called JIDs.

A JID often looks a lot like an email address with a user@host form, but there's more to it:

        full JID
/                       \
[local@]domain[/resource]
\            /
   bare JID

A JID can be composed of a local part, a domain part, and a resource part. The domain part is mandatory for all JIDs, and can even stand alone (e.g., as the address for a server).

The combination of a local (user) part and a domain is called a "bare JID", and it is used to identitfy a particular account at a server.

A JID that includes a resource is called a "full JID", and it is used to identify a particular client connection (i.e., a specific connection for the associated "bare JID" account).

Installing

$ npm install xmpp-jid

Usage

var jid = require('xmpp-jid');

var res = new jid.JID('[email protected]');
// or jid.create('[email protected]/res');
//
// res == {
//     local: 'user',
//     domain: 'example.com',
//     resource: 'res',
//     bare: '[email protected]',
//     full: '[email protected]/res',
//     unescapedLocal: 'user',
//     unescapedBare: '[email protected]',
//     unescapedFull: '[email protected]/res',
//     prepped: true
// }

StringPrep

Correctly working with JIDs can be slightly tricky thanks to Unicode, which requires us to use StringPrep to normalize the individual parts of a JID so that we can safely use them in comparisons. Unfortunately, we don't have always have access to StringPrep, so all JID objects are marked with a prepped attribute indicating if StringPrep has been applied.

To enable full StringPrep application, also add the node-stringprep module to your dependcies:

npm i node-stringprep

Comparisons between JIDs should only be trusted if both JIDs have prepped set to true.

The provided equal function can be used to reliably check that two JIDs are equivalent, with an optional parameter to disable the prepped flag check.

jid.equal('[email protected]/res', '[email protected]/res');
// true, if StringPrep is available


jid.equal('[email protected]/res', '[email protected]/res', false);
// true

jid.equal('[email protected]/res1', '[email protected]/res2');
// false, full JIDs don't match

The same applies for the provided equalBare function, which checks that two JIDs have the same "bare JID" form (i.e., it ignores differences in resources).

jid.equal('[email protected]/resource1', '[email protected]/resource2');
// true, if StringPrep is available


jid.equal('[email protected]/resource1', '[email protected]/resource2', false);
// true

jid.equal('[email protected]/resource1', '[email protected]/resource2', false);
// false, bare JIDs don't match

Even in the browser, there are ways to ensure that StringPrep is applied by getting your XMPP server to do the prepping for you. This is already done for the standard stanza routing attributes ("to" and "from"), and other places where the server can reliably ensure that the JIDs are prepped (e.g., roster entries).

In other cases, you may need to use XEP-0328: JID Prep to explicity ask your server to prep a given JID.

JID Escaping

XEP-0106: JID Escaping allows you to create JIDs using characters typically prohibited in the local part: "' <:>&@

When creating a new JID by specifying the local part separately (e.g. new JID('localpart', 'domain')), the local part will be automatically escaped where necessary.

(Using new JID('local@domain') will not escape the local part, as that is assumed to already be the escaped form.)

These fields on the resulting JID object yield the human-presentable, unescaped forms:

  • unescapedLocal
  • unescapedBare
  • unescapedFull

If you show the unescaped forms anywhere to a user, you should do so everywhere to be consistent and prevent potential security issues related to JID spoofing.

License

MIT

Created By

If you like this, follow @lancestout on twitter.