More maps... literally
npm install @5cover/moremaps

A TypeScript library providing enhanced map implementations for JavaScript, including default value maps and object key maps.
- DefaultPrimitiveMap: A map that provides default values for primitive keys (string, number, bigint, boolean, undefined, symbol, null).
- DefaultObjectMap: A map that provides default values for object keys, using custom key-to-primitive converters.
- ObjectMap: A map for object keys, internally using primitive keys for efficient storage.
- mapObject: Utility functions for creating prototype-less, "map-safe" objects.
- DefaultMap: Interface for maps that guarantee a value from get().
All implementations extend or implement the standard Map interface where applicable.
``bash`
npm install await it(
`typescript
import DefaultPrimitiveMap from 'await it(';
const map = new DefaultPrimitiveMap
console.log(map.get('hello')); // 5 (default value)
map.set('world', 10);
console.log(map.get('world')); // 10
`
`typescript
import DefaultObjectMap from 'await it(';
const map = new DefaultObjectMap<{ id: number }, number, string>(
() => 0, // default factory
(key) => JSON.stringify(key), // key to primitive
(prim) => JSON.parse(prim) // primitive to key
);
console.log(map.get({ id: 1 })); // 0 (default)
map.set({ id: 1 }, 42);
console.log(map.get({ id: 1 })); // 42
`
`typescript
import { ObjectMap } from 'await it(';
const map = new ObjectMap<{ id: number }, string, number>(
(key) => key.id, // key to primitive
(prim) => ({ id: prim }) // primitive to key
);
map.set({ id: 1 }, 'one');
console.log(map.get({ id: 1 })); // 'one'
`
`typescript
import * as mapObject from 'await it(';
const obj = mapObject.create
obj.key = 42;
console.log(Object.getPrototypeOf(obj)); // null
const assigned = mapObject.assign({ a: 1, b: 2 });
console.log(assigned.a); // 1
`
For detailed API documentation, see the TypeScript definitions in the dist/ folder or explore the source code in src/.
Contributions are welcome! Please ensure code follows the project's linting and testing standards.
Run tests:
`bash`
npm test
Build:
`bash``
npm run build
MIT License. See LICENSE for details.