array-2-object
v1.1.0
Published
Returns a new object from a given array
Downloads
13
Maintainers
Readme
array-2-object
Returns an object from a given array
Table of Contents
Install
Using npm
npm install --save array-2-object
Usage
Signature
array2object (array: Array, [options: Object], [callback: Function]): Object
Default options
{
base: {},
value: null
}
const array2object = require('array-2-object')
Examples given the following array
const array = [
'V', 'version',
'n', 'name'
]
const object = array2object(array)
/* object
* {
* "version": null,
* "name": null,
* "V": null,
* "n": null
* }
*/
With a different initial value
const options = {value: "foo"}
const object = array2object(array, options)
/* object
* {
* "version": "foo",
* "name": "foo",
* "V": "foo",
* "n": "foo"
* }
*/
With a different initial value and a base object
const base = {
"dependencies": "bar",
"S": "bar"
}
const options = {
value: "foo",
base: base
}
const object = array2object(array, options)
/* object
* {
* "dependencies": "bar",
* "version": "foo",
* "name": "foo",
* "S": "bar",
* "V": "foo",
* "n": "foo"
* }
*/
Contribute
PRs accepted & greatly appreciated.
Tests
npm install
npm test
Dependencies
None
Dev Dependencies
- codecov: Uploading report to Codecov: https://codecov.io
- nyc: the Istanbul command line interface
- rimraf: A deep deletion module for node (like
rm -rf
) - tape: tap-producing test harness for node and browsers
License
MIT