argu
v0.1.4
Published
Helper for preprocessing arguments before passing to functions
Downloads
14
Readme
argu
Helper for preprocessing arguments before passing to functions
Usage
Helpers in this package help make sure that arguments passed to functions are arrays when arrays are expected, objects when objects are expected and the like.
toArray
toArray
takes all arguments and returns an array of them if not already an array.
import {toArray} from 'argu';
toArray(); // []
toArray(1); // [1]
toArray([1]); // [1]
toArray(1, 2); // [1, 2]
toArray(1, [2]); // [1, [2]]
toArray([1], 2); // [[1], 2]
toArray([1, 2]); // [1, 2]
toArrayOfArrays
toArrayOfArrays
takes all arguments and returns an array of arrays, if not already that.
import {toArrayOfArrays} from 'argu';
toArrayOfArrays(); // [[]]
toArrayOfArrays(1); // [[1]]
toArrayOfArrays([1]); // [[1]]
toArrayOfArrays(1, 2); // [[1], [2]]
toArrayOfArrays(1, [2]); // [[1], [2]]
toArrayOfArrays([1], 2); // [[1], [2]]
toArrayOfArrays([1, 2]); // [[1], [2]]
toArrayOfArrays([1], [2]); // [[1], [2]]
toArrayOfArrays([[1], 2]); // [[1], [2]]
License
argu is MIT licensed.
© 2016 Jason Lenoble