Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • Hashids

Index

Constructors

constructor

  • new Hashids(salt?: string, minLength?: number, alphabet?: string, seps?: string): Hashids
  • Parameters

    • Default value salt: string = ""
    • Default value minLength: number = 0
    • Default value alphabet: string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
    • Default value seps: string = "cfhistuCFHISTU"

    Returns Hashids

Properties

Private alphabet

alphabet: string

Private guards

guards: string

Private minLength

minLength: number

Private salt

salt: string

Private seps

seps: string

Methods

Private _decode

  • _decode(id: string, alphabet: string): NumberLike[]
  • Parameters

    • id: string
    • alphabet: string

    Returns NumberLike[]

Private _encode

  • Parameters

    Returns string

decode

  • Parameters

    • id: string

    Returns NumberLike[]

decodeHex

  • decodeHex(id: string): string
  • Parameters

    • id: string

    Returns string

encode

  • encode(numbers: string): string
  • encode(numbers: NumberLike[]): string
  • encode(...numbers: NumberLike[]): string
  • encode(numbers: string[]): string
  • encode(...numbers: string[]): string
  • Parameters

    • numbers: string

    Returns string

  • Parameters

    Returns string

  • Parameters

    Returns string

  • Parameters

    • numbers: string[]

    Returns string

  • Parameters

    • Rest ...numbers: string[]

    Returns string

encodeHex

  • encodeHex(hex: string | bigint): string
  • description

    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)

    Parameters

    • hex: string | bigint

    Returns string

Generated using TypeDoc