Comparing version 1.0.3 to 1.0.4
{ | ||
"name": "pro-array", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Extends the functionality of Arrays with several useful methods", | ||
@@ -5,0 +5,0 @@ "main": "pro-array.js", |
/** | ||
* ProArray | ||
* @version 1.0.4 | ||
* @copyright 2015 Nathan Woltman | ||
* @license MIT https://github.com/woollybogger/pro-array/blob/master/LICENSE.txt | ||
*/ | ||
@@ -21,6 +24,2 @@ | ||
function retval(v) { | ||
return v; | ||
} | ||
/** | ||
@@ -111,3 +110,11 @@ * @class Array | ||
compact: function() { | ||
return this.filter(retval); | ||
var res = []; | ||
for (var i = 0; i < this.length; i++) { | ||
if (this[i]) { | ||
res.push(this[i]); | ||
} | ||
} | ||
return res; | ||
}, | ||
@@ -207,3 +214,3 @@ | ||
* | ||
* __Note:__ The order of elements in the arrays DOES matter. The elements must be found in the same order | ||
* __Note:__ The order of elements in the arrays __does__ matter. The elements must be found in the same order | ||
* for the arrays to be considered equal. | ||
@@ -275,3 +282,4 @@ * | ||
/** | ||
* Performs a set intersection on this array and the input array(s). | ||
* Performs a [set intersection](http://en.wikipedia.org/wiki/Intersection_(set_theory)) | ||
* on this array and the input array(s). | ||
* | ||
@@ -363,4 +371,6 @@ * @function Array#intersect | ||
/** | ||
* Removes all occurrences of the passed in items from the array if they exist in the array. | ||
* Removes all occurrences of the passed in items from the array and returns the array. | ||
* | ||
* __Note:__ Unlike {@link Array#without|`.without()`}, this method mutates the array. | ||
* | ||
* @function Array#remove | ||
@@ -383,10 +393,31 @@ * @param {...*} *items - Items to remove from the array. | ||
remove: function() { | ||
for (var i = 0; i < arguments.length; i++) { | ||
for (;;) { | ||
var remIndex = this.indexOf(arguments[i]); | ||
if (remIndex < 0) break; | ||
this.splice(remIndex, 1); | ||
var remStartIndex = 0; | ||
var numToRemove = 0; | ||
for (var i = 0; i < this.length; i++) { | ||
var removeCurrentIndex = false; | ||
for (var j = 0; j < arguments.length; j++) { | ||
if (this[i] === arguments[j]) { | ||
removeCurrentIndex = true; | ||
break; | ||
} | ||
} | ||
if (removeCurrentIndex) { | ||
if (!numToRemove) { | ||
remStartIndex = i; | ||
} | ||
++numToRemove; | ||
} else if (numToRemove) { | ||
this.splice(remStartIndex, numToRemove); | ||
i -= numToRemove; | ||
numToRemove = 0; | ||
} | ||
} | ||
if (numToRemove) { | ||
this.splice(remStartIndex, numToRemove); | ||
} | ||
return this; | ||
@@ -400,3 +431,4 @@ }, | ||
* @param {...Array} *arrays - A variable number of arrays. | ||
* @returns {Array} An array that is the union of this array and the input array(s). | ||
* @returns {Array} An array that is the [union](http://en.wikipedia.org/wiki/Union_%28set_theory%29) | ||
* of this array and the input array(s). | ||
* | ||
@@ -443,20 +475,22 @@ * @example | ||
unique: function(isSorted) { | ||
var unique = []; | ||
var i = 0; | ||
var res = []; | ||
var len = this.length; | ||
if (!len) { | ||
return res; | ||
} | ||
res[0] = this[0]; | ||
var i = 1; | ||
if (isSorted) { | ||
var lastIndex = this.length - 1; | ||
if (lastIndex === -1) { | ||
return unique; | ||
} | ||
for (; i < lastIndex; i++) { | ||
if (this[i] !== this[i + 1]) { | ||
unique.push(this[i]); | ||
for (; i < len; i++) { | ||
if (this[i] !== this[i - 1]) { | ||
res.push(this[i]); | ||
} | ||
} | ||
unique.push(this[lastIndex]); | ||
} else { | ||
for (; i < this.length; i++) { | ||
if (unique.indexOf(this[i]) < 0) { | ||
unique.push(this[i]); | ||
for (; i < len; i++) { | ||
if (res.indexOf(this[i]) < 0) { | ||
res.push(this[i]); | ||
} | ||
@@ -466,3 +500,3 @@ } | ||
return unique; | ||
return res; | ||
}, | ||
@@ -517,2 +551,10 @@ | ||
/** | ||
* Alias of {@link Array#remove}. | ||
* | ||
* @function Array#rem | ||
* @see {@link Array#remove} | ||
*/ | ||
properties.rem = properties.remove; | ||
/** | ||
* Alias of {@link Array#unique}. | ||
@@ -519,0 +561,0 @@ * |
# ProArray | ||
Extends the functionality of Arrays ([safely](#extending-array-prototype)) with several useful methods | ||
Extends the functionality of Arrays ([safely](#extending-array-prototype)) with several useful methods of unparalleled performance | ||
@@ -49,2 +49,3 @@ [![NPM Version](https://img.shields.io/npm/v/pro-array.svg)](https://www.npmjs.com/package/pro-array) | ||
* [.numsort()](#Array#numsort) ⇒ <code>[Array](#Array)</code> | ||
* [.rem()](#Array#rem) | ||
* [.remove(...*items)](#Array#remove) ⇒ <code>[Array](#Array)</code> | ||
@@ -220,3 +221,3 @@ * [.rnumsort()](#Array#rnumsort) ⇒ <code>[Array](#Array)</code> | ||
__Note:__ The order of elements in the arrays DOES matter. The elements must be found in the same order | ||
__Note:__ The order of elements in the arrays __does__ matter. The elements must be found in the same order | ||
for the arrays to be considered equal. | ||
@@ -282,3 +283,4 @@ | ||
### array.intersect(...*arrays) ⇒ <code>[Array](#Array)</code> | ||
Performs a set intersection on this array and the input array(s). | ||
Performs a [set intersection](http://en.wikipedia.org/wiki/Intersection_(set_theory)) | ||
on this array and the input array(s). | ||
@@ -341,7 +343,17 @@ | ||
<a name="Array#rem"></a> | ||
### array.rem() | ||
Alias of [remove](#Array#remove). | ||
**See**: [remove](#Array#remove) | ||
--- | ||
<a name="Array#remove"></a> | ||
### array.remove(...*items) ⇒ <code>[Array](#Array)</code> | ||
Removes all occurrences of the passed in items from the array if they exist in the array. | ||
Removes all occurrences of the passed in items from the array and returns the array. | ||
__Note:__ Unlike [`.without()`](#Array#without), this method mutates the array. | ||
| Param | Type | Description | | ||
@@ -395,3 +407,4 @@ | --- | --- | --- | | ||
**Returns**: <code>[Array](#Array)</code> - An array that is the union of this array and the input array(s). | ||
**Returns**: <code>[Array](#Array)</code> - An array that is the [union](http://en.wikipedia.org/wiki/Union_%28set_theory%29) | ||
of this array and the input array(s). | ||
@@ -465,1 +478,9 @@ **Example** | ||
ProArray uses [`Object.defineProperties()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties) to safely extend the native Array prototype such that the added properties are not enumerable. This keeps native arrays clean and prevents [potential abnormalities](http://fireboltjs.com/prototype-extending/#enumerable_properties) when working with arrays. | ||
#### Worried about naming collisions? | ||
It is extremely unlikely that the name of any method that ProArray adds to the Array prototype will be used in a future ECMAScript standard, but if you're still worried and want to be extra safe, try using the alias methods: | ||
+ [.diff()](#Array#diff) ⇒ [.difference()](#Array#difference) | ||
+ [.rem()](#Array#rem) ⇒ [.remove()](#Array#remove) | ||
+ [.uniq()](#Array#uniq) ⇒ [.unique()](#Array#unique) |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
481
0
28904
5
497