just-index
Advanced tools
Comparing version 1.0.0 to 2.0.0
14
index.js
@@ -8,4 +8,4 @@ module.exports = index; | ||
index([], 'id'); // {} | ||
index([], null); // undefined | ||
index({}, 'id'); // undefined | ||
index([], null); // throws | ||
index({}, 'id'); // throws | ||
*/ | ||
@@ -15,12 +15,9 @@ | ||
if (!Array.isArray(arr)) { | ||
return undefined; | ||
throw new Error('expected an array for first argument'); | ||
} | ||
if (typeof key !== 'string') { | ||
return undefined; | ||
if (typeof key != 'string') { | ||
throw new Error('expected a string for second argument'); | ||
} | ||
var result = {}; | ||
var len = arr.length; | ||
for (var i = 0; i < len; i++) { | ||
@@ -33,4 +30,3 @@ var index = arr[i] && arr[i][key]; | ||
} | ||
return result; | ||
} |
{ | ||
"name": "just-index", | ||
"version": "1.0.0", | ||
"description": "return an object from an array, keyed by the value at the given id", | ||
"version": "2.0.0", | ||
"description": | ||
"return an object from an array, keyed by the value at the given id", | ||
"main": "index.js", | ||
@@ -10,8 +11,3 @@ "scripts": { | ||
"repository": "https://github.com/angus-c/just", | ||
"keywords": [ | ||
"array", | ||
"index", | ||
"no-dependencies", | ||
"just" | ||
], | ||
"keywords": ["array", "index", "no-dependencies", "just"], | ||
"author": "Cam Pedersen", | ||
@@ -18,0 +14,0 @@ "license": "MIT", |
1744