0.1.3 • Published 2 years ago

@btnguyen2k/checksum v0.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@btnguyen2k/checksum

npm Release Actions Status codecov

šŸ”§ Configurable hash functions: md5, sha1, sha256 and sha512.

⭐ Supported data types:

  • Primitive
  • Special values: NaN, null, undefined and Infinity
  • Function
  • Array
  • Object
  • Built-in objects:
    • Symbol
    • Error
    • Date
    • RegExp
    • Arrays (include IntxxxArray, FloatxxxArray, UintxxxArray, ArrayBuffer and DataView)
    • Map (WeakMap is not supported!)
    • Set (WeakSet is 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/checksum

Usage

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.

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago