diff --git a/.travis.yml b/.travis.yml index 73f7742..ebbbde9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,8 @@ language: node_js node_js: + - 12 + - 10 + - 8 - 6 cache: directories: diff --git a/README.md b/README.md index ee2f9d6..36259bb 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,12 @@ npm install punycode --save In [Node.js](https://nodejs.org/): +> ⚠️ Note that userland modules don't hide core modules. +> For example, `require('punycode')` still imports the deprecated core module even if you executed `npm install punycode`. +> Use `require('punycode/')` to import userland modules rather than core modules. + ```js -const punycode = require('punycode'); +const punycode = require('punycode/'); ``` ## API diff --git a/package.json b/package.json index 9202ccf..7cf866f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "punycode", - "version": "2.1.1", + "version": "2.2.0", "description": "A robust Punycode converter that fully complies to RFC 3492 and RFC 5891, and works on nearly all JavaScript platforms.", "homepage": "https://mths.be/punycode", "main": "punycode.js", diff --git a/punycode.js b/punycode.js index ea61fd0..4fb262c 100644 --- a/punycode.js +++ b/punycode.js @@ -50,11 +50,11 @@ function error(type) { * item. * @returns {Array} A new array of values returned by the callback function. */ -function map(array, fn) { +function map(array, callback) { const result = []; let length = array.length; while (length--) { - result[length] = fn(array[length]); + result[length] = callback(array[length]); } return result; } @@ -66,22 +66,22 @@ function map(array, fn) { * @param {String} domain The domain name or email address. * @param {Function} callback The function that gets called for every * character. - * @returns {Array} A new string of characters returned by the callback + * @returns {String} A new string of characters returned by the callback * function. */ -function mapDomain(string, fn) { - const parts = string.split('@'); +function mapDomain(domain, callback) { + const parts = domain.split('@'); let result = ''; if (parts.length > 1) { // In email addresses, only the domain name should be punycoded. Leave // the local part (i.e. everything up to `@`) intact. result = parts[0] + '@'; - string = parts[1]; + domain = parts[1]; } // Avoid `split(regex)` for IE8 compatibility. See #17. - string = string.replace(regexSeparators, '\x2E'); - const labels = string.split('.'); - const encoded = map(labels, fn).join('.'); + domain = domain.replace(regexSeparators, '\x2E'); + const labels = domain.split('.'); + const encoded = map(labels, callback).join('.'); return result + encoded; } @@ -130,7 +130,7 @@ function ucs2decode(string) { * @param {Array} codePoints The array of numeric code points. * @returns {String} The new Unicode string (UCS-2). */ -const ucs2encode = array => String.fromCodePoint(...array); +const ucs2encode = codePoints => String.fromCodePoint(...codePoints); /** * Converts a basic code point into a digit/integer. @@ -342,7 +342,7 @@ const encode = function(input) { if (currentValue < n && ++delta > maxInt) { error('overflow'); } - if (currentValue == n) { + if (currentValue === n) { // Represent delta as a generalized variable-length integer. let q = delta; for (let k = base; /* no condition */; k += base) { @@ -359,7 +359,7 @@ const encode = function(input) { } output.push(stringFromCharCode(digitToBasic(q, 0))); - bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength); + bias = adapt(delta, handledCPCountPlusOne, handledCPCount === basicLength); delta = 0; ++handledCPCount; }