@oxog/vld 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +117 -102
- package/README.md +78 -13
- package/dist/coercion/bigint.d.ts +27 -0
- package/dist/coercion/bigint.d.ts.map +1 -0
- package/dist/coercion/bigint.js +108 -0
- package/dist/coercion/bigint.js.map +1 -0
- package/dist/coercion/boolean.d.ts +20 -0
- package/dist/coercion/boolean.d.ts.map +1 -0
- package/dist/coercion/boolean.js +63 -0
- package/dist/coercion/boolean.js.map +1 -0
- package/dist/coercion/date.d.ts +20 -0
- package/dist/coercion/date.d.ts.map +1 -0
- package/dist/coercion/date.js +52 -0
- package/dist/coercion/date.js.map +1 -0
- package/dist/coercion/number.d.ts +35 -0
- package/dist/coercion/number.d.ts.map +1 -0
- package/dist/coercion/number.js +144 -0
- package/dist/coercion/number.js.map +1 -0
- package/dist/coercion/string.d.ts +38 -0
- package/dist/coercion/string.d.ts.map +1 -0
- package/dist/coercion/string.js +168 -0
- package/dist/coercion/string.js.map +1 -0
- package/dist/index-new.d.ts.map +1 -0
- package/dist/index.d.ts +64 -257
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +86 -1164
- package/dist/index.js.map +1 -1
- package/dist/locales/af.js +3 -3
- package/dist/locales/af.js.map +1 -1
- package/dist/utils/deep-merge.d.ts +18 -0
- package/dist/utils/deep-merge.d.ts.map +1 -0
- package/dist/utils/deep-merge.js +68 -0
- package/dist/utils/deep-merge.js.map +1 -0
- package/dist/validators/any.d.ts +19 -0
- package/dist/validators/any.d.ts.map +1 -0
- package/dist/validators/any.js +25 -0
- package/dist/validators/any.js.map +1 -0
- package/dist/validators/array.d.ts +48 -0
- package/dist/validators/array.d.ts.map +1 -0
- package/dist/validators/array.js +135 -0
- package/dist/validators/array.js.map +1 -0
- package/dist/validators/base.d.ts +155 -0
- package/dist/validators/base.d.ts.map +1 -0
- package/dist/validators/base.js +245 -0
- package/dist/validators/base.js.map +1 -0
- package/dist/validators/bigint.d.ts +60 -0
- package/dist/validators/bigint.d.ts.map +1 -0
- package/dist/validators/bigint.js +104 -0
- package/dist/validators/bigint.js.map +1 -0
- package/dist/validators/boolean.d.ts +32 -0
- package/dist/validators/boolean.d.ts.map +1 -0
- package/dist/validators/boolean.js +86 -0
- package/dist/validators/boolean.js.map +1 -0
- package/dist/validators/date.d.ts +68 -0
- package/dist/validators/date.d.ts.map +1 -0
- package/dist/validators/date.js +148 -0
- package/dist/validators/date.js.map +1 -0
- package/dist/validators/enum.d.ts +25 -0
- package/dist/validators/enum.d.ts.map +1 -0
- package/dist/validators/enum.js +45 -0
- package/dist/validators/enum.js.map +1 -0
- package/dist/validators/index.d.ts +27 -0
- package/dist/validators/index.d.ts.map +1 -0
- package/dist/validators/index.js +30 -0
- package/dist/validators/index.js.map +1 -0
- package/dist/validators/intersection.d.ts +25 -0
- package/dist/validators/intersection.d.ts.map +1 -0
- package/dist/validators/intersection.js +57 -0
- package/dist/validators/intersection.js.map +1 -0
- package/dist/validators/literal.d.ts +25 -0
- package/dist/validators/literal.d.ts.map +1 -0
- package/dist/validators/literal.js +45 -0
- package/dist/validators/literal.js.map +1 -0
- package/dist/validators/map.d.ts +26 -0
- package/dist/validators/map.d.ts.map +1 -0
- package/dist/validators/map.js +54 -0
- package/dist/validators/map.js.map +1 -0
- package/dist/validators/never.d.ts +19 -0
- package/dist/validators/never.d.ts.map +1 -0
- package/dist/validators/never.js +29 -0
- package/dist/validators/never.js.map +1 -0
- package/dist/validators/number.d.ts +92 -0
- package/dist/validators/number.d.ts.map +1 -0
- package/dist/validators/number.js +173 -0
- package/dist/validators/number.js.map +1 -0
- package/dist/validators/object-optimized.d.ts +23 -0
- package/dist/validators/object-optimized.d.ts.map +1 -0
- package/dist/validators/object-optimized.js +179 -0
- package/dist/validators/object-optimized.js.map +1 -0
- package/dist/validators/object-ultra.d.ts +34 -0
- package/dist/validators/object-ultra.d.ts.map +1 -0
- package/dist/validators/object-ultra.js +175 -0
- package/dist/validators/object-ultra.js.map +1 -0
- package/dist/validators/object.d.ts +73 -0
- package/dist/validators/object.d.ts.map +1 -0
- package/dist/validators/object.js +289 -0
- package/dist/validators/object.js.map +1 -0
- package/dist/validators/record.d.ts +25 -0
- package/dist/validators/record.d.ts.map +1 -0
- package/dist/validators/record.js +52 -0
- package/dist/validators/record.js.map +1 -0
- package/dist/validators/set.d.ts +25 -0
- package/dist/validators/set.d.ts.map +1 -0
- package/dist/validators/set.js +51 -0
- package/dist/validators/set.js.map +1 -0
- package/dist/validators/string-ultra.d.ts +49 -0
- package/dist/validators/string-ultra.d.ts.map +1 -0
- package/dist/validators/string-ultra.js +217 -0
- package/dist/validators/string-ultra.js.map +1 -0
- package/dist/validators/string.d.ts +109 -0
- package/dist/validators/string.d.ts.map +1 -0
- package/dist/validators/string.js +242 -0
- package/dist/validators/string.js.map +1 -0
- package/dist/validators/symbol.d.ts +24 -0
- package/dist/validators/symbol.d.ts.map +1 -0
- package/dist/validators/symbol.js +42 -0
- package/dist/validators/symbol.js.map +1 -0
- package/dist/validators/tuple.d.ts +31 -0
- package/dist/validators/tuple.d.ts.map +1 -0
- package/dist/validators/tuple.js +55 -0
- package/dist/validators/tuple.js.map +1 -0
- package/dist/validators/union-optimized.d.ts +15 -0
- package/dist/validators/union-optimized.d.ts.map +1 -0
- package/dist/validators/union-optimized.js +92 -0
- package/dist/validators/union-optimized.js.map +1 -0
- package/dist/validators/union.d.ts +33 -0
- package/dist/validators/union.d.ts.map +1 -0
- package/dist/validators/union.js +121 -0
- package/dist/validators/union.js.map +1 -0
- package/dist/validators/unknown.d.ts +19 -0
- package/dist/validators/unknown.d.ts.map +1 -0
- package/dist/validators/unknown.js +25 -0
- package/dist/validators/unknown.js.map +1 -0
- package/dist/validators/void.d.ts +19 -0
- package/dist/validators/void.d.ts.map +1 -0
- package/dist/validators/void.js +35 -0
- package/dist/validators/void.js.map +1 -0
- package/package.json +12 -6
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { VldBase, ParseResult } from './base';
|
|
2
|
+
/**
|
|
3
|
+
* Immutable boolean validator
|
|
4
|
+
*/
|
|
5
|
+
export declare class VldBoolean extends VldBase<boolean, boolean> {
|
|
6
|
+
private readonly errorMessage?;
|
|
7
|
+
/**
|
|
8
|
+
* Protected constructor to allow extension while maintaining immutability
|
|
9
|
+
*/
|
|
10
|
+
protected constructor(errorMessage?: string);
|
|
11
|
+
/**
|
|
12
|
+
* Create a new boolean validator
|
|
13
|
+
*/
|
|
14
|
+
static create(): VldBoolean;
|
|
15
|
+
/**
|
|
16
|
+
* Parse and validate a boolean value
|
|
17
|
+
*/
|
|
18
|
+
parse(value: unknown): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Safely parse and validate a boolean value
|
|
21
|
+
*/
|
|
22
|
+
safeParse(value: unknown): ParseResult<boolean>;
|
|
23
|
+
/**
|
|
24
|
+
* Create a new validator that only accepts true
|
|
25
|
+
*/
|
|
26
|
+
true(message?: string): VldBoolean;
|
|
27
|
+
/**
|
|
28
|
+
* Create a new validator that only accepts false
|
|
29
|
+
*/
|
|
30
|
+
false(message?: string): VldBoolean;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=boolean.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boolean.d.ts","sourceRoot":"","sources":["../../src/validators/boolean.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAG9C;;GAEG;AACH,qBAAa,UAAW,SAAQ,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC;IACvD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAS;IAEvC;;OAEG;IACH,SAAS,aAAa,YAAY,CAAC,EAAE,MAAM;IAK3C;;OAEG;IACH,MAAM,CAAC,MAAM,IAAI,UAAU;IAI3B;;OAEG;IACH,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;IAO9B;;OAEG;IACH,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC;IAU/C;;OAEG;IACH,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,UAAU;IAIlC;;OAEG;IACH,KAAK,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,UAAU;CAGpC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { VldBase } from './base.js';
|
|
2
|
+
import { getMessages } from '../locales.js';
|
|
3
|
+
/**
|
|
4
|
+
* Immutable boolean validator
|
|
5
|
+
*/
|
|
6
|
+
export class VldBoolean extends VldBase {
|
|
7
|
+
/**
|
|
8
|
+
* Protected constructor to allow extension while maintaining immutability
|
|
9
|
+
*/
|
|
10
|
+
constructor(errorMessage) {
|
|
11
|
+
super();
|
|
12
|
+
this.errorMessage = errorMessage;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create a new boolean validator
|
|
16
|
+
*/
|
|
17
|
+
static create() {
|
|
18
|
+
return new VldBoolean();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Parse and validate a boolean value
|
|
22
|
+
*/
|
|
23
|
+
parse(value) {
|
|
24
|
+
if (typeof value !== 'boolean') {
|
|
25
|
+
throw new Error(this.errorMessage || getMessages().invalidBoolean);
|
|
26
|
+
}
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Safely parse and validate a boolean value
|
|
31
|
+
*/
|
|
32
|
+
safeParse(value) {
|
|
33
|
+
if (typeof value === 'boolean') {
|
|
34
|
+
return { success: true, data: value };
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
success: false,
|
|
38
|
+
error: new Error(this.errorMessage || getMessages().invalidBoolean)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Create a new validator that only accepts true
|
|
43
|
+
*/
|
|
44
|
+
true(message) {
|
|
45
|
+
return new VldTrue(message || 'Value must be true');
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Create a new validator that only accepts false
|
|
49
|
+
*/
|
|
50
|
+
false(message) {
|
|
51
|
+
return new VldFalse(message || 'Value must be false');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Validator that only accepts true
|
|
56
|
+
*/
|
|
57
|
+
class VldTrue extends VldBoolean {
|
|
58
|
+
constructor(message) {
|
|
59
|
+
super(message);
|
|
60
|
+
this.message = message;
|
|
61
|
+
}
|
|
62
|
+
parse(value) {
|
|
63
|
+
const result = super.parse(value);
|
|
64
|
+
if (result !== true) {
|
|
65
|
+
throw new Error(this.message);
|
|
66
|
+
}
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Validator that only accepts false
|
|
72
|
+
*/
|
|
73
|
+
class VldFalse extends VldBoolean {
|
|
74
|
+
constructor(message) {
|
|
75
|
+
super(message);
|
|
76
|
+
this.message = message;
|
|
77
|
+
}
|
|
78
|
+
parse(value) {
|
|
79
|
+
const result = super.parse(value);
|
|
80
|
+
if (result !== false) {
|
|
81
|
+
throw new Error(this.message);
|
|
82
|
+
}
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=boolean.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../src/validators/boolean.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAe,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC;;GAEG;AACH,MAAM,OAAO,UAAW,SAAQ,OAAyB;IAGvD;;OAEG;IACH,YAAsB,YAAqB;QACzC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC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S,SAAQ,UAAU;IAC/B,YAA6B,OAAe;QAC1C,KAAK,CAAC,OAAO,CAAC,CAAC;QADY,YAAO,GAAP,OAAO,CAAQ;IAE5C,CAAC;IAED,KAAK,CAAC,KAAc;QAClB,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAClC,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAChC,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["import { VldBase, ParseResult } from './base';\nimport { getMessages } from '../locales';\n\n/**\n * Immutable boolean validator\n */\nexport class VldBoolean extends VldBase<boolean, boolean> {\n private readonly errorMessage?: string;\n \n /**\n * Protected constructor to allow extension while maintaining immutability\n */\n protected constructor(errorMessage?: string) {\n super();\n this.errorMessage = errorMessage;\n }\n \n /**\n * Create a new boolean validator\n */\n static create(): VldBoolean {\n return new VldBoolean();\n }\n \n /**\n * Parse and validate a boolean value\n */\n parse(value: unknown): boolean {\n if (typeof value !== 'boolean') {\n throw new Error(this.errorMessage || getMessages().invalidBoolean);\n }\n return value;\n }\n \n /**\n * Safely parse and validate a boolean value\n */\n safeParse(value: unknown): ParseResult<boolean> {\n if (typeof value === 'boolean') {\n return { success: true, data: value };\n }\n return { \n success: false, \n error: new Error(this.errorMessage || getMessages().invalidBoolean) \n };\n }\n \n /**\n * Create a new validator that only accepts true\n */\n true(message?: string): VldBoolean {\n return new VldTrue(message || 'Value must be true');\n }\n \n /**\n * Create a new validator that only accepts false\n */\n false(message?: string): VldBoolean {\n return new VldFalse(message || 'Value must be false');\n }\n}\n\n/**\n * Validator that only accepts true\n */\nclass VldTrue extends VldBoolean {\n constructor(private readonly message: string) {\n super(message);\n }\n \n parse(value: unknown): boolean {\n const result = super.parse(value);\n if (result !== true) {\n throw new Error(this.message);\n }\n return result;\n }\n}\n\n/**\n * Validator that only accepts false\n */\nclass VldFalse extends VldBoolean {\n constructor(private readonly message: string) {\n super(message);\n }\n \n parse(value: unknown): boolean {\n const result = super.parse(value);\n if (result !== false) {\n throw new Error(this.message);\n }\n return result;\n }\n}"]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { VldBase, ParseResult } from './base';
|
|
2
|
+
/**
|
|
3
|
+
* Type for date validation check functions
|
|
4
|
+
*/
|
|
5
|
+
type DateCheck = (value: Date) => boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Configuration for date validator
|
|
8
|
+
*/
|
|
9
|
+
interface DateValidatorConfig {
|
|
10
|
+
readonly checks: ReadonlyArray<DateCheck>;
|
|
11
|
+
readonly errorMessage?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Immutable date validator with chainable methods
|
|
15
|
+
*/
|
|
16
|
+
export declare class VldDate extends VldBase<Date, Date> {
|
|
17
|
+
private readonly config;
|
|
18
|
+
/**
|
|
19
|
+
* Protected constructor to allow extension while maintaining immutability
|
|
20
|
+
*/
|
|
21
|
+
protected constructor(config?: Partial<DateValidatorConfig>);
|
|
22
|
+
/**
|
|
23
|
+
* Create a new date validator
|
|
24
|
+
*/
|
|
25
|
+
static create(): VldDate;
|
|
26
|
+
/**
|
|
27
|
+
* Parse and validate a date value
|
|
28
|
+
*/
|
|
29
|
+
parse(value: unknown): Date;
|
|
30
|
+
/**
|
|
31
|
+
* Safely parse and validate a date value
|
|
32
|
+
*/
|
|
33
|
+
safeParse(value: unknown): ParseResult<Date>;
|
|
34
|
+
/**
|
|
35
|
+
* Create a new validator with minimum date constraint
|
|
36
|
+
*/
|
|
37
|
+
min(date: Date | string | number, message?: string): VldDate;
|
|
38
|
+
/**
|
|
39
|
+
* Create a new validator with maximum date constraint
|
|
40
|
+
*/
|
|
41
|
+
max(date: Date | string | number, message?: string): VldDate;
|
|
42
|
+
/**
|
|
43
|
+
* Create a new validator with a range constraint
|
|
44
|
+
*/
|
|
45
|
+
between(min: Date | string | number, max: Date | string | number, message?: string): VldDate;
|
|
46
|
+
/**
|
|
47
|
+
* Create a new validator that checks if date is in the past
|
|
48
|
+
*/
|
|
49
|
+
past(message?: string): VldDate;
|
|
50
|
+
/**
|
|
51
|
+
* Create a new validator that checks if date is in the future
|
|
52
|
+
*/
|
|
53
|
+
future(message?: string): VldDate;
|
|
54
|
+
/**
|
|
55
|
+
* Create a new validator that checks if date is today
|
|
56
|
+
*/
|
|
57
|
+
today(message?: string): VldDate;
|
|
58
|
+
/**
|
|
59
|
+
* Create a new validator that checks if date is a weekday
|
|
60
|
+
*/
|
|
61
|
+
weekday(message?: string): VldDate;
|
|
62
|
+
/**
|
|
63
|
+
* Create a new validator that checks if date is a weekend
|
|
64
|
+
*/
|
|
65
|
+
weekend(message?: string): VldDate;
|
|
66
|
+
}
|
|
67
|
+
export {};
|
|
68
|
+
//# sourceMappingURL=date.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../src/validators/date.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAG9C;;GAEG;AACH,KAAK,SAAS,GAAG,CAAC,KAAK,EAAE,IAAI,KAAK,OAAO,CAAC;AAE1C;;GAEG;AACH,UAAU,mBAAmB;IAC3B,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;IAC1C,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;CAChC;AAED;;GAEG;AACH,qBAAa,OAAQ,SAAQ,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC;IAC9C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsB;IAE7C;;OAEG;IACH,SAAS,aAAa,MAAM,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC;IAQ3D;;OAEG;IACH,MAAM,CAAC,MAAM,IAAI,OAAO;IAIxB;;OAEG;IACH,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI;IA0B3B;;OAEG;IACH,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CAAC,IAAI,CAAC;IAQ5C;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO;IAQ5D;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO;IAQ5D;;OAEG;IACH,OAAO,CACL,GAAG,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,EAC3B,GAAG,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,EAC3B,OAAO,CAAC,EAAE,MAAM,GACf,OAAO;IASV;;OAEG;IACH,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO;IAO/B;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO;IAOjC;;OAEG;IACH,KAAK,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO;IAYhC;;OAEG;IACH,OAAO,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO;IAUlC;;OAEG;IACH,OAAO,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO;CASnC"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { VldBase } from './base.js';
|
|
2
|
+
import { getMessages } from '../locales.js';
|
|
3
|
+
/**
|
|
4
|
+
* Immutable date validator with chainable methods
|
|
5
|
+
*/
|
|
6
|
+
export class VldDate extends VldBase {
|
|
7
|
+
/**
|
|
8
|
+
* Protected constructor to allow extension while maintaining immutability
|
|
9
|
+
*/
|
|
10
|
+
constructor(config) {
|
|
11
|
+
super();
|
|
12
|
+
this.config = {
|
|
13
|
+
checks: config?.checks || [],
|
|
14
|
+
errorMessage: config?.errorMessage
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Create a new date validator
|
|
19
|
+
*/
|
|
20
|
+
static create() {
|
|
21
|
+
return new VldDate();
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Parse and validate a date value
|
|
25
|
+
*/
|
|
26
|
+
parse(value) {
|
|
27
|
+
let date;
|
|
28
|
+
if (value instanceof Date) {
|
|
29
|
+
date = value;
|
|
30
|
+
}
|
|
31
|
+
else if (typeof value === 'string' || typeof value === 'number') {
|
|
32
|
+
date = new Date(value);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
throw new Error(this.config.errorMessage || getMessages().invalidDate);
|
|
36
|
+
}
|
|
37
|
+
// Check if the date is valid
|
|
38
|
+
if (isNaN(date.getTime())) {
|
|
39
|
+
throw new Error(this.config.errorMessage || getMessages().invalidDate);
|
|
40
|
+
}
|
|
41
|
+
// Apply all checks
|
|
42
|
+
for (const check of this.config.checks) {
|
|
43
|
+
if (!check(date)) {
|
|
44
|
+
throw new Error(this.config.errorMessage || getMessages().invalidDate);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return date;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Safely parse and validate a date value
|
|
51
|
+
*/
|
|
52
|
+
safeParse(value) {
|
|
53
|
+
try {
|
|
54
|
+
return { success: true, data: this.parse(value) };
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
return { success: false, error: error };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Create a new validator with minimum date constraint
|
|
62
|
+
*/
|
|
63
|
+
min(date, message) {
|
|
64
|
+
const minDate = date instanceof Date ? date : new Date(date);
|
|
65
|
+
return new VldDate({
|
|
66
|
+
checks: [...this.config.checks, (v) => v >= minDate],
|
|
67
|
+
errorMessage: message || getMessages().dateMin(minDate)
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Create a new validator with maximum date constraint
|
|
72
|
+
*/
|
|
73
|
+
max(date, message) {
|
|
74
|
+
const maxDate = date instanceof Date ? date : new Date(date);
|
|
75
|
+
return new VldDate({
|
|
76
|
+
checks: [...this.config.checks, (v) => v <= maxDate],
|
|
77
|
+
errorMessage: message || getMessages().dateMax(maxDate)
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Create a new validator with a range constraint
|
|
82
|
+
*/
|
|
83
|
+
between(min, max, message) {
|
|
84
|
+
const minDate = min instanceof Date ? min : new Date(min);
|
|
85
|
+
const maxDate = max instanceof Date ? max : new Date(max);
|
|
86
|
+
return new VldDate({
|
|
87
|
+
checks: [...this.config.checks, (v) => v >= minDate && v <= maxDate],
|
|
88
|
+
errorMessage: message || `Date must be between ${minDate.toISOString()} and ${maxDate.toISOString()}`
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Create a new validator that checks if date is in the past
|
|
93
|
+
*/
|
|
94
|
+
past(message) {
|
|
95
|
+
return new VldDate({
|
|
96
|
+
checks: [...this.config.checks, (v) => v < new Date()],
|
|
97
|
+
errorMessage: message || 'Date must be in the past'
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Create a new validator that checks if date is in the future
|
|
102
|
+
*/
|
|
103
|
+
future(message) {
|
|
104
|
+
return new VldDate({
|
|
105
|
+
checks: [...this.config.checks, (v) => v > new Date()],
|
|
106
|
+
errorMessage: message || 'Date must be in the future'
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Create a new validator that checks if date is today
|
|
111
|
+
*/
|
|
112
|
+
today(message) {
|
|
113
|
+
return new VldDate({
|
|
114
|
+
checks: [...this.config.checks, (v) => {
|
|
115
|
+
const today = new Date();
|
|
116
|
+
return v.getFullYear() === today.getFullYear() &&
|
|
117
|
+
v.getMonth() === today.getMonth() &&
|
|
118
|
+
v.getDate() === today.getDate();
|
|
119
|
+
}],
|
|
120
|
+
errorMessage: message || 'Date must be today'
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Create a new validator that checks if date is a weekday
|
|
125
|
+
*/
|
|
126
|
+
weekday(message) {
|
|
127
|
+
return new VldDate({
|
|
128
|
+
checks: [...this.config.checks, (v) => {
|
|
129
|
+
const day = v.getDay();
|
|
130
|
+
return day >= 1 && day <= 5;
|
|
131
|
+
}],
|
|
132
|
+
errorMessage: message || 'Date must be a weekday'
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Create a new validator that checks if date is a weekend
|
|
137
|
+
*/
|
|
138
|
+
weekend(message) {
|
|
139
|
+
return new VldDate({
|
|
140
|
+
checks: [...this.config.checks, (v) => {
|
|
141
|
+
const day = v.getDay();
|
|
142
|
+
return day === 0 || day === 6;
|
|
143
|
+
}],
|
|
144
|
+
errorMessage: message || 'Date must be a weekend'
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=date.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.js","sourceRoot":"","sources":["../../src/validators/date.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAe,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAezC;;GAEG;AACH,MAAM,OAAO,OAAQ,SAAQ,OAAmB;IAG9C;;OAEG;IACH,YAAsB,MAAqC;QACzD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,MAAM,GAAG;YACZ,MAAM,EAAE,MAAM,EAAE,MAAM,IAAI,EAAE;YAC5B,YAAY,EAAE,MAAM,EAAE,YAAY;SACnC,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,MAAM;QACX,OAAO,IAAI,OAAO,EAAE,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAc;QAClB,IAAI,IAAU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AAC;YACjB,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAO,EAAE,EAAE;oBAC1C,MAAM,GAAG,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC;oBACvB,OAAO,GAAG,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;gBAC9B,CAAC,CAAC;YACF,YAAY,EAAE,OAAO,IAAI,wBAAwB;SAClD,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,OAAgB;QACtB,OAAO,IAAI,OAAO,CAAC;YACjB,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAO,EAAE,EAAE;oBAC1C,MAAM,GAAG,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC;oBACvB,OAAO,GAAG,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC;gBAChC,CAAC,CAAC;YACF,YAAY,EAAE,OAAO,IAAI,wBAAwB;SAClD,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { VldBase, ParseResult } from './base';\nimport { getMessages } from '../locales';\n\n/**\n * Type for date validation check functions\n */\ntype DateCheck = (value: Date) => boolean;\n\n/**\n * Configuration for date validator\n */\ninterface DateValidatorConfig {\n readonly checks: ReadonlyArray<DateCheck>;\n readonly errorMessage?: string;\n}\n\n/**\n * Immutable date validator with chainable methods\n */\nexport class VldDate extends VldBase<Date, Date> {\n private readonly config: DateValidatorConfig;\n \n /**\n * Protected constructor to allow extension while maintaining immutability\n */\n protected constructor(config?: Partial<DateValidatorConfig>) {\n super();\n this.config = {\n checks: config?.checks || [],\n errorMessage: config?.errorMessage\n };\n }\n \n /**\n * Create a new date validator\n */\n static create(): VldDate {\n return new VldDate();\n }\n \n /**\n * Parse and validate a date value\n */\n parse(value: unknown): Date {\n let date: Date;\n \n if (value instanceof Date) {\n date = value;\n } else if (typeof value === 'string' || typeof value === 'number') {\n date = new Date(value);\n } else {\n throw new Error(this.config.errorMessage || getMessages().invalidDate);\n }\n \n // Check if the date is valid\n if (isNaN(date.getTime())) {\n throw new Error(this.config.errorMessage || getMessages().invalidDate);\n }\n \n // Apply all checks\n for (const check of this.config.checks) {\n if (!check(date)) {\n throw new Error(this.config.errorMessage || getMessages().invalidDate);\n }\n }\n \n return date;\n }\n \n /**\n * Safely parse and validate a date value\n */\n safeParse(value: unknown): ParseResult<Date> {\n try {\n return { success: true, data: this.parse(value) };\n } catch (error) {\n return { success: false, error: error as Error };\n }\n }\n \n /**\n * Create a new validator with minimum date constraint\n */\n min(date: Date | string | number, message?: string): VldDate {\n const minDate = date instanceof Date ? date : new Date(date);\n return new VldDate({\n checks: [...this.config.checks, (v: Date) => v >= minDate],\n errorMessage: message || getMessages().dateMin(minDate)\n });\n }\n \n /**\n * Create a new validator with maximum date constraint\n */\n max(date: Date | string | number, message?: string): VldDate {\n const maxDate = date instanceof Date ? date : new Date(date);\n return new VldDate({\n checks: [...this.config.checks, (v: Date) => v <= maxDate],\n errorMessage: message || getMessages().dateMax(maxDate)\n });\n }\n \n /**\n * Create a new validator with a range constraint\n */\n between(\n min: Date | string | number,\n max: Date | string | number,\n message?: string\n ): VldDate {\n const minDate = min instanceof Date ? min : new Date(min);\n const maxDate = max instanceof Date ? max : new Date(max);\n return new VldDate({\n checks: [...this.config.checks, (v: Date) => v >= minDate && v <= maxDate],\n errorMessage: message || `Date must be between ${minDate.toISOString()} and ${maxDate.toISOString()}`\n });\n }\n \n /**\n * Create a new validator that checks if date is in the past\n */\n past(message?: string): VldDate {\n return new VldDate({\n checks: [...this.config.checks, (v: Date) => v < new Date()],\n errorMessage: message || 'Date must be in the past'\n });\n }\n \n /**\n * Create a new validator that checks if date is in the future\n */\n future(message?: string): VldDate {\n return new VldDate({\n checks: [...this.config.checks, (v: Date) => v > new Date()],\n errorMessage: message || 'Date must be in the future'\n });\n }\n \n /**\n * Create a new validator that checks if date is today\n */\n today(message?: string): VldDate {\n return new VldDate({\n checks: [...this.config.checks, (v: Date) => {\n const today = new Date();\n return v.getFullYear() === today.getFullYear() &&\n v.getMonth() === today.getMonth() &&\n v.getDate() === today.getDate();\n }],\n errorMessage: message || 'Date must be today'\n });\n }\n \n /**\n * Create a new validator that checks if date is a weekday\n */\n weekday(message?: string): VldDate {\n return new VldDate({\n checks: [...this.config.checks, (v: Date) => {\n const day = v.getDay();\n return day >= 1 && day <= 5;\n }],\n errorMessage: message || 'Date must be a weekday'\n });\n }\n \n /**\n * Create a new validator that checks if date is a weekend\n */\n weekend(message?: string): VldDate {\n return new VldDate({\n checks: [...this.config.checks, (v: Date) => {\n const day = v.getDay();\n return day === 0 || day === 6;\n }],\n errorMessage: message || 'Date must be a weekend'\n });\n }\n}"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { VldBase, ParseResult } from './base';
|
|
2
|
+
/**
|
|
3
|
+
* Immutable enum validator for string enum values
|
|
4
|
+
*/
|
|
5
|
+
export declare class VldEnum<T extends readonly [string, ...string[]]> extends VldBase<string, T[number]> {
|
|
6
|
+
private readonly values;
|
|
7
|
+
private readonly errorMessage?;
|
|
8
|
+
/**
|
|
9
|
+
* Private constructor to enforce immutability
|
|
10
|
+
*/
|
|
11
|
+
private constructor();
|
|
12
|
+
/**
|
|
13
|
+
* Create a new enum validator
|
|
14
|
+
*/
|
|
15
|
+
static create<T extends readonly [string, ...string[]]>(values: T): VldEnum<T>;
|
|
16
|
+
/**
|
|
17
|
+
* Parse and validate an enum value
|
|
18
|
+
*/
|
|
19
|
+
parse(value: unknown): T[number];
|
|
20
|
+
/**
|
|
21
|
+
* Safely parse and validate an enum value
|
|
22
|
+
*/
|
|
23
|
+
safeParse(value: unknown): ParseResult<T[number]>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=enum.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enum.d.ts","sourceRoot":"","sources":["../../src/validators/enum.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAG9C;;GAEG;AACH,qBAAa,OAAO,CAAC,CAAC,SAAS,SAAS,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAAE,SAAQ,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;IAK7F,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;IALhC;;OAEG;IACH,OAAO;IAOP;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,SAAS,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAI9E;;OAEG;IACH,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC;IAUhC;;OAEG;IACH,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;CAYlD"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { VldBase } from './base.js';
|
|
2
|
+
import { getMessages } from '../locales.js';
|
|
3
|
+
/**
|
|
4
|
+
* Immutable enum validator for string enum values
|
|
5
|
+
*/
|
|
6
|
+
export class VldEnum extends VldBase {
|
|
7
|
+
/**
|
|
8
|
+
* Private constructor to enforce immutability
|
|
9
|
+
*/
|
|
10
|
+
constructor(values, errorMessage) {
|
|
11
|
+
super();
|
|
12
|
+
this.values = values;
|
|
13
|
+
this.errorMessage = errorMessage;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Create a new enum validator
|
|
17
|
+
*/
|
|
18
|
+
static create(values) {
|
|
19
|
+
return new VldEnum(values);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Parse and validate an enum value
|
|
23
|
+
*/
|
|
24
|
+
parse(value) {
|
|
25
|
+
if (!this.values.includes(value)) {
|
|
26
|
+
throw new Error(this.errorMessage ||
|
|
27
|
+
getMessages().enumExpected([...this.values], JSON.stringify(value)));
|
|
28
|
+
}
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Safely parse and validate an enum value
|
|
33
|
+
*/
|
|
34
|
+
safeParse(value) {
|
|
35
|
+
if (this.values.includes(value)) {
|
|
36
|
+
return { success: true, data: value };
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
success: false,
|
|
40
|
+
error: new Error(this.errorMessage ||
|
|
41
|
+
getMessages().enumExpected([...this.values], JSON.stringify(value)))
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=enum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enum.js","sourceRoot":"","sources":["../../src/validators/enum.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAe,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC;;GAEG;AACH,MAAM,OAAO,OAAkD,SAAQ,OAA0B;IAC/F;;OAEG;IACH,YACmB,MAAS,EACT,YAAqB;QAEtC,KAAK,EAAE,CAAC;QAHS,WAAM,GAAN,MAAM,CAAG;QACT,iBAAY,GAAZ,YAAY,CAAS;IAGxC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,MAAM,CAA2C,MAAS;QAC/D,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAc;QAClB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAe,CAAC,EAAE,CAAC;YAC3C,MAAM,IAAI,KAAK,CACb,IAAI,CAAC,YAAY;gBACjB,WAAW,EAAE,CAAC,YAAY,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CACpE,CAAC;QACJ,CAAC;QACD,OAAO,KAAkB,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,SAAS,CAAC,KAAc;QACtB,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAe,CAAC,EAAE,CAAC;YAC1C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAkB,EAAE,CAAC;QACrD,CAAC;QACD,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,IAAI,KAAK,CACd,IAAI,CAAC,YAAY;gBACjB,WAAW,EAAE,CAAC,YAAY,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CACpE;SACF,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { VldBase, ParseResult } from './base';\nimport { getMessages } from '../locales';\n\n/**\n * Immutable enum validator for string enum values\n */\nexport class VldEnum<T extends readonly [string, ...string[]]> extends VldBase<string, T[number]> {\n /**\n * Private constructor to enforce immutability\n */\n private constructor(\n private readonly values: T,\n private readonly errorMessage?: string\n ) {\n super();\n }\n \n /**\n * Create a new enum validator\n */\n static create<T extends readonly [string, ...string[]]>(values: T): VldEnum<T> {\n return new VldEnum(values);\n }\n \n /**\n * Parse and validate an enum value\n */\n parse(value: unknown): T[number] {\n if (!this.values.includes(value as string)) {\n throw new Error(\n this.errorMessage || \n getMessages().enumExpected([...this.values], JSON.stringify(value))\n );\n }\n return value as T[number];\n }\n \n /**\n * Safely parse and validate an enum value\n */\n safeParse(value: unknown): ParseResult<T[number]> {\n if (this.values.includes(value as string)) {\n return { success: true, data: value as T[number] };\n }\n return { \n success: false, \n error: new Error(\n this.errorMessage || \n getMessages().enumExpected([...this.values], JSON.stringify(value))\n )\n };\n }\n}"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main entry point for all validators
|
|
3
|
+
*/
|
|
4
|
+
export { VldBase, ParseResult, VldRefine, VldTransform, VldDefault, VldCatch, VldOptional, VldNullable, VldNullish } from './base';
|
|
5
|
+
export { VldString } from './string';
|
|
6
|
+
export { VldNumber } from './number';
|
|
7
|
+
export { VldBoolean } from './boolean';
|
|
8
|
+
export { VldDate } from './date';
|
|
9
|
+
export { VldArray } from './array';
|
|
10
|
+
export { VldObject } from './object';
|
|
11
|
+
export { VldUnion } from './union';
|
|
12
|
+
export { VldIntersection } from './intersection';
|
|
13
|
+
export { VldLiteral } from './literal';
|
|
14
|
+
export { VldEnum } from './enum';
|
|
15
|
+
export { VldTuple } from './tuple';
|
|
16
|
+
export { VldRecord } from './record';
|
|
17
|
+
export { VldSet } from './set';
|
|
18
|
+
export { VldMap } from './map';
|
|
19
|
+
export { VldBigInt } from './bigint';
|
|
20
|
+
export { VldSymbol } from './symbol';
|
|
21
|
+
export { VldAny } from './any';
|
|
22
|
+
export { VldUnknown } from './unknown';
|
|
23
|
+
export { VldVoid } from './void';
|
|
24
|
+
export { VldNever } from './never';
|
|
25
|
+
import { VldBase } from './base';
|
|
26
|
+
export type Infer<T extends VldBase<any, any>> = T extends VldBase<any, infer U> ? U : never;
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validators/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EACL,OAAO,EACP,WAAW,EACX,SAAS,EACT,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,WAAW,EACX,WAAW,EACX,UAAU,EACX,MAAM,QAAQ,CAAC;AAGhB,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAGjC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAGrC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAGrC,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGnC,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAGjC,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,SAAS,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main entry point for all validators
|
|
3
|
+
*/
|
|
4
|
+
// Export base types and classes
|
|
5
|
+
export { VldBase, VldRefine, VldTransform, VldDefault, VldCatch, VldOptional, VldNullable, VldNullish } from './base.js';
|
|
6
|
+
// Export primitive validators
|
|
7
|
+
export { VldString } from './string.js';
|
|
8
|
+
export { VldNumber } from './number.js';
|
|
9
|
+
export { VldBoolean } from './boolean.js';
|
|
10
|
+
export { VldDate } from './date.js';
|
|
11
|
+
// Export complex validators
|
|
12
|
+
export { VldArray } from './array.js';
|
|
13
|
+
export { VldObject } from './object.js';
|
|
14
|
+
// Export utility validators (to be implemented)
|
|
15
|
+
export { VldUnion } from './union.js';
|
|
16
|
+
export { VldIntersection } from './intersection.js';
|
|
17
|
+
export { VldLiteral } from './literal.js';
|
|
18
|
+
export { VldEnum } from './enum.js';
|
|
19
|
+
export { VldTuple } from './tuple.js';
|
|
20
|
+
export { VldRecord } from './record.js';
|
|
21
|
+
export { VldSet } from './set.js';
|
|
22
|
+
export { VldMap } from './map.js';
|
|
23
|
+
export { VldBigInt } from './bigint.js';
|
|
24
|
+
export { VldSymbol } from './symbol.js';
|
|
25
|
+
// Export special validators
|
|
26
|
+
export { VldAny } from './any.js';
|
|
27
|
+
export { VldUnknown } from './unknown.js';
|
|
28
|
+
export { VldVoid } from './void.js';
|
|
29
|
+
export { VldNever } from './never.js';
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/validators/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,gCAAgC;AAChC,OAAO,EACL,OAAO,EAEP,SAAS,EACT,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,WAAW,EACX,WAAW,EACX,UAAU,EACX,MAAM,QAAQ,CAAC;AAEhB,8BAA8B;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEjC,4BAA4B;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,gDAAgD;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,4BAA4B;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC","sourcesContent":["/**\n * Main entry point for all validators\n */\n\n// Export base types and classes\nexport { \n VldBase, \n ParseResult,\n VldRefine,\n VldTransform,\n VldDefault,\n VldCatch,\n VldOptional,\n VldNullable,\n VldNullish\n} from './base';\n\n// Export primitive validators\nexport { VldString } from './string';\nexport { VldNumber } from './number';\nexport { VldBoolean } from './boolean';\nexport { VldDate } from './date';\n\n// Export complex validators\nexport { VldArray } from './array';\nexport { VldObject } from './object';\n\n// Export utility validators (to be implemented)\nexport { VldUnion } from './union';\nexport { VldIntersection } from './intersection';\nexport { VldLiteral } from './literal';\nexport { VldEnum } from './enum';\nexport { VldTuple } from './tuple';\nexport { VldRecord } from './record';\nexport { VldSet } from './set';\nexport { VldMap } from './map';\nexport { VldBigInt } from './bigint';\nexport { VldSymbol } from './symbol';\n\n// Export special validators\nexport { VldAny } from './any';\nexport { VldUnknown } from './unknown';\nexport { VldVoid } from './void';\nexport { VldNever } from './never';\n\n// Import base for type inference\nimport { VldBase } from './base';\n\n// Type inference helper\nexport type Infer<T extends VldBase<any, any>> = T extends VldBase<any, infer U> ? U : never;"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { VldBase, ParseResult } from './base';
|
|
2
|
+
/**
|
|
3
|
+
* Immutable intersection validator for combining validators
|
|
4
|
+
*/
|
|
5
|
+
export declare class VldIntersection<A, B> extends VldBase<unknown, A & B> {
|
|
6
|
+
private readonly validatorA;
|
|
7
|
+
private readonly validatorB;
|
|
8
|
+
/**
|
|
9
|
+
* Private constructor to enforce immutability
|
|
10
|
+
*/
|
|
11
|
+
private constructor();
|
|
12
|
+
/**
|
|
13
|
+
* Create a new intersection validator
|
|
14
|
+
*/
|
|
15
|
+
static create<A, B>(validatorA: VldBase<unknown, A>, validatorB: VldBase<unknown, B>): VldIntersection<A, B>;
|
|
16
|
+
/**
|
|
17
|
+
* Parse and validate a value against both validators
|
|
18
|
+
*/
|
|
19
|
+
parse(value: unknown): A & B;
|
|
20
|
+
/**
|
|
21
|
+
* Safely parse and validate a value against both validators
|
|
22
|
+
*/
|
|
23
|
+
safeParse(value: unknown): ParseResult<A & B>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=intersection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intersection.d.ts","sourceRoot":"","sources":["../../src/validators/intersection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAI9C;;GAEG;AACH,qBAAa,eAAe,CAAC,CAAC,EAAE,CAAC,CAAE,SAAQ,OAAO,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC;IAK9D,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,UAAU;IAL7B;;OAEG;IACH,OAAO;IAOP;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAChB,UAAU,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,EAC/B,UAAU,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,GAC9B,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC;IAIxB;;OAEG;IACH,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,CAAC,GAAG,CAAC;IAuB5B;;OAEG;IACH,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC;CAO9C"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { VldBase } from './base.js';
|
|
2
|
+
import { deepMerge, isPlainObject } from '../utils/deep-merge.js';
|
|
3
|
+
import { getMessages } from '../locales.js';
|
|
4
|
+
/**
|
|
5
|
+
* Immutable intersection validator for combining validators
|
|
6
|
+
*/
|
|
7
|
+
export class VldIntersection extends VldBase {
|
|
8
|
+
/**
|
|
9
|
+
* Private constructor to enforce immutability
|
|
10
|
+
*/
|
|
11
|
+
constructor(validatorA, validatorB) {
|
|
12
|
+
super();
|
|
13
|
+
this.validatorA = validatorA;
|
|
14
|
+
this.validatorB = validatorB;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Create a new intersection validator
|
|
18
|
+
*/
|
|
19
|
+
static create(validatorA, validatorB) {
|
|
20
|
+
return new VldIntersection(validatorA, validatorB);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Parse and validate a value against both validators
|
|
24
|
+
*/
|
|
25
|
+
parse(value) {
|
|
26
|
+
try {
|
|
27
|
+
// Both validators must pass
|
|
28
|
+
const resultA = this.validatorA.parse(value);
|
|
29
|
+
const resultB = this.validatorB.parse(value);
|
|
30
|
+
// For object types, deep merge the results
|
|
31
|
+
if (isPlainObject(resultA) && isPlainObject(resultB)) {
|
|
32
|
+
return deepMerge(resultA, resultB);
|
|
33
|
+
}
|
|
34
|
+
// For primitive types, both must be the same value
|
|
35
|
+
if (resultA === resultB) {
|
|
36
|
+
return resultA;
|
|
37
|
+
}
|
|
38
|
+
// If they're different primitive values, this is an error
|
|
39
|
+
throw new Error('Values must be identical for intersection of primitive types');
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
throw new Error(getMessages().intersectionError(error.message));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Safely parse and validate a value against both validators
|
|
47
|
+
*/
|
|
48
|
+
safeParse(value) {
|
|
49
|
+
try {
|
|
50
|
+
return { success: true, data: this.parse(value) };
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
return { success: false, error: error };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=intersection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intersection.js","sourceRoot":"","sources":["../../src/validators/intersection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAe,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC;;GAEG;AACH,MAAM,OAAO,eAAsB,SAAQ,OAAuB;IAChE;;OAEG;IACH,YACmB,UAA+B,EAC/B,UAA+B;QAEhD,KAAK,EAAE,CAAC;QAHS,eAAU,GAAV,UAAU,CAAqB;QAC/B,eAAU,GAAV,UAAU,CAAqB;IAGlD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,MAAM,CACX,UAA+B,EAC/B,UAA+B;QAE/B,OAAO,IAAI,eAAe,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IACrD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAc;QAClB,IAAI,CAAC;YACH,4BAA4B;YAC5B,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAC7C,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAE7C,2CAA2C;YAC3C,IAAI,aAAa,CAAC,OAAO,CAAC,IAAI,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC;gBACrD,OAAO,SAAS,CAAC,OAAc,EAAE,OAAc,CAAU,CAAC;YAC5D,CAAC;YAED,mDAAmD;YACnD,IAAK,OAAe,KAAM,OAAe,EAAE,CAAC;gBAC1C,OAAO,OAAgB,CAAC;YAC1B,CAAC;YAED,0DAA0D;YAC1D,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;QAClF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC,iBAAiB,CAAE,KAAe,CAAC,OAAO,CAAC,CAAC,CAAC;QAC7E,CAAC;IACH,CAAC;IAED;;OAEG;IACH,SAAS,CAAC,KAAc;QACtB,IAAI,CAAC;YACH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;QACpD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAc,EAAE,CAAC;QACnD,CAAC;IACH,CAAC;CACF","sourcesContent":["import { VldBase, ParseResult } from './base';\nimport { deepMerge, isPlainObject } from '../utils/deep-merge';\nimport { getMessages } from '../locales';\n\n/**\n * Immutable intersection validator for combining validators\n */\nexport class VldIntersection<A, B> extends VldBase<unknown, A & B> {\n /**\n * Private constructor to enforce immutability\n */\n private constructor(\n private readonly validatorA: VldBase<unknown, A>,\n private readonly validatorB: VldBase<unknown, B>\n ) {\n super();\n }\n \n /**\n * Create a new intersection validator\n */\n static create<A, B>(\n validatorA: VldBase<unknown, A>,\n validatorB: VldBase<unknown, B>\n ): VldIntersection<A, B> {\n return new VldIntersection(validatorA, validatorB);\n }\n \n /**\n * Parse and validate a value against both validators\n */\n parse(value: unknown): A & B {\n try {\n // Both validators must pass\n const resultA = this.validatorA.parse(value);\n const resultB = this.validatorB.parse(value);\n \n // For object types, deep merge the results\n if (isPlainObject(resultA) && isPlainObject(resultB)) {\n return deepMerge(resultA as any, resultB as any) as A & B;\n }\n \n // For primitive types, both must be the same value\n if ((resultA as any) === (resultB as any)) {\n return resultA as A & B;\n }\n \n // If they're different primitive values, this is an error\n throw new Error('Values must be identical for intersection of primitive types');\n } catch (error) {\n throw new Error(getMessages().intersectionError((error as Error).message));\n }\n }\n \n /**\n * Safely parse and validate a value against both validators\n */\n safeParse(value: unknown): ParseResult<A & B> {\n try {\n return { success: true, data: this.parse(value) };\n } catch (error) {\n return { success: false, error: error as Error };\n }\n }\n}"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { VldBase, ParseResult } from './base';
|
|
2
|
+
/**
|
|
3
|
+
* Immutable literal validator for exact value matching
|
|
4
|
+
*/
|
|
5
|
+
export declare class VldLiteral<T extends string | number | boolean | null | undefined> extends VldBase<T, T> {
|
|
6
|
+
private readonly literal;
|
|
7
|
+
private readonly errorMessage?;
|
|
8
|
+
/**
|
|
9
|
+
* Private constructor to enforce immutability
|
|
10
|
+
*/
|
|
11
|
+
private constructor();
|
|
12
|
+
/**
|
|
13
|
+
* Create a new literal validator
|
|
14
|
+
*/
|
|
15
|
+
static create<T extends string | number | boolean | null | undefined>(literal: T): VldLiteral<T>;
|
|
16
|
+
/**
|
|
17
|
+
* Parse and validate a literal value
|
|
18
|
+
*/
|
|
19
|
+
parse(value: unknown): T;
|
|
20
|
+
/**
|
|
21
|
+
* Safely parse and validate a literal value
|
|
22
|
+
*/
|
|
23
|
+
safeParse(value: unknown): ParseResult<T>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=literal.d.ts.map
|