arraywrap
if it's not an array, wrap it in an array. if it's already an array, do nothing.
Last updated 10 years ago by evanhahn .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install arraywrap 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.1.0                                ...           latest (4 years ago)

5 Versions

  • 1.1.0                                ...           4 years ago
  • 1.0.0                                ...           9 years ago
  • 0.2.1                                ...           10 years ago
  • 0.2.0                                ...           11 years ago
  • 0.1.0                                ...           11 years ago
Maintainers (1)
Downloads
Today 0
This Week 1
This Month 1
Last Day 0
Last Week 1
Last Month 1
Dependencies (0)
None
Dev Dependencies (2)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |