All projects

HSC

Human Short Code (HSC)

Released

HSC turns long numeric IDs into short codes people can read, say and type: 987654 becomes QRQW-ISAA and decodes back. Encoding is reversible on its own, without a lookup table or a database, and the alphabet and code length are configurable.

Gallery

Example

$ npm i human-short-code
import { hsc } from "human-short-code";

const myNumber = 123456789;

// Encode number to short code
const shortCode = hsc.encode(myNumber);
console.log(shortCode); // Example output: "QIUN-ESAD"

// Decode short code back to number
const originalNumber = hsc.decode(shortCode);
console.log(originalNumber); // 123456789

// Verify if a code is valid
const isValid = hsc.verify(shortCode);
console.log(isValid); // true