rrrfffrrr / arraywrap.js

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

Home Page:https://www.npmjs.org/package/arraywrap

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

array wrap dot js

npm version

If it's not an array, make it one:

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([]); // => []

var arr = [1, 2];
arrayWrap(arr) === arr; // true

To use it in Node/Browserify/Webpack:

var arrayWrap = require("arraywrap");
arrayWrap(47);

To use it in the browser:

<script src="arraywrap.js"></script>
<script>
  arrayWrap(47);
</script>

This should support environments that don't have Array.isArray (like IE8 and below).

About

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

https://www.npmjs.org/package/arraywrap

License:MIT License


Languages

Language:JavaScript 100.0%