@btnguyen2k/checksum v0.1.3
@btnguyen2k/checksum
š§ Configurable hash functions: md5, sha1, sha256 and sha512.
ā Supported data types:
- Primitive
- Special values:
NaN,null,undefinedandInfinity - Function
- Array
- Object
- Built-in objects:
SymbolErrorDateRegExp- Arrays (include
IntxxxArray,FloatxxxArray,UintxxxArray,ArrayBufferandDataView) Map(WeakMapis not supported!)Set(WeakSetis not supported!)
š« Support nested data structure of any supported type above.
Checksum rules
š checksum(null|undefined) returns empty string ('').
š numbers (int, float, bigint) have the same checksum: checksum(1) === checksum(1.0) === checksum(1n).
š order of object properties do not affect checksum: checksum({a: 1, b: 2}) === checksum({b: 2, a: 1}).
š order of map entries do not affect checksum: checksum(new Map([['a', 1], ['b', 2]])) === checksum(new Map([['b', 2], ['a', 1]])).
š order of set entries do not affect checksum: checksum(new Set([1, 2])) === checksum(new Set([2, 1])).
š map and object with the same entries have the same checksum: checksum(new Map([['a', 1], ['b', 2]])) === checksum({a: 1, b: 2}).
š objects of different classes with the same entries have differnt checksums: checksum(new Map([['a', 1], ['b', 2]])) !== checksum(new (class {a = 1; b = 2})()).
Installation
with npm
$ npm install -S @btnguyen2k/checksumUsage
import {checksum} from '@btnguyen2k/checksum'
// use default hash function
console.log(checksum('a string'))
// specify a hash function
console.log(checksum([1, 'a string', true]))License
MIT - see LICENSE.md.