Skip to content

Set and Map extension to prove a custom key derivation function

License

Notifications You must be signed in to change notification settings

CaselIT/hash-set-map

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Set and Map extension to prove a custom key derivation function

Resources

License

Stars

Watchers

Forks

Packages

No packages published