1.0.4 • Published 3 years ago

ts-index-map v1.0.4

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

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
1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago