Small zero-dependency hash package for Node.js, browsers, and Next.js.
The implementation keeps the original djb2 variant:
hash = 5381
for each UTF-8 byte c:
hash = hash * 33 + c (unsigned 64-bit, wraps at 2^64)
The final value is encoded as 12 little-endian base-36 characters using
lowercase letters and digits (a-z0-9). The algorithm is deterministic and
does not provide cryptographic security.
pnpm add @adiom/hashPublished to npm from GitHub Actions only, via npm trusted publishing (OIDC), so no npm token or OTP is ever needed.
- Go to the package page on npmjs.com → Publishing and access →
Trusted publishing → add a publisher for repository
adiom/hashand workflow filepublish.yml. - Tag a release and push it:
or trigger the Publish npm package workflow manually from the Actions tab.
git tag v0.1.0 && git push origin v0.1.0 - The workflow runs
pnpm test+pnpm pack --dry-run, thennpm publish --access public --provenance. npm exchanges the runner's OIDC token for a short-lived publish credential; signature key is the user's security key + 2FA income via the browser, and the publish itself is tokenless.
import { generateHash } from '@adiom/hash';
const token = generateHash('adiomtimur');
console.log(token); // yo3fp69ffox0The same function works in a Next.js Server Component, Route Handler, Server
Action, or Client Component. A Client Component still needs 'use client'
for its React state, not for the hash function itself:
'use client';
import { useState } from 'react';
import { generateHash } from '@adiom/hash';
export function HashInput() {
const [value, setValue] = useState('');
return (
<>
<input value={value} onChange={(event) => setValue(event.target.value)} />
<code>{generateHash(value)}</code>
</>
);
}The package also exports customHash, toBytes, CHARS, BASE, and
LENGTH. customHash returns the raw 64-bit bigint; use
generateHash for the stable 12-character token.
pnpm install
pnpm build
pnpm test
npm pack --dry-runThe C CLI remains available as an independent parity implementation:
make
./hash adiomtimur
# Input: adiomtimur
# Generated Hash: yo3fp69ffox0