1.0.1 • Published 4 years ago

ridxd v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

ridxd

A tiny (143 bytes) function for reverse indexing a map into an array of objects with that index included.

Install

$ yarn add ridxd

Usage

import ridxd from 'ridxd';

const data = {
  'thing 1': {
    id: '001',
    member: 'Who',
  },
  'thing 2': {
    id: '002',
    member: 'Why',
  },
  'Cat in the Hat': {
    id: '003',
    member: 'How',
  }
};

const dataArray = ridxd(data, 'character');
/* =>
[
  { id: '001', member: 'Who', character: 'thing 1' },
  { id: '002', member: 'Why', character: 'thing 2' },
  { id: '003', member: 'How', character: 'Cat in the Hat' },
]
*/

API

ridxd(map, key)

ParameterTypeRequiredDescription
map{ [key: string]: <Record<any, any>> }trueAn indexed map of objects to reverse index into an array.
keystringtrueThe name of the field you wish the index to take on in each object.

Inspiration

This packages was inspired by idxd and the need for the reverse operation of it.