array.prototype.tosorted
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -8,2 +8,13 @@ # Changelog | ||
## [v1.1.0](https://github.com/es-shims/Array.prototype.toSorted/compare/v1.0.0...v1.1.0) - 2022-08-14 | ||
### Commits | ||
- [Tests] add coverage from https://github.com/tc39/test262/pull/3464 [`2172830`](https://github.com/es-shims/Array.prototype.toSorted/commit/21728306e552c80868753b0147dc5637e57ffd2b) | ||
- [meta] use `npmignore` to autogenerate an npmignore file [`972f761`](https://github.com/es-shims/Array.prototype.toSorted/commit/972f761599aaf97049a005974caa2d9b24581119) | ||
- [New] `shim`/`auto`: add `toSorted` to `Symbol.unscopables` [`2ad9bad`](https://github.com/es-shims/Array.prototype.toSorted/commit/2ad9bad51ab7d2e7cc579f6681809fe495682163) | ||
- [Deps] update `define-properties`, `es-abstract`, `get-intrinsic` [`e7b229d`](https://github.com/es-shims/Array.prototype.toSorted/commit/e7b229dbb0c199661f785dfa0d5403b81ed7811e) | ||
- [Dev Deps] update `@ljharb/eslint-config`, `functions-have-names`, `tape` [`2bccb92`](https://github.com/es-shims/Array.prototype.toSorted/commit/2bccb92d5314e3b86bb3ffc1144f0c86cdca285a) | ||
- [readme] fix link to spec [`0d024e6`](https://github.com/es-shims/Array.prototype.toSorted/commit/0d024e68e3d41b3ec8dbc8aa47e99d8987c91fea) | ||
## v1.0.0 - 2022-03-31 | ||
@@ -10,0 +21,0 @@ |
{ | ||
"name": "array.prototype.tosorted", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "An ESnext spec-compliant `Array.prototype.toSorted` shim/polyfill/replacement that works as far down as ES3.", | ||
@@ -15,2 +15,3 @@ "main": "index.js", | ||
"scripts": { | ||
"prepack": "npmignore --auto --commentLines=autogenerated", | ||
"prepublish": "not-in-publish || npm run prepublishOnly", | ||
@@ -50,3 +51,3 @@ "prepublishOnly": "safe-publish-latest", | ||
"@es-shims/api": "^2.2.3", | ||
"@ljharb/eslint-config": "^20.2.3", | ||
"@ljharb/eslint-config": "^21.0.0", | ||
"aud": "^2.0.0", | ||
@@ -56,13 +57,16 @@ "auto-changelog": "^2.4.0", | ||
"evalmd": "^0.0.19", | ||
"functions-have-names": "^1.2.2", | ||
"functions-have-names": "^1.2.3", | ||
"has": "^1.0.3", | ||
"has-strict-mode": "^1.0.1", | ||
"npmignore": "^0.3.0", | ||
"nyc": "^10.3.2", | ||
"safe-publish-latest": "^2.0.0", | ||
"tape": "^5.5.2" | ||
"tape": "^5.5.3" | ||
}, | ||
"dependencies": { | ||
"call-bind": "^1.0.2", | ||
"define-properties": "^1.1.3", | ||
"es-abstract": "^1.19.2", | ||
"get-intrinsic": "^1.1.1" | ||
"define-properties": "^1.1.4", | ||
"es-abstract": "^1.20.1", | ||
"es-shim-unscopables": "^1.0.0", | ||
"get-intrinsic": "^1.1.2" | ||
}, | ||
@@ -76,3 +80,8 @@ "auto-changelog": { | ||
"hideCredit": true | ||
}, | ||
"publishConfig": { | ||
"ignore": [ | ||
".github/workflows" | ||
] | ||
} | ||
} |
@@ -12,3 +12,3 @@ # array.prototype.tosorted <sup>[![Version Badge][npm-version-svg]][package-url]</sup> | ||
This package implements the [es-shim API](https://github.com/es-shims/api) interface. It works in an ES3-supported environment and complies with the proposed [spec](https://tc39.github.io/proposal-array-grouping/). | ||
This package implements the [es-shim API](https://github.com/es-shims/api) interface. It works in an ES3-supported environment and complies with the proposed [spec](https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.toSorted). | ||
@@ -15,0 +15,0 @@ Because `Array.prototype.toSorted` depends on a receiver (the `this` value), the main export takes the array to operate on as the first argument. |
'use strict'; | ||
var define = require('define-properties'); | ||
var shimUnscopables = require('es-shim-unscopables'); | ||
var getPolyfill = require('./polyfill'); | ||
@@ -8,2 +10,3 @@ | ||
var polyfill = getPolyfill(); | ||
define( | ||
@@ -14,3 +17,6 @@ Array.prototype, | ||
); | ||
shimUnscopables('toSorted'); | ||
return polyfill; | ||
}; |
'use strict'; | ||
var has = require('has'); | ||
module.exports = function (toSorted, t) { | ||
@@ -31,2 +33,119 @@ var nums = [2, 1, 3]; | ||
); | ||
var arrayLikeLengthValueOf = { | ||
length: { | ||
valueOf: function () { return 2; } | ||
}, | ||
0: 4, | ||
1: 0, | ||
2: 1 | ||
}; | ||
t.deepEqual(toSorted(arrayLikeLengthValueOf), [0, 4]); | ||
t.test('not positive integer lengths', function (st) { | ||
st.deepEqual(toSorted({ length: -2 }), []); | ||
st.deepEqual(toSorted({ length: 'dog' }), []); | ||
st.deepEqual(toSorted({ length: NaN }), []); | ||
st.end(); | ||
}); | ||
t.test('getters', { skip: !Object.defineProperty }, function (st) { | ||
var getCalls = []; | ||
var arrayLike = { | ||
0: 2, | ||
1: 1, | ||
2: 3, | ||
length: 3 | ||
}; | ||
Object.defineProperty(arrayLike, '0', { | ||
get: function () { | ||
getCalls.push(0); | ||
return 2; | ||
} | ||
}); | ||
Object.defineProperty(arrayLike, '1', { | ||
get: function () { | ||
getCalls.push(1); | ||
return 1; | ||
} | ||
}); | ||
Object.defineProperty(arrayLike, '2', { | ||
get: function () { | ||
getCalls.push(2); | ||
return 3; | ||
} | ||
}); | ||
var up = {}; | ||
st['throws']( | ||
function () { | ||
toSorted(arrayLike, function () { | ||
throw up; | ||
}); | ||
}, | ||
up | ||
); | ||
st.deepEqual(getCalls, [0, 1, 2]); | ||
var arr1 = [5, 0, 3]; | ||
Object.defineProperty(arr1, '0', { | ||
get: function () { | ||
arr1.push(1); | ||
return 5; | ||
} | ||
}); | ||
st.deepEqual(toSorted(arr1), [0, 3, 5]); | ||
var arr = [5, 1, 4, 6, 3]; | ||
Array.prototype[3] = 2; // eslint-disable-line no-extend-native | ||
st.teardown(function () { | ||
delete Array.prototype[3]; | ||
}); | ||
Object.defineProperty(arr, '2', { | ||
get: function () { | ||
arr.length = 1; | ||
return 4; | ||
} | ||
}); | ||
st.deepEqual(toSorted(arr), [1, 2, 4, 5, undefined]); | ||
st.end(); | ||
}); | ||
t.test('too-large lengths', function (st) { | ||
var arrayLike = { | ||
0: 0, | ||
4294967295: 4294967295, | ||
4294967296: 4294967296, | ||
length: Math.pow(2, 32) | ||
}; | ||
st['throws']( | ||
function () { toSorted(arrayLike); }, | ||
RangeError | ||
); | ||
st.end(); | ||
}); | ||
t.deepEqual(toSorted(true), [], 'true yields empty array'); | ||
t.deepEqual(toSorted(false), [], 'false yields empty array'); | ||
t.test('holes', function (st) { | ||
var arr = [3, /* hole */, 4, /* hole */, 1]; // eslint-disable-line no-sparse-arrays | ||
Array.prototype[3] = 2; // eslint-disable-line no-extend-native | ||
st.teardown(function () { | ||
delete Array.prototype[3]; | ||
}); | ||
var sorted = toSorted(arr); | ||
st.deepEqual(sorted, [1, 2, 3, 4, undefined]); | ||
st.ok(has(sorted, 4)); | ||
st.end(); | ||
}); | ||
}; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17475
248
5
13
+ Addedes-shim-unscopables@^1.0.0
+ Addedes-shim-unscopables@1.0.2(transitive)
Updateddefine-properties@^1.1.4
Updatedes-abstract@^1.20.1
Updatedget-intrinsic@^1.1.2