Skip to content

EJayCheng/hash-id

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HashId

HashId is a library that generates short, unique, non-sequential ids from numbers.

based on hashids

Getting Started

GitHub / npm

npm i id-hasher --save

import { HashId } from "id-hasher";
const hashId = new HashId({
  salt: "a17b3c3e73ad70620e87b7170f6857c7",
  minHashLength: 6,
  prefix: "PREFIX_",
  suffix: "_SUFFIX",
});

console.log(hashId.encode(10353)); // PREFIX_GJWMQ5_SUFFIX
console.log(hashId.decode("PREFIX_GJWMQ5_SUFFIX")); // 10353

Interface

export interface HashIdConfig {
  /** hash salt */
  salt: string;
  /** prefix of hashify */
  prefix?: string;
  /** suffix of hashify  */
  suffix?: string;
  /** min length of hashify, Default: 6 */
  minHashLength?: number;
  /** allow alphabet of hashify, Default: ABCDEFGHJKLMNPQRSTUVWXYZ23456789 */
  alphabet?: string;
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published