decoval
Version:
DecoVal is a decorator-driven validation pattern that allows you to add validation rules directly to the properties of TypeScript classes, simplifying data control and increasing code readability and reusability.
16 lines (13 loc) • 453 B
text/typescript
export type DvIdTypes = "uuid" | "mongo" | "number";
export interface DvIdOptions {
type?: DvIdTypes;
optional?: boolean;
null?: boolean;
empty?: boolean;
regex?: string | RegExp | { value: string | RegExp; message?: string };
}
export const ID_PATTERNS: Record<DvIdTypes, RegExp> = {
uuid: /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,
mongo: /^[0-9a-fA-F]{24}$/,
number: /^[0-9]+$/,
};