-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjid.js
90 lines (71 loc) · 2.05 KB
/
jid.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Generated by CoffeeScript 1.8.0
/*
This program is distributed under the terms of the MIT license.
Copyright 2012 - 2014 (c) Markus Kohlhase <mail@markus-kohlhase.de>
*/
/*
This is coffee-script fork of
https://github.com/astro/node-xmpp/blob/master/lib/xmpp/jid.js
*/
(function() {
var JID, toUnicode;
toUnicode = (typeof punycode !== "undefined" && punycode !== null ? punycode.toUnicode : void 0) || function(a) {
return a;
};
JID = (function() {
function JID(a, b, c) {
if (a && (b == null) && (c == null)) {
this.parseJID(a);
} else if (b != null) {
this.setUser(a);
this.setDomain(b);
this.resource = c;
} else {
throw new Error('Argument error');
}
}
JID.prototype.user = null;
JID.prototype.resource = null;
JID.prototype.domain = null;
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.resource = s.substr(s.indexOf('/') + 1);
s = s.substr(0, s.indexOf('/'));
}
return this.setDomain(s);
};
JID.prototype.toString = function() {
var s;
s = this.domain;
if (this.user) {
s = this.user + '@' + s;
}
if (this.resource) {
s += '/' + this.resource;
}
return s;
};
JID.prototype.bare = function() {
if (this.resource) {
return new JID(this.user, this.domain, null);
} else {
return this;
}
};
JID.prototype.equals = function(other) {
return this.user === other.user && this.domain === other.domain && this.resource === other.resource;
};
JID.prototype.setUser = function(user) {
return this.user = user && user.toLowerCase();
};
JID.prototype.setDomain = function(domain) {
return this.domain = domain && (domain.split(".").map(toUnicode).join(".")).toLowerCase();
};
return JID;
})();
window.JID = JID;
}).call(this);