1.2.1 • Published 5 years ago

arraify v1.2.1

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

arraify npm.io

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