A map where the keys are Sets. Any two equivalent sets map to the same key, even when they are different objects.
This is useful for grouping and caching over select properties in an environment where the Set object is not necessarily shared.
- Set-based Keys: Use Sets as keys in a Map-like interface
- The Key is the Set Content: Different Set instances with equivalent elements are matching keys
- Full Map Interface: Implements the complete Map interface
- Array-like Interface: Implements additional array-like methods
- Type Safe: Full TypeScript support with generic type parameters
import { SetKeyedMap } from "set-keyed-map";
const setKeyedMap = new SetKeyedMap<string, number>();
const key1 = new Set(["a", "b", "c"]);
const key2 = new Set(["a", "b", "c"]); // Different object, equivalent elements
setKeyedMap.set(key1, 100);
// These are equivalent - both return 100
console.log(setKeyedMap.get(key1)); // 100
console.log(setKeyedMap.get(key2)); // 100
console.log(setKeyedMap.has(key2)); // trueset(key, value)- Add or update a key-value pairget(key)- Retrieve value by keyhas(key)- Check if key existsdelete(key)- Remove key-value pairclear()- Remove all entriessize- Number of entrieskeys(),values(),entries()- IteratorsforEach(callback)- Iterate over entries
every(callback)- Test if all entries pass conditionsome(callback)- Test if any entry passes conditionfilter(callback)- Create new SetKeyedMap with filtered entriesfind(callback)- Find first entry matching conditionincludes(value)- Check if value existsmap(callback)- Map entries to arrayflatMap(callback)- Map and flatten entries to arraymapOver(callback)- Map entries to new SetKeyedMapreduce(callback, initial)- Reduce entries to single valuereduceRight(callback, initial)- Reduce entries right-to-left
KT- Type of elements within the Set keysV- Type of values stored in the mapK- Type of Set keys (defaults toSet<KT>)
MIT
