Skip to content

xxhash implementation in pure typescript (using tc39 bigint), supports XXH64 & XXH3-128

License

Notifications You must be signed in to change notification settings

i404788/xxh3-ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

6d5a713 · Feb 27, 2025

History

17 Commits
Dec 22, 2019
Feb 8, 2025
Dec 21, 2019
Feb 27, 2025
Feb 8, 2025
Feb 26, 2025
Feb 8, 2025
Dec 21, 2019
Feb 8, 2025
Jan 21, 2025
Feb 8, 2025

Repository files navigation

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 polyfill in browser.

Usage:

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 package or the following snippet:

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 and is input/output compatible with upstream v0.8.3