utilitify-core 1.0.0
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/LICENSE +21 -0
- package/README.md +338 -0
- package/dist/async.cjs +25 -0
- package/dist/async.cjs.map +1 -0
- package/dist/async.d.cts +104 -0
- package/dist/async.d.ts +104 -0
- package/dist/async.js +4 -0
- package/dist/async.js.map +1 -0
- package/dist/chunk-2ICNRTSN.cjs +346 -0
- package/dist/chunk-2ICNRTSN.cjs.map +1 -0
- package/dist/chunk-3DPF72DY.js +170 -0
- package/dist/chunk-3DPF72DY.js.map +1 -0
- package/dist/chunk-4CV4JOE5.js +24 -0
- package/dist/chunk-4CV4JOE5.js.map +1 -0
- package/dist/chunk-4SLYNSLH.cjs +783 -0
- package/dist/chunk-4SLYNSLH.cjs.map +1 -0
- package/dist/chunk-5WP7DWCG.js +1285 -0
- package/dist/chunk-5WP7DWCG.js.map +1 -0
- package/dist/chunk-BMQ6YPKV.js +876 -0
- package/dist/chunk-BMQ6YPKV.js.map +1 -0
- package/dist/chunk-BZCMWUKS.cjs +479 -0
- package/dist/chunk-BZCMWUKS.cjs.map +1 -0
- package/dist/chunk-C5R744DY.cjs +173 -0
- package/dist/chunk-C5R744DY.cjs.map +1 -0
- package/dist/chunk-C75J62CV.cjs +913 -0
- package/dist/chunk-C75J62CV.cjs.map +1 -0
- package/dist/chunk-CZLDE2OZ.cjs +28 -0
- package/dist/chunk-CZLDE2OZ.cjs.map +1 -0
- package/dist/chunk-DSMB6AF6.cjs +193 -0
- package/dist/chunk-DSMB6AF6.cjs.map +1 -0
- package/dist/chunk-ETWGPOPY.js +426 -0
- package/dist/chunk-ETWGPOPY.js.map +1 -0
- package/dist/chunk-FQBPVN63.cjs +403 -0
- package/dist/chunk-FQBPVN63.cjs.map +1 -0
- package/dist/chunk-G4GYQGTW.cjs +178 -0
- package/dist/chunk-G4GYQGTW.cjs.map +1 -0
- package/dist/chunk-GFDMZDMI.js +486 -0
- package/dist/chunk-GFDMZDMI.js.map +1 -0
- package/dist/chunk-HOTOYIPB.js +171 -0
- package/dist/chunk-HOTOYIPB.js.map +1 -0
- package/dist/chunk-HYADH4ZX.js +176 -0
- package/dist/chunk-HYADH4ZX.js.map +1 -0
- package/dist/chunk-JBN7C5WE.js +255 -0
- package/dist/chunk-JBN7C5WE.js.map +1 -0
- package/dist/chunk-JNCTPFTD.cjs +25 -0
- package/dist/chunk-JNCTPFTD.cjs.map +1 -0
- package/dist/chunk-N3BH3BV7.js +21 -0
- package/dist/chunk-N3BH3BV7.js.map +1 -0
- package/dist/chunk-NFPGAVRQ.js +749 -0
- package/dist/chunk-NFPGAVRQ.js.map +1 -0
- package/dist/chunk-OFFRGRBN.cjs +1332 -0
- package/dist/chunk-OFFRGRBN.cjs.map +1 -0
- package/dist/chunk-OZLKYIZL.cjs +490 -0
- package/dist/chunk-OZLKYIZL.cjs.map +1 -0
- package/dist/chunk-P3NUK46X.js +145 -0
- package/dist/chunk-P3NUK46X.js.map +1 -0
- package/dist/chunk-P7P2B7ZI.cjs +429 -0
- package/dist/chunk-P7P2B7ZI.cjs.map +1 -0
- package/dist/chunk-PB6SKSJN.cjs +150 -0
- package/dist/chunk-PB6SKSJN.cjs.map +1 -0
- package/dist/chunk-R3IXCJR7.js +378 -0
- package/dist/chunk-R3IXCJR7.js.map +1 -0
- package/dist/chunk-SD6P3WEJ.js +324 -0
- package/dist/chunk-SD6P3WEJ.js.map +1 -0
- package/dist/chunk-YSCHP26P.js +451 -0
- package/dist/chunk-YSCHP26P.js.map +1 -0
- package/dist/chunk-ZLMPRPCY.cjs +274 -0
- package/dist/chunk-ZLMPRPCY.cjs.map +1 -0
- package/dist/common-CBDYNJeh.d.cts +48 -0
- package/dist/common-CBDYNJeh.d.ts +48 -0
- package/dist/constants.cjs +42 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.cts +60 -0
- package/dist/constants.d.ts +60 -0
- package/dist/constants.js +5 -0
- package/dist/constants.js.map +1 -0
- package/dist/country/index.cjs +154 -0
- package/dist/country/index.cjs.map +1 -0
- package/dist/country/index.d.cts +1 -0
- package/dist/country/index.d.ts +1 -0
- package/dist/country/index.js +5 -0
- package/dist/country/index.js.map +1 -0
- package/dist/date/index.cjs +117 -0
- package/dist/date/index.cjs.map +1 -0
- package/dist/date/index.d.cts +283 -0
- package/dist/date/index.d.ts +283 -0
- package/dist/date/index.js +4 -0
- package/dist/date/index.js.map +1 -0
- package/dist/environment/index.cjs +73 -0
- package/dist/environment/index.cjs.map +1 -0
- package/dist/environment/index.d.cts +127 -0
- package/dist/environment/index.d.ts +127 -0
- package/dist/environment/index.js +4 -0
- package/dist/environment/index.js.map +1 -0
- package/dist/form/index.cjs +81 -0
- package/dist/form/index.cjs.map +1 -0
- package/dist/form/index.d.cts +227 -0
- package/dist/form/index.d.ts +227 -0
- package/dist/form/index.js +4 -0
- package/dist/form/index.js.map +1 -0
- package/dist/i18n.cjs +37 -0
- package/dist/i18n.cjs.map +1 -0
- package/dist/i18n.d.cts +102 -0
- package/dist/i18n.d.ts +102 -0
- package/dist/i18n.js +4 -0
- package/dist/i18n.js.map +1 -0
- package/dist/index-BXBmBHyL.d.ts +718 -0
- package/dist/index-BYsUCP3u.d.cts +718 -0
- package/dist/index-Cl26FrAZ.d.cts +362 -0
- package/dist/index-Cl26FrAZ.d.ts +362 -0
- package/dist/index.cjs +1265 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +205 -0
- package/dist/index.d.ts +205 -0
- package/dist/index.js +277 -0
- package/dist/index.js.map +1 -0
- package/dist/schema.cjs +13 -0
- package/dist/schema.cjs.map +1 -0
- package/dist/schema.d.cts +84 -0
- package/dist/schema.d.ts +84 -0
- package/dist/schema.js +4 -0
- package/dist/schema.js.map +1 -0
- package/dist/security/index.cjs +94 -0
- package/dist/security/index.cjs.map +1 -0
- package/dist/security/index.d.cts +216 -0
- package/dist/security/index.d.ts +216 -0
- package/dist/security/index.js +5 -0
- package/dist/security/index.js.map +1 -0
- package/dist/string/index.cjs +153 -0
- package/dist/string/index.cjs.map +1 -0
- package/dist/string/index.d.cts +471 -0
- package/dist/string/index.d.ts +471 -0
- package/dist/string/index.js +4 -0
- package/dist/string/index.js.map +1 -0
- package/dist/transform/index.cjs +105 -0
- package/dist/transform/index.cjs.map +1 -0
- package/dist/transform/index.d.cts +271 -0
- package/dist/transform/index.d.ts +271 -0
- package/dist/transform/index.js +4 -0
- package/dist/transform/index.js.map +1 -0
- package/dist/validators/index.cjs +195 -0
- package/dist/validators/index.cjs.map +1 -0
- package/dist/validators/index.d.cts +2 -0
- package/dist/validators/index.d.ts +2 -0
- package/dist/validators/index.js +6 -0
- package/dist/validators/index.js.map +1 -0
- package/package.json +229 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkZLMPRPCY_cjs = require('../chunk-ZLMPRPCY.cjs');
|
|
4
|
+
require('../chunk-CZLDE2OZ.cjs');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Object.defineProperty(exports, "createErrorMessages", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return chunkZLMPRPCY_cjs.createErrorMessages; }
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "errors", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return chunkZLMPRPCY_cjs.errors; }
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(exports, "formatMessage", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () { return chunkZLMPRPCY_cjs.formatMessage; }
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(exports, "formatValidationResult", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () { return chunkZLMPRPCY_cjs.formatValidationResult; }
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "inRange", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () { return chunkZLMPRPCY_cjs.inRange; }
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports, "isEmpty", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () { return chunkZLMPRPCY_cjs.isEmpty; }
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(exports, "isPresent", {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () { return chunkZLMPRPCY_cjs.isPresent; }
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "matchesPattern", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () { return chunkZLMPRPCY_cjs.matchesPattern; }
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(exports, "maxLength", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
get: function () { return chunkZLMPRPCY_cjs.maxLength; }
|
|
43
|
+
});
|
|
44
|
+
Object.defineProperty(exports, "minLength", {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
get: function () { return chunkZLMPRPCY_cjs.minLength; }
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "mustMatch", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () { return chunkZLMPRPCY_cjs.mustMatch; }
|
|
51
|
+
});
|
|
52
|
+
Object.defineProperty(exports, "oneOf", {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
get: function () { return chunkZLMPRPCY_cjs.oneOf; }
|
|
55
|
+
});
|
|
56
|
+
Object.defineProperty(exports, "requireAllOrNone", {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
get: function () { return chunkZLMPRPCY_cjs.requireAllOrNone; }
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(exports, "requireOneOf", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () { return chunkZLMPRPCY_cjs.requireOneOf; }
|
|
63
|
+
});
|
|
64
|
+
Object.defineProperty(exports, "required", {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
get: function () { return chunkZLMPRPCY_cjs.required; }
|
|
67
|
+
});
|
|
68
|
+
Object.defineProperty(exports, "requiredIf", {
|
|
69
|
+
enumerable: true,
|
|
70
|
+
get: function () { return chunkZLMPRPCY_cjs.requiredIf; }
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(exports, "requiredUnless", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function () { return chunkZLMPRPCY_cjs.requiredUnless; }
|
|
75
|
+
});
|
|
76
|
+
Object.defineProperty(exports, "validateConditional", {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
get: function () { return chunkZLMPRPCY_cjs.validateConditional; }
|
|
79
|
+
});
|
|
80
|
+
//# sourceMappingURL=index.cjs.map
|
|
81
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs"}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { I as IValidationError } from '../common-CBDYNJeh.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Check if field is required and present
|
|
5
|
+
*
|
|
6
|
+
* @param value - Value to check
|
|
7
|
+
* @param fieldName - Field name for error
|
|
8
|
+
* @returns Validation error or null
|
|
9
|
+
*/
|
|
10
|
+
declare function required(value: unknown, fieldName: string): IValidationError | null;
|
|
11
|
+
/**
|
|
12
|
+
* Check if value meets minimum length
|
|
13
|
+
*
|
|
14
|
+
* @param value - Value to check
|
|
15
|
+
* @param min - Minimum length
|
|
16
|
+
* @param fieldName - Field name for error
|
|
17
|
+
* @returns Validation error or null
|
|
18
|
+
*/
|
|
19
|
+
declare function minLength(value: string | unknown[], min: number, fieldName: string): IValidationError | null;
|
|
20
|
+
/**
|
|
21
|
+
* Check if value meets maximum length
|
|
22
|
+
*
|
|
23
|
+
* @param value - Value to check
|
|
24
|
+
* @param max - Maximum length
|
|
25
|
+
* @param fieldName - Field name for error
|
|
26
|
+
* @returns Validation error or null
|
|
27
|
+
*/
|
|
28
|
+
declare function maxLength(value: string | unknown[], max: number, fieldName: string): IValidationError | null;
|
|
29
|
+
/**
|
|
30
|
+
* Check if value is within range
|
|
31
|
+
*
|
|
32
|
+
* @param value - Value to check
|
|
33
|
+
* @param min - Minimum value
|
|
34
|
+
* @param max - Maximum value
|
|
35
|
+
* @param fieldName - Field name for error
|
|
36
|
+
* @returns Validation error or null
|
|
37
|
+
*/
|
|
38
|
+
declare function inRange(value: number, min: number, max: number, fieldName: string): IValidationError | null;
|
|
39
|
+
/**
|
|
40
|
+
* Check if value matches pattern
|
|
41
|
+
*
|
|
42
|
+
* @param value - Value to check
|
|
43
|
+
* @param pattern - RegExp pattern
|
|
44
|
+
* @param fieldName - Field name for error
|
|
45
|
+
* @param message - Custom error message
|
|
46
|
+
* @returns Validation error or null
|
|
47
|
+
*/
|
|
48
|
+
declare function matchesPattern(value: string, pattern: RegExp, fieldName: string, message?: string): IValidationError | null;
|
|
49
|
+
/**
|
|
50
|
+
* Check if value is one of allowed values
|
|
51
|
+
*
|
|
52
|
+
* @param value - Value to check
|
|
53
|
+
* @param allowedValues - Allowed values
|
|
54
|
+
* @param fieldName - Field name for error
|
|
55
|
+
* @returns Validation error or null
|
|
56
|
+
*/
|
|
57
|
+
declare function oneOf(value: unknown, allowedValues: unknown[], fieldName: string): IValidationError | null;
|
|
58
|
+
/**
|
|
59
|
+
* Helper to check if value is present (truthy)
|
|
60
|
+
*/
|
|
61
|
+
declare function isPresent(value: unknown): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Helper to check if value is empty
|
|
64
|
+
*/
|
|
65
|
+
declare function isEmpty(value: unknown): boolean;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Conditional validation rule
|
|
69
|
+
*/
|
|
70
|
+
interface ConditionalRule<T> {
|
|
71
|
+
/** Field to check */
|
|
72
|
+
when: keyof T;
|
|
73
|
+
/** Condition to check */
|
|
74
|
+
is: unknown | ((value: unknown) => boolean);
|
|
75
|
+
/** Validation to run if condition is true */
|
|
76
|
+
then: (value: unknown, data: T) => IValidationError | null;
|
|
77
|
+
/** Validation to run if condition is false */
|
|
78
|
+
otherwise?: (value: unknown, data: T) => IValidationError | null;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Run conditional validation
|
|
82
|
+
*
|
|
83
|
+
* @param data - Full data object
|
|
84
|
+
* @param rule - Conditional rule
|
|
85
|
+
* @param value - Value being validated
|
|
86
|
+
* @returns Validation error or null
|
|
87
|
+
*/
|
|
88
|
+
declare function validateConditional<T extends object>(data: T, rule: ConditionalRule<T>, value: unknown): IValidationError | null;
|
|
89
|
+
/**
|
|
90
|
+
* Require field if another field is present
|
|
91
|
+
*
|
|
92
|
+
* @param data - Full data object
|
|
93
|
+
* @param field - Field to validate
|
|
94
|
+
* @param dependsOn - Field this depends on
|
|
95
|
+
* @returns Validation error or null
|
|
96
|
+
*/
|
|
97
|
+
declare function requiredIf<T extends object>(data: T, field: keyof T, dependsOn: keyof T): IValidationError | null;
|
|
98
|
+
/**
|
|
99
|
+
* Require field unless another field is present
|
|
100
|
+
*
|
|
101
|
+
* @param data - Full data object
|
|
102
|
+
* @param field - Field to validate
|
|
103
|
+
* @param unlessField - Field that makes this optional
|
|
104
|
+
* @returns Validation error or null
|
|
105
|
+
*/
|
|
106
|
+
declare function requiredUnless<T extends object>(data: T, field: keyof T, unlessField: keyof T): IValidationError | null;
|
|
107
|
+
/**
|
|
108
|
+
* Require at least one of the specified fields
|
|
109
|
+
*
|
|
110
|
+
* @param data - Full data object
|
|
111
|
+
* @param fields - Fields to check
|
|
112
|
+
* @returns Validation error or null
|
|
113
|
+
*/
|
|
114
|
+
declare function requireOneOf<T extends object>(data: T, fields: (keyof T)[]): IValidationError | null;
|
|
115
|
+
/**
|
|
116
|
+
* Require all or none of the specified fields
|
|
117
|
+
*
|
|
118
|
+
* @param data - Full data object
|
|
119
|
+
* @param fields - Fields to check
|
|
120
|
+
* @returns Validation error or null
|
|
121
|
+
*/
|
|
122
|
+
declare function requireAllOrNone<T extends object>(data: T, fields: (keyof T)[]): IValidationError | null;
|
|
123
|
+
/**
|
|
124
|
+
* Field must match another field
|
|
125
|
+
*
|
|
126
|
+
* @param data - Full data object
|
|
127
|
+
* @param field - Field to validate
|
|
128
|
+
* @param matchField - Field to match
|
|
129
|
+
* @returns Validation error or null
|
|
130
|
+
*/
|
|
131
|
+
declare function mustMatch<T extends object>(data: T, field: keyof T, matchField: keyof T): IValidationError | null;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Error message templates
|
|
135
|
+
*/
|
|
136
|
+
interface ErrorMessages {
|
|
137
|
+
required?: string;
|
|
138
|
+
minLength?: string;
|
|
139
|
+
maxLength?: string;
|
|
140
|
+
pattern?: string;
|
|
141
|
+
email?: string;
|
|
142
|
+
phone?: string;
|
|
143
|
+
url?: string;
|
|
144
|
+
numeric?: string;
|
|
145
|
+
alpha?: string;
|
|
146
|
+
alphanumeric?: string;
|
|
147
|
+
[key: string]: string | undefined;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Generate error message from template
|
|
151
|
+
*
|
|
152
|
+
* @param template - Message template
|
|
153
|
+
* @param params - Template parameters
|
|
154
|
+
* @returns Formatted message
|
|
155
|
+
*/
|
|
156
|
+
declare function formatMessage(template: string, params: Record<string, unknown>): string;
|
|
157
|
+
/**
|
|
158
|
+
* Create error message generator
|
|
159
|
+
*
|
|
160
|
+
* @param customMessages - Custom message templates
|
|
161
|
+
* @returns Error message generator function
|
|
162
|
+
*/
|
|
163
|
+
declare function createErrorMessages(customMessages?: ErrorMessages): {
|
|
164
|
+
/**
|
|
165
|
+
* Get error message for code
|
|
166
|
+
*/
|
|
167
|
+
getMessage(code: string, params?: Record<string, unknown>): string;
|
|
168
|
+
/**
|
|
169
|
+
* Create validation error
|
|
170
|
+
*/
|
|
171
|
+
createError(field: string, code: string, params?: Record<string, unknown>): IValidationError;
|
|
172
|
+
/**
|
|
173
|
+
* Format multiple errors as object
|
|
174
|
+
*/
|
|
175
|
+
formatErrors(errors: IValidationError[]): Record<string, string[]>;
|
|
176
|
+
/**
|
|
177
|
+
* Get first error for each field
|
|
178
|
+
*/
|
|
179
|
+
getFirstErrors(errors: IValidationError[]): Record<string, string>;
|
|
180
|
+
/**
|
|
181
|
+
* Check if field has errors
|
|
182
|
+
*/
|
|
183
|
+
hasError(errors: IValidationError[], field: string): boolean;
|
|
184
|
+
/**
|
|
185
|
+
* Get errors for specific field
|
|
186
|
+
*/
|
|
187
|
+
getFieldErrors(errors: IValidationError[], field: string): string[];
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* Default error generator
|
|
191
|
+
*/
|
|
192
|
+
declare const errors: {
|
|
193
|
+
/**
|
|
194
|
+
* Get error message for code
|
|
195
|
+
*/
|
|
196
|
+
getMessage(code: string, params?: Record<string, unknown>): string;
|
|
197
|
+
/**
|
|
198
|
+
* Create validation error
|
|
199
|
+
*/
|
|
200
|
+
createError(field: string, code: string, params?: Record<string, unknown>): IValidationError;
|
|
201
|
+
/**
|
|
202
|
+
* Format multiple errors as object
|
|
203
|
+
*/
|
|
204
|
+
formatErrors(errors: IValidationError[]): Record<string, string[]>;
|
|
205
|
+
/**
|
|
206
|
+
* Get first error for each field
|
|
207
|
+
*/
|
|
208
|
+
getFirstErrors(errors: IValidationError[]): Record<string, string>;
|
|
209
|
+
/**
|
|
210
|
+
* Check if field has errors
|
|
211
|
+
*/
|
|
212
|
+
hasError(errors: IValidationError[], field: string): boolean;
|
|
213
|
+
/**
|
|
214
|
+
* Get errors for specific field
|
|
215
|
+
*/
|
|
216
|
+
getFieldErrors(errors: IValidationError[], field: string): string[];
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* Format validation result for display
|
|
220
|
+
*
|
|
221
|
+
* @param errors - Validation errors
|
|
222
|
+
* @param format - Output format
|
|
223
|
+
* @returns Formatted errors
|
|
224
|
+
*/
|
|
225
|
+
declare function formatValidationResult(validationErrors: IValidationError[], format?: 'object' | 'array' | 'flat'): Record<string, string[]> | IValidationError[] | string[];
|
|
226
|
+
|
|
227
|
+
export { type ConditionalRule, type ErrorMessages, createErrorMessages, errors, formatMessage, formatValidationResult, inRange, isEmpty, isPresent, matchesPattern, maxLength, minLength, mustMatch, oneOf, requireAllOrNone, requireOneOf, required, requiredIf, requiredUnless, validateConditional };
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { I as IValidationError } from '../common-CBDYNJeh.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Check if field is required and present
|
|
5
|
+
*
|
|
6
|
+
* @param value - Value to check
|
|
7
|
+
* @param fieldName - Field name for error
|
|
8
|
+
* @returns Validation error or null
|
|
9
|
+
*/
|
|
10
|
+
declare function required(value: unknown, fieldName: string): IValidationError | null;
|
|
11
|
+
/**
|
|
12
|
+
* Check if value meets minimum length
|
|
13
|
+
*
|
|
14
|
+
* @param value - Value to check
|
|
15
|
+
* @param min - Minimum length
|
|
16
|
+
* @param fieldName - Field name for error
|
|
17
|
+
* @returns Validation error or null
|
|
18
|
+
*/
|
|
19
|
+
declare function minLength(value: string | unknown[], min: number, fieldName: string): IValidationError | null;
|
|
20
|
+
/**
|
|
21
|
+
* Check if value meets maximum length
|
|
22
|
+
*
|
|
23
|
+
* @param value - Value to check
|
|
24
|
+
* @param max - Maximum length
|
|
25
|
+
* @param fieldName - Field name for error
|
|
26
|
+
* @returns Validation error or null
|
|
27
|
+
*/
|
|
28
|
+
declare function maxLength(value: string | unknown[], max: number, fieldName: string): IValidationError | null;
|
|
29
|
+
/**
|
|
30
|
+
* Check if value is within range
|
|
31
|
+
*
|
|
32
|
+
* @param value - Value to check
|
|
33
|
+
* @param min - Minimum value
|
|
34
|
+
* @param max - Maximum value
|
|
35
|
+
* @param fieldName - Field name for error
|
|
36
|
+
* @returns Validation error or null
|
|
37
|
+
*/
|
|
38
|
+
declare function inRange(value: number, min: number, max: number, fieldName: string): IValidationError | null;
|
|
39
|
+
/**
|
|
40
|
+
* Check if value matches pattern
|
|
41
|
+
*
|
|
42
|
+
* @param value - Value to check
|
|
43
|
+
* @param pattern - RegExp pattern
|
|
44
|
+
* @param fieldName - Field name for error
|
|
45
|
+
* @param message - Custom error message
|
|
46
|
+
* @returns Validation error or null
|
|
47
|
+
*/
|
|
48
|
+
declare function matchesPattern(value: string, pattern: RegExp, fieldName: string, message?: string): IValidationError | null;
|
|
49
|
+
/**
|
|
50
|
+
* Check if value is one of allowed values
|
|
51
|
+
*
|
|
52
|
+
* @param value - Value to check
|
|
53
|
+
* @param allowedValues - Allowed values
|
|
54
|
+
* @param fieldName - Field name for error
|
|
55
|
+
* @returns Validation error or null
|
|
56
|
+
*/
|
|
57
|
+
declare function oneOf(value: unknown, allowedValues: unknown[], fieldName: string): IValidationError | null;
|
|
58
|
+
/**
|
|
59
|
+
* Helper to check if value is present (truthy)
|
|
60
|
+
*/
|
|
61
|
+
declare function isPresent(value: unknown): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Helper to check if value is empty
|
|
64
|
+
*/
|
|
65
|
+
declare function isEmpty(value: unknown): boolean;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Conditional validation rule
|
|
69
|
+
*/
|
|
70
|
+
interface ConditionalRule<T> {
|
|
71
|
+
/** Field to check */
|
|
72
|
+
when: keyof T;
|
|
73
|
+
/** Condition to check */
|
|
74
|
+
is: unknown | ((value: unknown) => boolean);
|
|
75
|
+
/** Validation to run if condition is true */
|
|
76
|
+
then: (value: unknown, data: T) => IValidationError | null;
|
|
77
|
+
/** Validation to run if condition is false */
|
|
78
|
+
otherwise?: (value: unknown, data: T) => IValidationError | null;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Run conditional validation
|
|
82
|
+
*
|
|
83
|
+
* @param data - Full data object
|
|
84
|
+
* @param rule - Conditional rule
|
|
85
|
+
* @param value - Value being validated
|
|
86
|
+
* @returns Validation error or null
|
|
87
|
+
*/
|
|
88
|
+
declare function validateConditional<T extends object>(data: T, rule: ConditionalRule<T>, value: unknown): IValidationError | null;
|
|
89
|
+
/**
|
|
90
|
+
* Require field if another field is present
|
|
91
|
+
*
|
|
92
|
+
* @param data - Full data object
|
|
93
|
+
* @param field - Field to validate
|
|
94
|
+
* @param dependsOn - Field this depends on
|
|
95
|
+
* @returns Validation error or null
|
|
96
|
+
*/
|
|
97
|
+
declare function requiredIf<T extends object>(data: T, field: keyof T, dependsOn: keyof T): IValidationError | null;
|
|
98
|
+
/**
|
|
99
|
+
* Require field unless another field is present
|
|
100
|
+
*
|
|
101
|
+
* @param data - Full data object
|
|
102
|
+
* @param field - Field to validate
|
|
103
|
+
* @param unlessField - Field that makes this optional
|
|
104
|
+
* @returns Validation error or null
|
|
105
|
+
*/
|
|
106
|
+
declare function requiredUnless<T extends object>(data: T, field: keyof T, unlessField: keyof T): IValidationError | null;
|
|
107
|
+
/**
|
|
108
|
+
* Require at least one of the specified fields
|
|
109
|
+
*
|
|
110
|
+
* @param data - Full data object
|
|
111
|
+
* @param fields - Fields to check
|
|
112
|
+
* @returns Validation error or null
|
|
113
|
+
*/
|
|
114
|
+
declare function requireOneOf<T extends object>(data: T, fields: (keyof T)[]): IValidationError | null;
|
|
115
|
+
/**
|
|
116
|
+
* Require all or none of the specified fields
|
|
117
|
+
*
|
|
118
|
+
* @param data - Full data object
|
|
119
|
+
* @param fields - Fields to check
|
|
120
|
+
* @returns Validation error or null
|
|
121
|
+
*/
|
|
122
|
+
declare function requireAllOrNone<T extends object>(data: T, fields: (keyof T)[]): IValidationError | null;
|
|
123
|
+
/**
|
|
124
|
+
* Field must match another field
|
|
125
|
+
*
|
|
126
|
+
* @param data - Full data object
|
|
127
|
+
* @param field - Field to validate
|
|
128
|
+
* @param matchField - Field to match
|
|
129
|
+
* @returns Validation error or null
|
|
130
|
+
*/
|
|
131
|
+
declare function mustMatch<T extends object>(data: T, field: keyof T, matchField: keyof T): IValidationError | null;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Error message templates
|
|
135
|
+
*/
|
|
136
|
+
interface ErrorMessages {
|
|
137
|
+
required?: string;
|
|
138
|
+
minLength?: string;
|
|
139
|
+
maxLength?: string;
|
|
140
|
+
pattern?: string;
|
|
141
|
+
email?: string;
|
|
142
|
+
phone?: string;
|
|
143
|
+
url?: string;
|
|
144
|
+
numeric?: string;
|
|
145
|
+
alpha?: string;
|
|
146
|
+
alphanumeric?: string;
|
|
147
|
+
[key: string]: string | undefined;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Generate error message from template
|
|
151
|
+
*
|
|
152
|
+
* @param template - Message template
|
|
153
|
+
* @param params - Template parameters
|
|
154
|
+
* @returns Formatted message
|
|
155
|
+
*/
|
|
156
|
+
declare function formatMessage(template: string, params: Record<string, unknown>): string;
|
|
157
|
+
/**
|
|
158
|
+
* Create error message generator
|
|
159
|
+
*
|
|
160
|
+
* @param customMessages - Custom message templates
|
|
161
|
+
* @returns Error message generator function
|
|
162
|
+
*/
|
|
163
|
+
declare function createErrorMessages(customMessages?: ErrorMessages): {
|
|
164
|
+
/**
|
|
165
|
+
* Get error message for code
|
|
166
|
+
*/
|
|
167
|
+
getMessage(code: string, params?: Record<string, unknown>): string;
|
|
168
|
+
/**
|
|
169
|
+
* Create validation error
|
|
170
|
+
*/
|
|
171
|
+
createError(field: string, code: string, params?: Record<string, unknown>): IValidationError;
|
|
172
|
+
/**
|
|
173
|
+
* Format multiple errors as object
|
|
174
|
+
*/
|
|
175
|
+
formatErrors(errors: IValidationError[]): Record<string, string[]>;
|
|
176
|
+
/**
|
|
177
|
+
* Get first error for each field
|
|
178
|
+
*/
|
|
179
|
+
getFirstErrors(errors: IValidationError[]): Record<string, string>;
|
|
180
|
+
/**
|
|
181
|
+
* Check if field has errors
|
|
182
|
+
*/
|
|
183
|
+
hasError(errors: IValidationError[], field: string): boolean;
|
|
184
|
+
/**
|
|
185
|
+
* Get errors for specific field
|
|
186
|
+
*/
|
|
187
|
+
getFieldErrors(errors: IValidationError[], field: string): string[];
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* Default error generator
|
|
191
|
+
*/
|
|
192
|
+
declare const errors: {
|
|
193
|
+
/**
|
|
194
|
+
* Get error message for code
|
|
195
|
+
*/
|
|
196
|
+
getMessage(code: string, params?: Record<string, unknown>): string;
|
|
197
|
+
/**
|
|
198
|
+
* Create validation error
|
|
199
|
+
*/
|
|
200
|
+
createError(field: string, code: string, params?: Record<string, unknown>): IValidationError;
|
|
201
|
+
/**
|
|
202
|
+
* Format multiple errors as object
|
|
203
|
+
*/
|
|
204
|
+
formatErrors(errors: IValidationError[]): Record<string, string[]>;
|
|
205
|
+
/**
|
|
206
|
+
* Get first error for each field
|
|
207
|
+
*/
|
|
208
|
+
getFirstErrors(errors: IValidationError[]): Record<string, string>;
|
|
209
|
+
/**
|
|
210
|
+
* Check if field has errors
|
|
211
|
+
*/
|
|
212
|
+
hasError(errors: IValidationError[], field: string): boolean;
|
|
213
|
+
/**
|
|
214
|
+
* Get errors for specific field
|
|
215
|
+
*/
|
|
216
|
+
getFieldErrors(errors: IValidationError[], field: string): string[];
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* Format validation result for display
|
|
220
|
+
*
|
|
221
|
+
* @param errors - Validation errors
|
|
222
|
+
* @param format - Output format
|
|
223
|
+
* @returns Formatted errors
|
|
224
|
+
*/
|
|
225
|
+
declare function formatValidationResult(validationErrors: IValidationError[], format?: 'object' | 'array' | 'flat'): Record<string, string[]> | IValidationError[] | string[];
|
|
226
|
+
|
|
227
|
+
export { type ConditionalRule, type ErrorMessages, createErrorMessages, errors, formatMessage, formatValidationResult, inRange, isEmpty, isPresent, matchesPattern, maxLength, minLength, mustMatch, oneOf, requireAllOrNone, requireOneOf, required, requiredIf, requiredUnless, validateConditional };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { createErrorMessages, errors, formatMessage, formatValidationResult, inRange, isEmpty, isPresent, matchesPattern, maxLength, minLength, mustMatch, oneOf, requireAllOrNone, requireOneOf, required, requiredIf, requiredUnless, validateConditional } from '../chunk-JBN7C5WE.js';
|
|
2
|
+
import '../chunk-4CV4JOE5.js';
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
package/dist/i18n.cjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkG4GYQGTW_cjs = require('./chunk-G4GYQGTW.cjs');
|
|
4
|
+
require('./chunk-CZLDE2OZ.cjs');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Object.defineProperty(exports, "addLocale", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return chunkG4GYQGTW_cjs.addLocale; }
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "getAvailableLocales", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return chunkG4GYQGTW_cjs.getAvailableLocales; }
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(exports, "getLocale", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () { return chunkG4GYQGTW_cjs.getLocale; }
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(exports, "getMessage", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () { return chunkG4GYQGTW_cjs.getMessage; }
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "setCustomMessages", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () { return chunkG4GYQGTW_cjs.setCustomMessages; }
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports, "setLocale", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () { return chunkG4GYQGTW_cjs.setLocale; }
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(exports, "withLocalization", {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () { return chunkG4GYQGTW_cjs.withLocalization; }
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=i18n.cjs.map
|
|
37
|
+
//# sourceMappingURL=i18n.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"i18n.cjs"}
|
package/dist/i18n.d.cts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internationalization (i18n) module for Utilitify
|
|
3
|
+
* Provides multi-language error message support
|
|
4
|
+
*
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
* @since 1.0.0
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Supported locales
|
|
10
|
+
*/
|
|
11
|
+
type Locale = 'en' | 'es' | 'fr' | 'de' | 'ar' | 'zh' | 'ur' | 'hi';
|
|
12
|
+
/**
|
|
13
|
+
* Error message templates
|
|
14
|
+
*/
|
|
15
|
+
interface MessageTemplates {
|
|
16
|
+
required: string;
|
|
17
|
+
invalid: string;
|
|
18
|
+
tooShort: string;
|
|
19
|
+
tooLong: string;
|
|
20
|
+
emailInvalid: string;
|
|
21
|
+
emailDisposable: string;
|
|
22
|
+
emailDomainBlocked: string;
|
|
23
|
+
phoneInvalid: string;
|
|
24
|
+
phoneTooShort: string;
|
|
25
|
+
phoneTooLong: string;
|
|
26
|
+
phoneMobileOnly: string;
|
|
27
|
+
passwordTooWeak: string;
|
|
28
|
+
passwordNoUppercase: string;
|
|
29
|
+
passwordNoLowercase: string;
|
|
30
|
+
passwordNoNumber: string;
|
|
31
|
+
passwordNoSymbol: string;
|
|
32
|
+
passwordCommonPattern: string;
|
|
33
|
+
nameInvalid: string;
|
|
34
|
+
nameContainsNumbers: string;
|
|
35
|
+
usernameReserved: string;
|
|
36
|
+
usernameInvalidChars: string;
|
|
37
|
+
urlInvalid: string;
|
|
38
|
+
urlDangerous: string;
|
|
39
|
+
cardInvalid: string;
|
|
40
|
+
cardExpired: string;
|
|
41
|
+
cardCvvInvalid: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Set the current locale
|
|
45
|
+
*
|
|
46
|
+
* @param locale - Locale to set
|
|
47
|
+
* @since 1.0.0
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* import { setLocale } from 'utilitify/i18n';
|
|
52
|
+
* setLocale('es'); // Switch to Spanish
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
declare function setLocale(locale: Locale): void;
|
|
56
|
+
/**
|
|
57
|
+
* Get the current locale
|
|
58
|
+
*/
|
|
59
|
+
declare function getLocale(): Locale;
|
|
60
|
+
/**
|
|
61
|
+
* Get a translated message
|
|
62
|
+
*
|
|
63
|
+
* @param key - Message key
|
|
64
|
+
* @param params - Parameters to interpolate
|
|
65
|
+
* @returns Translated message
|
|
66
|
+
* @since 1.0.0
|
|
67
|
+
*/
|
|
68
|
+
declare function getMessage(key: keyof MessageTemplates, params?: Record<string, string | number>): string;
|
|
69
|
+
/**
|
|
70
|
+
* Set custom messages
|
|
71
|
+
*
|
|
72
|
+
* @param messages - Custom message overrides
|
|
73
|
+
* @since 1.0.0
|
|
74
|
+
*/
|
|
75
|
+
declare function setCustomMessages(messages: Partial<MessageTemplates>): void;
|
|
76
|
+
/**
|
|
77
|
+
* Add a new locale
|
|
78
|
+
*
|
|
79
|
+
* @param locale - Locale code
|
|
80
|
+
* @param messages - Message templates
|
|
81
|
+
* @since 1.0.0
|
|
82
|
+
*/
|
|
83
|
+
declare function addLocale(locale: string, messages: MessageTemplates): void;
|
|
84
|
+
/**
|
|
85
|
+
* Get all available locales
|
|
86
|
+
*/
|
|
87
|
+
declare function getAvailableLocales(): Locale[];
|
|
88
|
+
/**
|
|
89
|
+
* Create a localized validator wrapper
|
|
90
|
+
*
|
|
91
|
+
* @param validator - Original validator function
|
|
92
|
+
* @returns Localized validator
|
|
93
|
+
* @since 1.0.0
|
|
94
|
+
*/
|
|
95
|
+
declare function withLocalization<T extends (...args: unknown[]) => {
|
|
96
|
+
errors: Array<{
|
|
97
|
+
code: string;
|
|
98
|
+
message: string;
|
|
99
|
+
}>;
|
|
100
|
+
}>(validator: T): T;
|
|
101
|
+
|
|
102
|
+
export { type Locale, type MessageTemplates, addLocale, getAvailableLocales, getLocale, getMessage, setCustomMessages, setLocale, withLocalization };
|