|
@ -34,6 +34,10 @@ |
|
|
initialN = 128, // 0x80
|
|
|
initialN = 128, // 0x80
|
|
|
delimiter = '-', // '\x2D'
|
|
|
delimiter = '-', // '\x2D'
|
|
|
|
|
|
|
|
|
|
|
|
/** Regular expressions */ |
|
|
|
|
|
regexASCII = /[^\x20-\x7e]/, |
|
|
|
|
|
regexPunycode = /^xn--/, |
|
|
|
|
|
|
|
|
/** Error messages */ |
|
|
/** Error messages */ |
|
|
errors = { |
|
|
errors = { |
|
|
'overflow': 'Overflow: input needs wider integers to process.', |
|
|
'overflow': 'Overflow: input needs wider integers to process.', |
|
@ -87,7 +91,7 @@ |
|
|
*/ |
|
|
*/ |
|
|
function mapDomain(string, fn) { |
|
|
function mapDomain(string, fn) { |
|
|
var glue = '.'; |
|
|
var glue = '.'; |
|
|
return map(string.toLowerCase().split(glue), fn).join(glue); |
|
|
return map(string.split(glue), fn).join(glue); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -196,6 +200,7 @@ |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Converts a basic code point to lowercase is `flag` is falsy, or to |
|
|
* Converts a basic code point to lowercase is `flag` is falsy, or to |
|
|
|
|
|
* uppercase if `flag` is truthy. The code point is unchanged if it's |
|
|
* caseless. The behavior is undefined if `codePoint` is not a basic code |
|
|
* caseless. The behavior is undefined if `codePoint` is not a basic code |
|
|
* point. |
|
|
* point. |
|
|
* @private |
|
|
* @private |
|
@ -482,22 +487,6 @@ |
|
|
return output.join(''); |
|
|
return output.join(''); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Converts a Unicode string representing a domain name to Punycode. Only the |
|
|
|
|
|
* non-ASCII parts of the domain name will be converted, i.e. it doesn't |
|
|
|
|
|
* matter if you call it with a domain that's already in ASCII. |
|
|
|
|
|
* @memberOf Punycode |
|
|
|
|
|
* @param {String} domain The domain name to convert, as a Unicode string. |
|
|
|
|
|
* @returns {String} The Punycode representation of the given domain name. |
|
|
|
|
|
*/ |
|
|
|
|
|
function toASCII(domain) { |
|
|
|
|
|
return mapDomain(domain, function(string) { |
|
|
|
|
|
return string.match(/[^a-zA-Z0-9-]/) |
|
|
|
|
|
? 'xn--' + encode(string) |
|
|
|
|
|
: string; |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Converts a Punycode string representing a domain name to Unicode. Only the |
|
|
* Converts a Punycode string representing a domain name to Unicode. Only the |
|
|
* Punycoded parts of the domain name will be converted, i.e. it doesn't |
|
|
* Punycoded parts of the domain name will be converted, i.e. it doesn't |
|
@ -510,8 +499,24 @@ |
|
|
*/ |
|
|
*/ |
|
|
function toUnicode(domain) { |
|
|
function toUnicode(domain) { |
|
|
return mapDomain(domain, function(string) { |
|
|
return mapDomain(domain, function(string) { |
|
|
return string.match(/^xn--/) |
|
|
return regexPunycode.test(string) |
|
|
? decode(string.slice(4)) |
|
|
? decode(string.slice(4).toLowerCase()) |
|
|
|
|
|
: string; |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Converts a Unicode string representing a domain name to Punycode. Only the |
|
|
|
|
|
* non-ASCII parts of the domain name will be converted, i.e. it doesn't |
|
|
|
|
|
* matter if you call it with a domain that's already in ASCII. |
|
|
|
|
|
* @memberOf Punycode |
|
|
|
|
|
* @param {String} domain The domain name to convert, as a Unicode string. |
|
|
|
|
|
* @returns {String} The Punycode representation of the given domain name. |
|
|
|
|
|
*/ |
|
|
|
|
|
function toASCII(domain) { |
|
|
|
|
|
return mapDomain(domain, function(string) { |
|
|
|
|
|
return regexASCII.test(string) |
|
|
|
|
|
? 'xn--' + encode(string) |
|
|
: string; |
|
|
: string; |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
@ -520,11 +525,10 @@ |
|
|
|
|
|
|
|
|
/** Define the public API */ |
|
|
/** Define the public API */ |
|
|
Punycode = { |
|
|
Punycode = { |
|
|
'version': '0.0.1337', |
|
|
'version': '0.1.1', |
|
|
/** |
|
|
/** |
|
|
* An object of methods to convert from JavaScript's internal character |
|
|
* An object of methods to convert from JavaScript's internal character |
|
|
* representation to Unicode and back. |
|
|
* representation to Unicode and back. |
|
|
* @static |
|
|
|
|
|
* @memberOf Punycode |
|
|
* @memberOf Punycode |
|
|
* @type Object |
|
|
* @type Object |
|
|
*/ |
|
|
*/ |
|
|