isValidUlid
function isValidUlid(__namedParameters): boolean | null;Defined in: ulid-utils.ts:120
Whether a prefixed or plain id holds a well-formed 26-character ULID (Crockford base32, case-insensitive).
With throwOnInvalid: true it throws only when no ULID part can be extracted
(empty id, more than one _); a malformed ULID still returns false.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
__namedParameters |
{ id: string; throwOnInvalid?: boolean; } |
__namedParameters.id |
string |
__namedParameters.throwOnInvalid? |
boolean |
Returns
Section titled “Returns”boolean | null
Example
Section titled “Example”Check a route param
import { isValidUlid } from "@xtandard/lib/ulid";
isValidUlid({ id: "usr_01jd8x3kq6f2v9w4z7y5b8c1ne" }); // trueisValidUlid({ id: "usr_hello" }); // falseisValidUlid({ id: "" }); // falseisValidUlid({ id: "", throwOnInvalid: true }); // throws Error("ID is required")