array-2-object

1.1.0 • Public • Published

array-2-object

CircleCI Codecov npm

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"
 * }
 */

standard-readme compliant David David

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

Package Sidebar

Install

npm i array-2-object

Weekly Downloads

7

Version

1.1.0

License

MIT

Last publish

Collaborators

  • mrzmmr