hashids

  • Version 2.2.8
  • Published
  • 127 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

Functions

function keepUnique

keepUnique: <T>(content: Iterable<T>) => T[];

    function onlyChars

    onlyChars: (chars: string[], keepChars: string[]) => string[];

      function withoutChars

      withoutChars: (chars: string[], withoutChars: string[]) => string[];

        Classes

        class Hashids

        class Hashids {}

          constructor

          public 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): string;
                (numbers: NumberLike[]): string;
                (...numbers: NumberLike[]): string;
                (numbers: string[]): string;
                (...numbers: string[]): string;
                };

                  method encodeHex

                  encodeHex: (hex: string | bigint) => 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;

                    Package Files (1)

                    Dependencies (0)

                    No dependencies.

                    Dev Dependencies (32)

                    Peer Dependencies (0)

                    No peer dependencies.

                    Badge

                    To add a badge like this onejsDocs.io badgeto 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>