Comparing version 1.4.0 to 1.4.1
61
oow.js
(function () { | ||
const Collection = { | ||
isEmpty() { return this.length === 0; }, | ||
notEmpty() { return !this.isEmpty(); }, | ||
first() { return this[0]; }, | ||
isEmpty() { return this.length === 0 }, | ||
notEmpty() { return !this.isEmpty() }, | ||
first() { return this[0] }, | ||
second() { return this[1] }, | ||
third() { return this[2] }, | ||
last() { return this[this.length-1]; }, | ||
@@ -13,6 +15,6 @@ any(predicate) { | ||
all(predicate) { | ||
return !this.any(elem => !predicate(elem)); | ||
return !this.any(elem => !predicate(elem)) | ||
}, | ||
take(n) { return this.slice(0, n); }, | ||
drop(n) { return this.slice(n, this.length); } | ||
take(n) { return this.slice(0, n) }, | ||
drop(n) { return this.slice(n, this.length) } | ||
}; | ||
@@ -23,33 +25,36 @@ | ||
if (!array) return false; | ||
if (this.length !== array.length) return false; | ||
let differentLength = this.length !== array.length; | ||
if (differentLength) return false; | ||
for (let i = 0, l=this.length; i < l; i++) { | ||
if (this[i] instanceof Array && array[i] instanceof Array) { | ||
if (!this[i].equals(array[i])) return false; | ||
} | ||
else if (this[i] !== array[i]) { | ||
return false; | ||
} | ||
for (let i = 0, l = this.length; i < l; i++) { | ||
let elemsAreArrays = (this[i] instanceof Array) && (array[i] instanceof Array); | ||
if (elemsAreArrays && !this[i].equals(array[i])) return false; | ||
if (this[i] !== array[i]) return false | ||
} | ||
return true; | ||
return true | ||
}, | ||
compact() { | ||
return this.filter(elem => elem !== null && elem !== undefined) | ||
}, | ||
sum(func, startValue) { | ||
let sumElement = (acc, elem) => acc + ((func && func(elem)) || elem); | ||
return this.reduce(sumElement, startValue || 0) | ||
} | ||
}; | ||
let eachExtensionOf = function(extension, block) { | ||
Object.keys(extension).forEach(block) | ||
}; | ||
let eachExtensionOf = (extension, block) => | ||
Object.keys(extension).forEach(block); | ||
let extend = function(proto, extension, methodName) { | ||
let extend = (proto, extension, methodName) => | ||
Object.defineProperty(proto, methodName, { value: extension[methodName] }); | ||
}; | ||
eachExtensionOf(Collection, function (methodName) { | ||
[Array.prototype, String.prototype].forEach(function (proto) { | ||
extend(proto, Collection, methodName); | ||
}); | ||
}); | ||
eachExtensionOf(Collection, methodName => | ||
[Array.prototype, String.prototype].forEach(proto => | ||
extend(proto, Collection, methodName) | ||
) | ||
); | ||
eachExtensionOf(ArrayExtensions, function (methodName) { | ||
extend(Array.prototype, ArrayExtensions, methodName); | ||
}); | ||
eachExtensionOf(ArrayExtensions, methodName => | ||
extend(Array.prototype, ArrayExtensions, methodName) | ||
) | ||
})(); |
{ | ||
"name": "oow", | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"description": "Extension methods that should exist in JS core by default", | ||
"homepage": "https://github.com/ngarbezza/oow", | ||
"repository": { | ||
"type" : "git", | ||
"url" : "https://github.com/ngarbezza/oow" | ||
"type": "git", | ||
"url": "https://github.com/ngarbezza/oow" | ||
}, | ||
@@ -14,3 +14,5 @@ "main": "oow.js", | ||
}, | ||
"files": ["oow.js"], | ||
"files": [ | ||
"oow.js" | ||
], | ||
"keywords": [ | ||
@@ -20,3 +22,6 @@ "oop" | ||
"author": "Nahuel Garbezza <nahuel@10pines.com>", | ||
"license": "MIT" | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@ngarbezza/testy": "^1.2.0" | ||
} | ||
} |
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
3479
52
1