parseCustomId
Parses a custom ID string into its constituent parts. A custom ID is expected in the form:
"prefix[/component/...][?param1/param2/...]". The ? separates path and params.
Parameters
Section titled “Parameters”customId(string) — The custom ID to parse. Examples:"modal/user/profile?123/abc""button/click?123""prefix?param"
onlyPrefix?(boolean) — If true, the function returns only the prefix string (the segment before the first/or?). Default:false.
Returns
Section titled “Returns”- If
onlyPrefixistrue:string— the prefix (e.g."button"). - Otherwise:
objectwith:compPath: string[]— full path split by/.prefix: string— first item ofcompPath.lastPathItem: string— last item ofcompPath.component: string | null— second item ofcompPathornull.params: string[]— parameters split by/after the?(empty array if none).firstParam: string | nulllastParam: string | null
Example
Section titled “Example”import { parseCustomId } from "@utils";
parseCustomId("modal/user/profile?123/abc");// {// compPath: ["modal","user","profile"],// prefix: "modal",// lastPathItem: "profile",// component: "user",// params: ["123","abc"],// firstParam: "123",// lastParam: "abc"// }
parseCustomId("button/click?123", true);// -> "button"