try {
    var StringPrep = require('node-stringprep').StringPrep;
    var c = function(n) {
	var p = new StringPrep(n);
	return function(s) {
	    return p.prepare(s);
	};
    };
    var nameprep = c('nameprep');
    var nodeprep = c('nodeprep');
    var resourceprep = c('resourceprep');
} catch(ex) {
    console.warn("Cannot use StringPrep bindings. You may need to `npm install node-stringprep'");
    var identity = function(a) { return a; };
    var nameprep = identity;
    var nodeprep = identity;
    var resourceprep = identity;
}

function JID(a, b, c) {
    if (a && b == null && c == null) {
        this.parseJID(a);
    } else if (b) {
        this.setUser(a);
        this.setDomain(b);
        this.setResource(c);
    } else
        throw 'Argument error';
}

JID.prototype.parseJID = function(s) {
    if (s.indexOf('@') >= 0) {
        this.setUser(s.substr(0, s.indexOf('@')));
        s = s.substr(s.indexOf('@') + 1);
    }
    if (s.indexOf('/') >= 0) {
        this.setResource(s.substr(s.indexOf('/') + 1));
        s = s.substr(0, s.indexOf('/'));
    }
    this.setDomain(s);
};

JID.prototype.toString = function() {
    var s = this.domain;
    if (this.user)
        s = this.user + '@' + s;
    if (this.resource)
        s = s + '/' + this.resource;
    return s;
};

/**
 * Convenience method to distinguish users
 **/
JID.prototype.bare = function() {
    if (this.resource)
        return new JID(this.user, this.domain, null);
    else
        return this;
};

/**
 * Comparison function
 **/
JID.prototype.equals = function(other) {
    return this.user == other.user &&
        this.domain == other.domain &&
        this.resource == other.resource;
};

/**
 * Setters that do stringprep normalization.
 **/
JID.prototype.setUser = function(user) {
    this.user = user && nodeprep(user);
};
JID.prototype.setDomain = function(domain) {
    this.domain = domain && nameprep(domain);
};
JID.prototype.setResource = function(resource) {
    this.resource = resource && resourceprep(resource);
};

exports.JID = JID;

@@ -59,16 +59,74 @@
 ngPrep;%0A
+    var toUnicode = require('node-stringprep').toUnicode;%0A
     var 
@@ -379,19 +379,20 @@
 %22Cannot 
-use
+load
  StringP
@@ -394,16 +394,22 @@
 ringPrep
+-0.1.0
  binding
@@ -502,24 +502,54 @@
 eturn a; %7D;%0A
+    var toUnicode = identity;%0A
     var name
@@ -1915,24 +1915,87 @@
 p(user);%0A%7D;%0A
+/**%0A * http://xmpp.org/rfcs/rfc6122.html#addressing-domain%0A */%0A
 JID.prototyp
@@ -2054,16 +2054,24 @@
 omain &&
+%0A       
  namepre
@@ -2078,16 +2078,88 @@
 p(domain
+.split(%22.%22).%0A                 map(toUnicode).%0A                 join(%22.%22)
 );%0A%7D;%0AJI

use new node-stringprep v0.1.0 IDN toUnicode()