Socket
Socket
Sign inDemoInstall

cast-to-array

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    cast-to-array

Cast a value to an array.


Version published
Maintainers
1
Install size
4.38 kB
Created

Readme

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

Last updated on 06 Nov 2015

Did you know?

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc