array-tools
Advanced tools
Comparing version 1.6.1 to 1.6.2
"use strict"; | ||
/* in this case setting module.exports above the requires is significant - it avoids circular reference issues */ | ||
module.exports = ArrayTools; | ||
@@ -51,10 +53,13 @@ | ||
function ArrayTools(array){ | ||
if (!(this instanceof ArrayTools)) return new ArrayTools(array); | ||
if (!Array.isArray(array)) throw new Error("must pass an array to array-tools"); | ||
this._array = array.slice(0); | ||
function ArrayTools(input){ | ||
if (!(this instanceof ArrayTools)) return new ArrayTools(input); | ||
if (Array.isArray(input)){ | ||
this._data = input.slice(0); | ||
} else { | ||
this._data = input; | ||
} | ||
} | ||
ArrayTools.prototype.val = function(){ | ||
return this._array; | ||
return this._data; | ||
}; | ||
@@ -64,3 +69,3 @@ | ||
ArrayTools.prototype[method] = function(){ | ||
this._array = Array.prototype[method].apply(this._array, arguments); | ||
this._data = Array.prototype[method].apply(this._data, arguments); | ||
return this; | ||
@@ -70,7 +75,7 @@ }; | ||
["pluck", "pick", "arrayify", "where", "without", "unique", "spliceWhile", "extract", "flatten", "sortBy"].forEach(function(method){ | ||
["pluck", "pick", "arrayify", "where", "findWhere", "without", "unique", "spliceWhile", "extract", "flatten", "sortBy"].forEach(function(method){ | ||
ArrayTools.prototype[method] = function(){ | ||
var args = arrayify(arguments); | ||
args.unshift(this._array); | ||
this._array = ArrayTools[method].apply(null, args); | ||
args.unshift(this._data); | ||
this._data = ArrayTools[method].apply(null, args); | ||
return this; | ||
@@ -81,3 +86,3 @@ }; | ||
ArrayTools.prototype.exists = function(value){ | ||
return exists(this._array, value); | ||
return exists(this._data, value); | ||
}; | ||
@@ -84,0 +89,0 @@ |
{ | ||
"name": "array-tools", | ||
"author": "Lloyd Brookes <75pound@gmail.com>", | ||
"version": "1.6.1", | ||
"version": "1.6.2", | ||
"description": "Lightweight tool-kit for working with arrays", | ||
@@ -6,0 +6,0 @@ "repository": "https://github.com/75lb/array-tools.git", |
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
51234
1074