SmartMap is a simple and efficient indexed map for Node and browser environments.
You may install the package via:
npm install smartmap
git clone https://github.com/emmorts/smartmap
Documentation is available here
interface MyInterface {
id: number;
value: number;
}
const map = new SmartMap<MyInterface>("id");
map.add(...[
{ id: 1, value: 1 },
{ id: 2, value: 4 },
{ id: 3, value: 9 }
]);
for (const item in map) {
console.log(item);
}
/*
{
id: 1,
value: 1
},
{
id: 2,
value: 4
},
{
id: 3,
value: 9
}
*/
Objects can also be mapped with multiple indexes.
const map = new SmartMap<MyInterface>("id", "value");
map.add(...[
{ id: 1, value: 1 },
{ id: 2, value: 4 },
{ id: 3, value: 9 }
]);
for (const item in map.iterateBy("value")) {
console.log(item);
}
/*
{
id: 1,
value: 1
},
{
id: 2,
value: 4
},
{
id: 3,
value: 9
}
*/
Generated using TypeDoc