npm

Need private packages and team management tools?Check out npm Orgs. »

arraify

1.2.1 • Public • Published

arraify

Convert a value to an array

Install

$ npm install arraify

Usage

const arrify = require('arraify');
 
const obj = {
  0: 'zero',
  1: 'one',
  length: 2,
};
arrify(obj);
// ['zero', 'one']
 
const obj = {
  0: 'zero',
  1: 'one',
  length: 3,
};
 
arrify.config.arraySimilarity = 2;
arrify(obj);
// [{ 0: 'zero', 1: 'one', length: 3 }]
arrify.config.arraySimilarity = 1;
arrify(obj);
// [{ 0: 'zero', 1: 'one', length: 3 }]
 
arrify.config.arraySimilarity = 0;
arrify(obj);
// ['zero', 'one', undefined]
 
arrify(1, 2, 3);
// [1, 2, 3]
 
arrify('string');
// ['s', 't', 'r', 'i', 'n', 'g']
 
arrify.config.splitString = false;
arrify('string');
// ['sting']
 
arrify([]);
// []
 
arrify();
// []
 
arrify(null);
// []
 
arrify(undefined);
// []

Configs

arrify.config = {
  splitString: true,
  arraySimilarity: 2,
};

splitString:

true | false, and true is the default

arraySimilarity:

0 | 1 | 2, and 2 is the default

License

MIT © Gyumeijie

install

npm i arraify

Downloadsweekly downloads

1

version

1.2.1

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability