argu

Helper for preprocessing arguments before passing to functions

Usage no npm install needed!

<script type="module">
  import argu from 'https://cdn.skypack.dev/argu';
</script>

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