2016-11-28 10:42:58 +00:00
|
|
|
/* globals punycode */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Punycode operations.
|
|
|
|
*
|
|
|
|
* @author n1474335 [n1474335@gmail.com]
|
|
|
|
* @copyright Crown Copyright 2016
|
|
|
|
* @license Apache-2.0
|
|
|
|
*
|
|
|
|
* @namespace
|
|
|
|
*/
|
2016-11-29 00:22:34 +00:00
|
|
|
const Punycode = {
|
2016-11-28 10:42:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @constant
|
|
|
|
* @default
|
|
|
|
*/
|
2016-11-29 00:22:34 +00:00
|
|
|
IDN: false,
|
|
|
|
|
2016-11-28 10:42:58 +00:00
|
|
|
/**
|
|
|
|
* To Punycode operation.
|
|
|
|
*
|
|
|
|
* @param {string} input
|
|
|
|
* @param {Object[]} args
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
2016-11-29 00:22:34 +00:00
|
|
|
run_to_ascii(input, args) {
|
|
|
|
const idn = args[0];
|
|
|
|
|
|
|
|
if (idn) {
|
|
|
|
return punycode.ToASCII(input);
|
|
|
|
} else {
|
|
|
|
return punycode.encode(input);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2016-11-28 10:42:58 +00:00
|
|
|
/**
|
|
|
|
* From Punycode operation.
|
|
|
|
*
|
|
|
|
* @param {string} input
|
|
|
|
* @param {Object[]} args
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
2016-11-29 00:22:34 +00:00
|
|
|
run_to_unicode(input, args) {
|
|
|
|
const idn = args[0];
|
|
|
|
|
|
|
|
if (idn) {
|
|
|
|
return punycode.ToUnicode(input);
|
|
|
|
} else {
|
|
|
|
return punycode.decode(input);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-11-28 10:42:58 +00:00
|
|
|
};
|