0.1.2 • Published 9 years ago

reformat-array v0.1.2

Weekly downloads
6
License
MIT
Repository
github
Last release
9 years ago

Reformat objects in an array.

Requirements

This module is written using ES6. It uses classes. Be sure you use the latest version of iojs. If you don't, you should use reformat-array@0.0.5.

Install

Node

npm install --save reformat-array

Usage

const ReformatArray = require('reformat-array');
const reformattedArray = ReformatArray.mapToArray(array, key, target);

The following code takes an array of objects and creates a new array containing the newly reformatted objects.

const ReformatArray = require('format-array');

const countries = [{code: 'UK', nEntries: 10}, {code: 'FR', nEntries: 15}, {code: 'ESP', nEntries: 4}];

const reformattedArray = ReformatArray.mapToArray(countries, 'code', 'nEntries');

// reformattedArray is now [{UK: 10}, {FR: 15}, {ESP: 30}]
// countries is still [{code: 'UK', nEntries: 10}, {code: 'FR', nEntries: 15}, {code: 'ESP', nEntries: 4}]

The following code takes an array of objects and creates one dictionary containing the newly reformatted objects.

const ReformatArray = require('format-array');

const countries = [{code: 'UK', nEntries: 10}, {code: 'FR', nEntries: 15}, {code: 'ESP', nEntries: 4}];

const dictionary = ReformatArray.mapToDictionary(countries, 'code', 'nEntries');

// dictionary is now { UK: 10, FR: 15, ESP: 30 }
// countries is still [{code: 'UK', nEntries: 10}, {code: 'FR', nEntries: 15}, {code: 'ESP', nEntries: 4}]
0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago

0.0.9

9 years ago

0.0.8

9 years ago

0.0.7

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago