arraywrap

if it's not an array, wrap it in an array. if it's already an array, do nothing.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
arraywrap
2.0.06 days ago8 years agoMinified + gzip package size for arraywrap in KB

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).