Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

reduce-array-object

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reduce-array-object

Small module to reduce arrays to objects supporting customized parameters.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

reduce-array-object

reduce-array-object is a small module to reduce arrays to objects supporting customized parameters. You can pass a numeric array or an array of objects and define what parater to use as key or value (default key: index, default value: item)

Install

You can install with [npm]:

$ npm install --save reduce-array-object

Usage

Please check the index.test.js to get a full list of examples but a typical use case in the following:


// Array of objects with country data.

const countries = [
  { name: 'Colombia', code: 'co', area: 1197411 },
  { name: 'Argentina', code: 'ar', area: 2766890 },
  { name: 'Canada', code: 'ca', area: 9984670 },
  { name: 'Brasil', code: 'br', area: 8511965 }
]

// Importing this module
const arrObjReducer = require('reduce-array-object')

// Reduce using the country code as key and the name as value.
const reduced = arrObjReducer((countries, {key: 'code', value: 'name'}))

// output: { co: 'Colombia', ar: 'Argentina', ca: 'Canada', br: 'Brasil' }

In conclusion the first parameter is the array to reduce and the second parameter is a configuration object where you can optionally define the key and value parameters to be used in the resulting object.

Running tests

You can run the tests and check the functionality of this module using:

$ npm test

License

Copyright © 2020, Juan Convers. Released under the MIT License.

Keywords

FAQs

Package last updated on 02 Aug 2020

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc