https://github.com/i404788/xxh3-ts
xxhash implementation in pure typescript (using tc39 bigint), supports XXH64 & XXH3-128
https://github.com/i404788/xxh3-ts
bigint esnext tc39 typescript xxh3 xxhash
Last synced: 3 months ago
JSON representation
xxhash implementation in pure typescript (using tc39 bigint), supports XXH64 & XXH3-128
- Host: GitHub
- URL: https://github.com/i404788/xxh3-ts
- Owner: i404788
- License: bsd-2-clause
- Created: 2019-12-21T20:47:00.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2025-02-27T09:17:20.000Z (over 1 year ago)
- Last Synced: 2025-09-22T03:56:31.478Z (9 months ago)
- Topics: bigint, esnext, tc39, typescript, xxh3, xxhash
- Language: TypeScript
- Homepage:
- Size: 32.2 KB
- Stars: 8
- Watchers: 1
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# xxh3-ts
xxhash implementation in pure typescript (using tc39 bigint), supports XXH64 & XXH3-128.
These algorithms require Node.js >=12.x, because of `Buffer::readBigUInt64LE` or [`browser`](https://www.npmjs.com/package/buffer) polyfill in browser.
## Usage:
```ts
import { XXH64 } from 'xxh3-ts';
import { Buffer } from 'buffer'; // if in browser.
let hash: bigint = XXH64(Buffer.from(JSON.stringify(v)))
```
For conversion back to buffer it's recommended to use [bigint-buffer](https://www.npmjs.com/package/bigint-buffer) package or the following snippet:
```ts
function toBufferBE(num: bigint): Buffer {
const hex = num.toString(16);
// Padding *is* needed otherwise the last nibble will be dropped in an edge case
return Buffer.from(hex.padStart(Math.ceil(hex.length/2) * 2, '0'), 'hex');
}
```
## Compatibility
XXH64 & XXH3-128 were derived from the [specifications](https://github.com/Cyan4973/xxHash/blob/v0.8.3/doc/xxhash_spec.md#xxh3-algorithm-overview) and is input/output compatible with [upstream v0.8.3](https://github.com/Cyan4973/xxHash/blob/v0.8.3)