collections
Advanced tools
Comparing version 5.0.7 to 5.1.0
@@ -0,1 +1,6 @@ | ||
## v5.1 | ||
- Addresses a bug with Array#find and deprecate findValue|findLastValue API in collections. | ||
... | ||
## v5.0.2 | ||
@@ -23,2 +28,6 @@ - Addresses a bug in range listening that happened when the number of listeners went beyond 1 and back to 0 | ||
## v2.0.x | ||
- This version (v2 branch) does not have issue with Array.#find and expose only findValue|findLastValue API in collections. | ||
## v1.2.4 | ||
@@ -25,0 +34,0 @@ |
30
deque.js
@@ -349,4 +349,21 @@ "use strict"; | ||
// TODO rename findValue | ||
Deque.prototype.find = function (value, equals, index) { | ||
var deprecatedWarnNonce = {}; | ||
function deprecatedWarn(msg, notOnce) { | ||
if ( | ||
typeof console !== 'undefined' && | ||
typeof console.warn === 'function' && | ||
(notOnce !== true && deprecatedWarnNonce.hasOwnProperty(msg) === false) | ||
) { | ||
console.warn(msg); | ||
deprecatedWarnNonce[msg]++; | ||
} | ||
} | ||
// TODO remove in v6 (not present in v2) | ||
Deque.prototype.find = function () { | ||
deprecatedWarn('Deque#find function is deprecated please use Deque#findValue instead.'); | ||
return this.findValue.apply(this, arguments); | ||
}; | ||
Deque.prototype.findValue = function (value, equals, index) { | ||
equals = equals || Object.equals; | ||
@@ -372,4 +389,9 @@ // Default start index at beginning | ||
// TODO rename findLastValue | ||
Deque.prototype.findLast = function (value, equals, index) { | ||
// TODO remove in v6 (not present in v2) | ||
Deque.prototype.findLast = function () { | ||
deprecatedWarn('Deque#findLast function is deprecated please use Deque#findLastValue instead.'); | ||
return this.findLastValue.apply(this, arguments); | ||
}; | ||
Deque.prototype.findLastValue = function (value, equals, index) { | ||
equals = equals || Object.equals; | ||
@@ -376,0 +398,0 @@ // Default start position at the end |
{ | ||
"name": "collections", | ||
"version": "5.0.7", | ||
"version": "5.1.0", | ||
"description": "data structures with idiomatic JavaScript collection interfaces", | ||
@@ -8,7 +8,10 @@ "homepage": "http://www.collectionsjs.com", | ||
"contributors": [ | ||
{ | ||
"name": "Benoit Marchant" | ||
} | ||
], | ||
"keywords": [ | ||
{ | ||
"name": "Benoit Marchant" | ||
}, | ||
{ | ||
"name": "Harold Thetiot" | ||
} | ||
], | ||
"keywords": [ | ||
"collections", | ||
@@ -63,4 +66,6 @@ "data structures", | ||
"test:karma-dev": "karma start --auto-watch --no-single-run --capture", | ||
"test:jasmine": "concurrently \"http-server -a localhost -p 8085\" \"open http://localhost:8085/test/run.html\"" | ||
"test:jasmine": "concurrently \"http-server -a localhost -p 8085\" \"open http://localhost:8085/test/run.html\"", | ||
"preversion:bower": "sed 's/\"version\": \"[^,]*\"/\"version\": \"'$npm_package_version'\"/' bower.json > output && mv output bower.json", | ||
"version": "npm run preversion:bower && git add -A bower.json" | ||
} | ||
} |
# Collections | ||
[![npm version](https://img.shields.io/npm/v/collections.svg?style=flat)](https://www.npmjs.com/package/collections) | ||
[![Build Status](https://travis-ci.org/montagejs/collections.png?branch=master)](http://travis-ci.org/montagejs/collections) | ||
@@ -36,1 +38,5 @@ | ||
## Design principles | ||
- extends core types (e.g extends `Array.prototype` with additional non-enumerable properties like `.set`) | ||
@@ -89,9 +89,9 @@ "use strict"; | ||
define("has", function (value, equals) { | ||
return this.find(value, equals) !== -1; | ||
return this.findValue(value, equals) !== -1; | ||
}); | ||
define("get", function (index, defaultValue) { | ||
if (+index !== index) | ||
if (+index !== index) { | ||
throw new Error("Indicies must be numbers"); | ||
if (!index in this) { | ||
} else if (!index in this) { | ||
return defaultValue; | ||
@@ -114,3 +114,3 @@ } else { | ||
define("delete", function (value, equals) { | ||
var index = this.find(value, equals); | ||
var index = this.findValue(value, equals); | ||
if (index !== -1) { | ||
@@ -137,3 +137,77 @@ this.spliceOne(index); | ||
define("find", function (value, equals) { | ||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find | ||
// https://tc39.github.io/ecma262/#sec-array.prototype.find | ||
if (!Array.prototype.find) { | ||
Object.defineProperty(Array.prototype, 'find', { | ||
value: function(predicate) { | ||
// 1. Let O be ? ToObject(this value). | ||
if (this == null) { | ||
throw new TypeError('"this" is null or not defined'); | ||
} | ||
var o = Object(this); | ||
// 2. Let len be ? ToLength(? Get(O, "length")). | ||
var len = o.length >>> 0; | ||
// 3. If IsCallable(predicate) is false, throw a TypeError exception. | ||
if (typeof predicate !== 'function') { | ||
throw new TypeError('predicate must be a function'); | ||
} | ||
// 4. If thisArg was supplied, let T be thisArg; else let T be undefined. | ||
var thisArg = arguments[1]; | ||
// 5. Let k be 0. | ||
var k = 0; | ||
// 6. Repeat, while k < len | ||
while (k < len) { | ||
// a. Let Pk be ! ToString(k). | ||
// b. Let kValue be ? Get(O, Pk). | ||
// c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). | ||
// d. If testResult is true, return kValue. | ||
var kValue = o[k]; | ||
if (predicate.call(thisArg, kValue, k, o)) { | ||
return kValue; | ||
} | ||
// e. Increase k by 1. | ||
k++; | ||
} | ||
} | ||
}); | ||
} | ||
// TODO remove in v6 (not present in v2) | ||
var deprecatedWarnNonce = {}; | ||
function deprecatedWarn(msg, notOnce) { | ||
if ( | ||
typeof console !== 'undefined' && | ||
typeof console.warn === 'function' && | ||
(notOnce !== true && deprecatedWarnNonce.hasOwnProperty(msg) === false) | ||
) { | ||
console.warn(msg); | ||
deprecatedWarnNonce[msg]++; | ||
} | ||
} | ||
// Save Array.prototype.find in order to support legacy and display warning. | ||
// TODO remove in v6 (not present in v2) | ||
var ArrayFindPrototype = Object.getOwnPropertyDescriptor(Array.prototype, 'find').value; | ||
define("find", function (value, equals, index) { | ||
if ( | ||
typeof arguments[0] === 'function' && | ||
this instanceof Array | ||
) { | ||
return ArrayFindPrototype.apply(this, arguments); | ||
} else { | ||
deprecatedWarn('Array#find usage is deprecated please use Array#findValue'); | ||
return this.findValue.apply(this, arguments); | ||
} | ||
}); | ||
define("findValue", function (value, equals, index) { | ||
if (index) { | ||
throw new Error("Array#findValue does not support third argument: index"); | ||
} | ||
equals = equals || this.contentEquals || Object.equals; | ||
@@ -148,3 +222,9 @@ for (var index = 0; index < this.length; index++) { | ||
// TODO remove in v6 (not present in v2) | ||
define("findLast", function (value, equals) { | ||
deprecatedWarn('Array#findLast function is deprecated please use Array#findLastValue instead.'); | ||
return this.findLastValue.apply(this, arguments); | ||
}); | ||
define("findLastValue", function (value, equals) { | ||
equals = equals || this.contentEquals || Object.equals; | ||
@@ -365,3 +445,4 @@ var index = this.length; | ||
this.end = end; | ||
}; | ||
} | ||
ArrayIterator.prototype.__iterationObject = null; | ||
@@ -368,0 +449,0 @@ Object.defineProperty(ArrayIterator.prototype,"_iterationObject", { |
@@ -201,9 +201,27 @@ "use strict"; | ||
var deprecatedWarnNonce = {}; | ||
function deprecatedWarn(msg, notOnce) { | ||
if ( | ||
typeof console !== 'undefined' && | ||
typeof console.warn === 'function' && | ||
(notOnce !== true && deprecatedWarnNonce.hasOwnProperty(msg) === false) | ||
) { | ||
console.warn(msg); | ||
deprecatedWarnNonce[msg]++; | ||
} | ||
} | ||
// TODO remove in v6 (not present in v2) | ||
SortedArray.prototype.find = function (value, equals, index) { | ||
deprecatedWarn('This SortedArray#find usage is deprecated please use SortedArray#findValue'); | ||
return this.findValue.apply(this, arguments); | ||
}; | ||
SortedArray.prototype.findValue = function (value, equals, index) { | ||
// TODO throw error if provided a start index | ||
if (equals) { | ||
throw new Error("SortedArray#find does not support second argument: equals"); | ||
throw new Error("SortedArray#findValue does not support second argument: equals"); | ||
} | ||
if (index) { | ||
throw new Error("SortedArray#find does not support third argument: index"); | ||
throw new Error("SortedArray#findValue does not support third argument: index"); | ||
} | ||
@@ -214,8 +232,14 @@ // TODO support initial partition index | ||
// TODO remove in v6 (not present in v2) | ||
SortedArray.prototype.findLast = function (value, equals, index) { | ||
deprecatedWarn('This SortedArray#findLast usage is deprecated please use SortedArray#findLastValue'); | ||
return this.findLastValue.apply(this, arguments); | ||
}; | ||
SortedArray.prototype.findLastValue = function (value, equals, index) { | ||
if (equals) { | ||
throw new Error("SortedArray#findLast does not support second argument: equals"); | ||
throw new Error("SortedArray#findLastValue does not support second argument: equals"); | ||
} | ||
if (index) { | ||
throw new Error("SortedArray#findLast does not support third argument: index"); | ||
throw new Error("SortedArray#findLastValue does not support third argument: index"); | ||
} | ||
@@ -222,0 +246,0 @@ // TODO support initial partition index |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
294824
53
7745
42
1