ts-index-map
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

TS Index Map

A data structure that allows indexing by multiple fields for fast data access.

Basic Usage

Pass the data and an array of index fields to the constructor. Get the data with a field and value.

import IndexMap from 'ts-index-map';

function Get() {
    const Data = [{a: 1, b: 2, c: 3}, 
    {a: 1, b: 3, c: 2}, {a: 3, b: 2, c: 1}];
    const Indexed = new IndexMap(['a', 'b'], Data);

    const A1 = Indexed.get('a', 1);
    const B2 = Indexed.get('b', 2);

    //prints [{a: 1, b: 2, c: 3}, {a: 1, b: 3, c: 2}]
    console.log(A1);

    //prints [{a: 1, b: 2, c: 3}, {a: 3, b: 2, c: 1}]
    console.log(B2);
}

API

new IndexMap(indexes, data); //data and indexes are optional
size; //the number of data entries
indexes; //the number of indexes
addIndex(field); //indexes the data by another index
removeIndex(field); //removes an index
values(); //gets an iterable of values
add(...data); //adds data
has(field, value); //does the data exist by field and value
get(field, value); //gets the data by field and value
delete(field, value); //removes the data by field and value

Readme

Keywords

Package Sidebar

Install

npm i ts-index-map

Weekly Downloads

0

Version

1.0.4

License

ISC

Unpacked Size

10.5 kB

Total Files

5

Last publish

Collaborators

  • cph0