arraywrap
v2.0.0
Published
if it's not an array, wrap it in an array. if it's already an array, do nothing.
Downloads
746
Readme
arraywrap.js
If it's not an array, make it one:
const arraywrap = require("arraywrap");
arraywrap(123); // => [123]
arraywrap("yo"); // => ['yo']
arraywrap(null); // => [null]
arraywrap(undefined); // => [undefined]
arraywrap(); // => []
If it's already an array, do nothing:
arraywrap([1, 2, 3]); // => [1, 2, 3]
arraywrap([]); // => []
const arr = [1, 2];
arrayWrap(arr) === arr; // true
This supports environments that don't have Array.isArray
(like IE8 and below).