mathiasbynens/punycode.js

Version confusion

Closed this issue · 1 comments

I just upgraded the punycode package from 2.1.0 to 2.3.0. Since I could not find a changelog or even a Git tag here, I backuped the 2.1.0 version from my node_modules folder and compared it to the version after the upgrade. They matched (empty diff)!

Then I found #122 and switched my installation to punycode.js. Now I'm seeing a difference (attached below), and importing punycode.js is obviously better than importing punycode/. But: node -pe "require('punycode.js').version" still outputs 2.1.0, taken from the source code:

punycode.js/punycode.js

Lines 418 to 425 in 36db01b

/** Define the public API */
const punycode = {
/**
* A string representing the current Punycode.js version number.
* @memberOf punycode
* @type String
*/
'version': '2.1.0',

diff --color punycode/package.json node_modules/punycode.js/package.json
2,3c2,3
<   "name": "punycode",
<   "version": "2.1.1",
---
>   "name": "punycode.js",
>   "version": "2.3.0",
34c34
<     "url": "https://github.com/bestiejs/punycode.js.git"
---
>     "url": "https://github.com/mathiasbynens/punycode.js.git"
36c36
<   "bugs": "https://github.com/bestiejs/punycode.js/issues",
---
>   "bugs": "https://github.com/mathiasbynens/punycode.js/issues",
44c44
<     "prepublish": "node scripts/prepublish.js"
---
>     "build": "node scripts/prepublish.js"
49c49
<     "mocha": "^2.5.3"
---
>     "mocha": "^10.2.0"
diff --color punycode/punycode.es6.js node_modules/punycode.js/punycode.es6.js
18c18
< const regexNonASCII = /[^\0-\x7E]/; // non-ASCII chars
---
> const regexNonASCII = /[^\0-\x7F]/; // Note: U+007F DEL is excluded too.
53c53
< function map(array, fn) {
---
> function map(array, callback) {
57c57
< 		result[length] = fn(array[length]);
---
> 		result[length] = callback(array[length]);
69c69
<  * @returns {Array} A new string of characters returned by the callback
---
>  * @returns {String} A new string of characters returned by the callback
72,73c72,73
< function mapDomain(string, fn) {
< 	const parts = string.split('@');
---
> function mapDomain(domain, callback) {
> 	const parts = domain.split('@');
79c79
< 		string = parts[1];
---
> 		domain = parts[1];
82,84c82,84
< 	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('.');
133c133
< const ucs2encode = array => String.fromCodePoint(...array);
---
> const ucs2encode = codePoints => String.fromCodePoint(...codePoints);
145,146c145,146
< 	if (codePoint - 0x30 < 0x0A) {
< 		return codePoint - 0x16;
---
> 	if (codePoint >= 0x30 && codePoint < 0x3A) {
> 		return 26 + (codePoint - 0x30);
148c148
< 	if (codePoint - 0x41 < 0x1A) {
---
> 	if (codePoint >= 0x41 && codePoint < 0x5B) {
151c151
< 	if (codePoint - 0x61 < 0x1A) {
---
> 	if (codePoint >= 0x61 && codePoint < 0x7B) {
231c231
< 		let oldi = i;
---
> 		const oldi = i;
240c240,243
< 			if (digit >= base || digit > floor((maxInt - i) / w)) {
---
> 			if (digit >= base) {
> 				error('invalid-input');
> 			}
> 			if (digit > floor((maxInt - i) / w)) {
294c297
< 	let inputLength = input.length;
---
> 	const inputLength = input.length;
308c311
< 	let basicLength = output.length;
---
> 	const basicLength = output.length;
345c348
< 			if (currentValue == n) {
---
> 			if (currentValue === n) {
362c365
< 				bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
---
> 				bias = adapt(delta, handledCPCountPlusOne, handledCPCount === basicLength);
diff --color punycode/punycode.js node_modules/punycode.js/punycode.js
18c18
< const regexNonASCII = /[^\0-\x7E]/; // non-ASCII chars
---
> const regexNonASCII = /[^\0-\x7F]/; // Note: U+007F DEL is excluded too.
53c53
< function map(array, fn) {
---
> function map(array, callback) {
57c57
< 		result[length] = fn(array[length]);
---
> 		result[length] = callback(array[length]);
69c69
<  * @returns {Array} A new string of characters returned by the callback
---
>  * @returns {String} A new string of characters returned by the callback
72,73c72,73
< function mapDomain(string, fn) {
< 	const parts = string.split('@');
---
> function mapDomain(domain, callback) {
> 	const parts = domain.split('@');
79c79
< 		string = parts[1];
---
> 		domain = parts[1];
82,84c82,84
< 	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('.');
133c133
< const ucs2encode = array => String.fromCodePoint(...array);
---
> const ucs2encode = codePoints => String.fromCodePoint(...codePoints);
145,146c145,146
< 	if (codePoint - 0x30 < 0x0A) {
< 		return codePoint - 0x16;
---
> 	if (codePoint >= 0x30 && codePoint < 0x3A) {
> 		return 26 + (codePoint - 0x30);
148c148
< 	if (codePoint - 0x41 < 0x1A) {
---
> 	if (codePoint >= 0x41 && codePoint < 0x5B) {
151c151
< 	if (codePoint - 0x61 < 0x1A) {
---
> 	if (codePoint >= 0x61 && codePoint < 0x7B) {
231c231
< 		let oldi = i;
---
> 		const oldi = i;
240c240,243
< 			if (digit >= base || digit > floor((maxInt - i) / w)) {
---
> 			if (digit >= base) {
> 				error('invalid-input');
> 			}
> 			if (digit > floor((maxInt - i) / w)) {
294c297
< 	let inputLength = input.length;
---
> 	const inputLength = input.length;
308c311
< 	let basicLength = output.length;
---
> 	const basicLength = output.length;
345c348
< 			if (currentValue == n) {
---
> 			if (currentValue === n) {
362c365
< 				bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
---
> 				bias = adapt(delta, handledCPCountPlusOne, handledCPCount === basicLength);
diff --color punycode/README.md node_modules/punycode.js/README.md
1c1
< # Punycode.js [![Build status](https://travis-ci.org/bestiejs/punycode.js.svg?branch=master)](https://travis-ci.org/bestiejs/punycode.js) [![Code coverage status](http://img.shields.io/codecov/c/github/bestiejs/punycode.js.svg)](https://codecov.io/gh/bestiejs/punycode.js) [![Dependency status](https://gemnasium.com/bestiejs/punycode.js.svg)](https://gemnasium.com/bestiejs/punycode.js)
---
> # Punycode.js [![punycode on npm](https://img.shields.io/npm/v/punycode)](https://www.npmjs.com/package/emoji-test-regex-pattern) [![](https://data.jsdelivr.com/v1/package/npm/punycode/badge)](https://www.jsdelivr.com/package/npm/punycode)
15c15
< The current version supports recent versions of Node.js only. It provides a CommonJS module and an ES6 module. For the old version that offers the same functionality with broader support, including Rhino, Ringo, Narwhal, and web browsers, see [v1.4.1](https://github.com/bestiejs/punycode.js/releases/tag/v1.4.1).
---
> This project provides a CommonJS module that uses ES2015+ features and JavaScript module, which work in modern Node.js versions and browsers. For the old Punycode.js version that offers the same functionality in a UMD build with support for older pre-ES2015 runtimes, including Rhino, Ringo, and Narwhal, see [v1.4.1](https://github.com/mathiasbynens/punycode.js/releases/tag/v1.4.1).
26a27,30
> > ⚠️ 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.
> 
28c32
< const punycode = require('punycode');
---
> const punycode = require('punycode/');

version has been updated to align with the package.json version number.