# deterministic-hash

> A deterministic value hashing algorithm for node.js.

Latest version **1.1.0** (published 2022-01-27) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install deterministic-hash
pnpm add deterministic-hash
yarn add deterministic-hash
bun add deterministic-hash
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2022-01-27 |
| First published | 2022-01-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 15 |
| Author | Zane Bauman |
| Maintainers | zbauman3 |
| Keywords | deterministic, hash, algorithm |

## Links

- npm: https://www.npmjs.com/package/deterministic-hash
- Repository: https://github.com/zbauman3/Deterministic-Hash
- Homepage: https://github.com/zbauman3/Deterministic-Hash#readme
- Issues: https://github.com/zbauman3/Deterministic-Hash/issues
- npm.io page: https://npm.io/package/deterministic-hash

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2022-01-27
- 1.0.2 — 2022-01-26
- 1.0.1 — 2022-01-26
- 1.0.0 — 2022-01-26

## README

# Deterministic-Hash
A deterministic value hashing algorithm for node.js.

## Usage
Pass any Javascript value and receive a deterministic hash (in hexadecimal) of the value. If an object is passed, only own enumerable string-keyed properties are used, the order of the keys does not matter as long as all of the values match.

```typescript
import deterministicHash from 'deterministic-hash';

const objA = { a: 'x', arr: [1,2,3,4], b: 'y' };
const objB = { b: 'y', a: 'x', arr: [1,2,3,4] };

deterministicHash({
	c: [ objA, objB ],
	b: objA,
	e: objB,
	f: ()=>{ Math.random(); },
	g: Symbol('Unique identity'),
	h: new Error('AHHH')
});
// -> 455b32a99a84efad551409b39bd91fc028a98343

deterministicHash({
	h: new Error('AHHH'),
	e: objB,
	g: Symbol('Unique identity'),
	b: objA,
	f: ()=>{ Math.random(); },
	c: [ objA, objB ]
});
// -> 455b32a99a84efad551409b39bd91fc028a98343
```

## Settings

A hash algorithm can be passed as the second argument. This takes any value that is valid for `crypto.createHash`. The default is `sha1`.

```typescript
deterministicHash('value', 'sha1');
// -> f32b67c7e26342af42efabc674d441dca0a281c5
deterministicHash('value', 'sha256');
// -> cd42404d52ad55ccfa9aca4adc828aa5800ad9d385a0671fbcbf724118320619
deterministicHash('value', 'sha512');
// -> ec2c83edecb60304d154ebdb85bdfaf61a92bd142e71c4f7b25a15b9cb5f3c0ae301cfb3569cf240e4470031385348bc296d8d99d09e06b26f09591a97527296
```

## Support
Currently this has only been tested on Node.js `16.3.x`. More tests are to come and this section will be updated as I test them.

---
_Source: https://npm.io/package/deterministic-hash · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
