Set
and Map
extension to prove a custom key derivation function. It also supports JSON serialization and de-serialization
The original Set
and Map
object are not modified, so can still be used.
This library does not provides polyfills for Set and Map.
npm i hash-set-map
The current version supports node v10+
and modern browsers.
- Typescript and es6
import { Set, Map } from 'hash-set-map'
- Nodejs
var Set = require('hash-set-map').Set;
var Map = require('hash-set-map').Map;
The unmodified Set and Map class can still be used:
import { Set as hSet, Map as hMap } from 'hash-set-map'
let originalMap = new Map()
let originalSet = new Set()
let hashMap = new hMap()
let hashSet = new hSet()
export function dateToKey(d: Date) {
return d.valueOf();
}
const set = new Set([new Date(1), new Date(1)], dateToKey);
set.size // size is 1
set.has(new Date(1)) // returns true
export function stringIgnoreCase(s: string) {
return s.toLowerCase();
}
const map = new Map([['a', 1], ['b', 3], ['C', 3]], stringIgnoreCase);
map.get('c') // returns 3
map.set('c', 42);
map.get('C') // returns 42
For further documentation on toJSON
and fromJSON
methods refer to json-set-map.
Refer to the JSDoc documentation on the files for mode details.