just-split-at
Advanced tools
Comparing version 1.0.0 to 2.0.0
17
index.js
@@ -7,8 +7,17 @@ module.exports = splitAt; | ||
splitAt([], 2); // [[], []] | ||
splitAt(null, 1); // undefined | ||
splitAt(undefined, 1); // undefined | ||
splitAt(null, 1); // throws | ||
splitAt(undefined, 1); // throws | ||
*/ | ||
function splitAt(array, n) { | ||
return Array.isArray(array) ? [array.slice(0, n), array.slice(n)] : undefined; | ||
function splitAt(arr, n) { | ||
if (!Array.isArray(arr)) { | ||
throw new Error('expected an array for the first argument'); | ||
} | ||
if (n != null && typeof n != 'number') { | ||
throw new Error('expected a number or null for the second argument'); | ||
} | ||
if (n == null) { | ||
n = 0; | ||
} | ||
return [arr.slice(0, n), arr.slice(n)]; | ||
} |
{ | ||
"name": "just-split-at", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "splits an array into two at a given position", | ||
@@ -10,8 +10,3 @@ "main": "index.js", | ||
"repository": "https://github.com/angus-c/split-at", | ||
"keywords": [ | ||
"array", | ||
"split-at", | ||
"no-dependencies", | ||
"just" | ||
], | ||
"keywords": ["array", "split-at", "no-dependencies", "just"], | ||
"author": "Cameron Hunter", | ||
@@ -18,0 +13,0 @@ "license": "MIT", |
1509
20