@btnguyen2k/checksum
v0.1.3
Published
Calculate checksum for any Javascript value
Readme
@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.
