JSPM

hash-fns

1.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 277
  • Score
    100M100P100Q89099F
  • License MIT

easily create, assess, and assure hashes within a pit-of-success

Package Exports

  • hash-fns
  • hash-fns/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (hash-fns) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

hash-fns

test publish

easily create, assess, and assure hashes within a pit-of-success

install

npm install hash-fns

use

for example

import { Hash, toHashSha256, isHashSha256 } from 'hash-fns';

// create a hash
const versionHash: Hash = await toHashSha256('some data');

// verify that a given value is a valid hash
const foundHash: Hash = isHashSha256.assure('__hash__');

// typeguard against random strings being passed as hashes
const expectHash: Hash = 'some string'; // 🛑 typescript will throw an error, since string is not assignable to Hash

// use a hash within functions that expect strings
const expectWords: string = await toHashSha256('some data'); // ✅ passes, as Hash is assignable to strings

🔧 mechs

asHashMd5(message: string): Promise<Hash>

  • .what: creates a 128-bit MD5 hash from a UTF-8 string
  • .why: fast and compact for non-secure use cases like fingerprinting, deduplication, or cache busting

example:

const cacheKey = await asHashMd5('GET /api/resource?id=123');

asHashSha256(message: string): Promise<Hash>

  • .what: creates a 256-bit SHA-256 hash from a UTF-8 string
  • .why: cryptographically secure hash for versioning, signatures, and data integrity

example:

const versionTag = await asHashSha256(JSON.stringify(configObject));

asHashShake256(message: string, options?: { bytes: number }): Promise<Hash>

  • .what: creates a variable-length cryptographic hash using SHAKE256 (Keccak sponge function)
  • .why: ideal when you need a specific hash length, such as for compact tokens, extended fingerprints, or key material

example:

const customHash = await asHashShake256('some secret', { bytes: 64 }); // 512-bit output