mol-proto
Advanced tools
Comparing version 0.1.13 to 0.1.14
{ | ||
"name": "proto", | ||
"version": "0.1.13", | ||
"version": "0.1.14", | ||
"homepage": "https://github.com/milojs/proto", | ||
@@ -5,0 +5,0 @@ "authors": [ |
@@ -62,3 +62,3 @@ 'use strict'; | ||
arrayMethods.find = Array.prototype.find | ||
|| utils.makeFindMethod(arrayMethods.forEach, 'value'); | ||
|| utils.makeFindMethod(arrayMethods.some, 'value'); | ||
@@ -76,3 +76,3 @@ | ||
arrayMethods.findIndex = Array.prototype.findIndex | ||
|| utils.makeFindMethod(arrayMethods.forEach, 'index'); | ||
|| utils.makeFindMethod(arrayMethods.some, 'index'); | ||
@@ -79,0 +79,0 @@ |
@@ -85,3 +85,3 @@ 'use strict'; | ||
*/ | ||
objectMethods.findValue = utils.makeFindMethod(eachKey, 'value'); | ||
objectMethods.findValue = utils.makeFindMethod(someKey, 'value'); | ||
@@ -99,3 +99,3 @@ | ||
*/ | ||
objectMethods.findKey = utils.makeFindMethod(eachKey, 'key'); | ||
objectMethods.findKey = utils.makeFindMethod(someKey, 'key'); | ||
@@ -102,0 +102,0 @@ |
@@ -36,29 +36,22 @@ 'use strict'; | ||
*/ | ||
function makeFindMethod(eachMethod, findWhat) { | ||
function makeFindMethod(someMethod, findWhat) { | ||
var argIndex = findWhat == 'value' ? 0 : 1; | ||
return function findValueOrIndex(callback, thisArg, onlyEnumerable) { | ||
var caughtError; | ||
try { | ||
eachMethod.call(this, testItem, thisArg, onlyEnumerable); | ||
} catch (found) { | ||
if (found === _error) throw caughtError; | ||
else return found; | ||
} | ||
var foundValueOrIndex; | ||
var found = someMethod.call(this, testItem, thisArg, onlyEnumerable); | ||
if (found) | ||
return foundValueOrIndex; | ||
// if looking for index and not found, return -1 | ||
if (argIndex && eachMethod == Array.prototype.forEach) | ||
return -1; | ||
else if (argIndex && someMethod == Array.prototype.some) | ||
return -1; | ||
function testItem(value, index, self) { | ||
var test; | ||
try { | ||
test = callback.call(this, value, index, self); | ||
} catch(err) { | ||
caughtError = err; | ||
throw _error; | ||
var test = callback.call(this, value, index, self); | ||
if (test) { | ||
foundValueOrIndex = arguments[argIndex] | ||
return test; | ||
} | ||
if (test) | ||
throw arguments[argIndex]; | ||
} | ||
} | ||
} |
{ | ||
"name": "mol-proto", | ||
"version": "0.1.13", | ||
"version": "0.1.14", | ||
"description": "ES5 object manipulation library for node and modern browsers", | ||
@@ -5,0 +5,0 @@ "main": "lib/proto.js", |
197194
4912