2.0.1 • Published 10 months ago

idxd v2.0.1

Weekly downloads
196
License
MIT
Repository
github
Last release
10 months ago

idxd

A tiny (81 bytes) function for indexing arrays of objects by some key.

Install

$ yarn add idxd

Usage

import idxd from 'idxd';

const users = [
  { id: '001', firstName: 'John', lastName: 'Chrysostom' },
  { id: '002', firstName: 'Basil', lastName: 'the Great' },
  { id: '003', firstName: 'Gregory', lastName: 'of Nyssa' },
  { id: '004', firstName: 'Ephrem', lastName: 'the Syrian' },
];

const usersByLastName = idxd(users, 'lastName');
/* =>
{
  'Chrysostom': {
    id: '001',
    firstName: 'John',
  },
  'the Great': {
    id: '002',
    firstName: 'Basil',
    lastName: 'the Great',
  },
  'of Nyssa': {
    id: '003',
    firstName: 'Gregory',
  },
  'the Syrian': {
    id: '004',
    firstName: 'Ephrem',
  }
}
*/

API

idxd(list, key)

list

Type: Array<Record<any, any>>

Required: ✅

A list of objects that you wish to be indexed.

Note: If the value of the key you wish to index by is shared by another object, the last object with that value will overwrite all others.

key

Type: string

Required: ✅

The name of the field you wish to index on.

2.0.1

10 months ago

2.0.0

10 months ago

1.0.1

4 years ago

1.0.0

4 years ago