You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

cast-to-array

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cast-to-array

Cast a value to an array.

0.1.0
latest
Source
npmnpm
Version published
Weekly downloads
2
100%
Maintainers
1
Weekly downloads
 
Created
Source

cast-to-array NPM version

Cast a value to an array.

Install

Install with npm

$ npm i cast-to-array --save

Usage

var arrayify = require('cast-to-array');

returns an empty array when value is null or undefined

arrayify(null);
arrayify(undefined);
//=> []

casts a non-array value to an array

arrayify('abc');
//=> ['abc']

arrayify(/xyz/);
//=> [/xyz/]

arrayify(new RegExp('.'));
//=> [new RegExp('.')]

arrayify([[]]);
//=> [[]]

arrayify({});
//=> [{}]

returns an array directly

arrayify(['foo']);
//=> ['foo']

arrayify([]);
//=> []

Similar projects

  • arr-map: Faster, node.js focused alternative to JavaScript's native array map. | homepage
  • array-last: Get the last or last n elements in an array. | homepage
  • array-map: [].map(f) for older browsers | homepage
  • array-sum: Add up all of the numbers in an array of numbers. Works when non-numbers are… more | homepage
  • array-xor: Returns the symmetric difference (exclusive-or) of an array of elements (elements that are present in… more | homepage

Running tests

Install dev dependencies:

$ npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Author

Jon Schlinkert

License

Copyright © 2015 Jon Schlinkert Released under the MIT license.

This file was generated by verb-cli on November 06, 2015.

FAQs

Package last updated on 06 Nov 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.