Socket
Book a DemoInstallSign in
Socket

objectify-array

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

objectify-array

Recursively convert arrays of objects into a single keyed object tree

Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

objectify-array Build Status

Recursively convert arrays of objects into a single keyed object tree

Installation

npm install objectify-array --save

or

yarn add objectify-array

Usage

const objectifyArray = require('objectify-array')

var people = [
  {id: 'bob', fullName: 'Bob Bobberson'},
  {id: 'sue', fullName: 'Sue Zinn'},
  {id: 'hal', fullName: 'Hal Itosis'}
]

var tree = objectifyArray(people)

This will return an object, using the id property values as keys:

{
  bob: { id: 'bob', fullName: 'Bob Bobberson' },
  sue: { id: 'sue', fullName: 'Sue Zinn' },
  hal: { id: 'hal', fullName: 'Hal Itosis'}
}

id and name are supported by default. If you want to use another property, specify it as an optional second argument:

var tree = objectifyArray(people, 'myCustomKeyName')

If your array contains nested arrays of objects, those are objectified too! For more extensive usage examples, see test.js

API

The module exports a single function:

objectifyArray(array[, keyName])

  • array Array
  • keyName String (optional) - A property other than id or name to use for the object keys.

Tests

npm i && npm t

Dependencies

None

Dev Dependencies

  • standard: JavaScript Standard Style
  • tap-spec: Formatted TAP output like Mocha's spec reporter
  • tape: tap-producing test harness for node and browsers

License

MIT

Keywords

array

FAQs

Package last updated on 26 Oct 2016

Did you know?

Socket

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