Skip to content

parseCustomId

parseCustomId(customId, onlyPrefix): string

Defined in: utils/index.ts:33

Parse a custom ID string into its parts.

Supports two modes:

  • onlyPrefix = true: returns the prefix string before the first ‘/’ or ‘?’.
  • onlyPrefix = false (default): returns an object with parsed pieces.

Expected customId shapes:

  • “prefix/component/other/path?param1/param2”
  • “prefix?param1/param2”

string

The custom ID to parse.

true

If true, only return the prefix string (default: false).

string

If onlyPrefix is true: string (the prefix). Otherwise an object with:

  • compPath: string[] (full path split by ‘/’),
  • prefix: string (first item of compPath),
  • lastPathItem: string (last item of compPath),
  • component: string | null (second item of compPath or null),
  • params: string[] (params split by ‘/’; empty array when none),
  • firstParam: string | null,
  • lastParam: string | null
parseCustomId("modal/user/profile?123/abc")
// => { compPath: ["modal","user","profile"], prefix: "modal", ... params: ["123","abc"], ... }
parseCustomId("button/click", true)
// => "button"

parseCustomId(customId, onlyPrefix?): object

Defined in: utils/index.ts:34

Parse a custom ID string into its parts.

Supports two modes:

  • onlyPrefix = true: returns the prefix string before the first ‘/’ or ‘?’.
  • onlyPrefix = false (default): returns an object with parsed pieces.

Expected customId shapes:

  • “prefix/component/other/path?param1/param2”
  • “prefix?param1/param2”

string

The custom ID to parse.

false

If true, only return the prefix string (default: false).

object

If onlyPrefix is true: string (the prefix). Otherwise an object with:

  • compPath: string[] (full path split by ‘/’),
  • prefix: string (first item of compPath),
  • lastPathItem: string (last item of compPath),
  • component: string | null (second item of compPath or null),
  • params: string[] (params split by ‘/’; empty array when none),
  • firstParam: string | null,
  • lastParam: string | null

component: string | null

compPath: string[]

firstParam: string | null

lastParam: string | null

lastPathItem: string

params: string[]

prefix: string

parseCustomId("modal/user/profile?123/abc")
// => { compPath: ["modal","user","profile"], prefix: "modal", ... params: ["123","abc"], ... }
parseCustomId("button/click", true)
// => "button"