hashids
- Version 2.3.0
- Published
- 137 kB
- No dependencies
- MIT license
Install
npm i hashids
yarn add hashids
pnpm add hashids
Overview
Generate YouTube-like ids from numbers. Use Hashids when you do not want to expose your database ids to the user.
Index
Classes
class Hashids
class Hashids {}
constructor
constructor(salt?: string, minLength?: number, alphabet?: string, seps?: string);
method decode
decode: (id: string) => NumberLike[];
method decodeHex
decodeHex: (id: string) => string;
method encode
encode: { (numbers: string | NumberLike[] | string[]): string; (...numbers: NumberLike[]): string; (...numbers: string[]): string;};
method encodeHex
encodeHex: (inputHex: bigint | string) => string;
Splits a hex string into groups of 12-digit hexadecimal numbers, then prefixes each with '1' and encodes the resulting array of numbers
Encoding '00000000000f00000000000f000f' would be the equivalent of: Hashids.encode([0x100000000000f, 0x100000000000f, 0x1000f])
This means that if your environment supports BigInts, you will get different (shorter) results if you provide a BigInt representation of your hex and use
encode
directly, e.g.: Hashids.encode(BigInt(0x${hex}
))To decode such a representation back to a hex string, use the following snippet: Hashids.decode(id)[0].toString(16)
method isValidId
isValidId: (id: string) => boolean;
Namespaces
namespace nodemark
module 'nodemark' {}
variable benchmark
const benchmark: { ( subject: () => any, setup?: () => any, durationMillis?: number ): BenchmarkResult; ( subject: (callback: (...args: unknown[]) => void) => any, setup?: () => any, durationMillis?: number ): Promise<BenchmarkResult>;};
namespace require-from-web
module 'require-from-web' {}
function requireFromWeb
requireFromWeb: <T>(url: string) => Promise<T>;
Package Files (2)
Dependencies (0)
No dependencies.
Dev Dependencies (4)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/hashids
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/hashids)
- HTML<a href="https://www.jsdocs.io/package/hashids"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 4046 ms. - Missing or incorrect documentation? Open an issue for this package.