hash-set-map
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

NPM version Build Status Coverage Status

hash-set-map

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.

Install

npm i hash-set-map

The current version supports node v10+ and modern browsers.

Usage

  • 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()

Example

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.

Package Sidebar

Install

npm i hash-set-map

Weekly Downloads

3,974

Version

2.0.0

License

MIT

Unpacked Size

36.4 kB

Total Files

18

Last publish

Collaborators

  • caselit