@jarenjs/formats 0.8.4 → 0.9.2
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 +128 -2
- package/dist/types/datetime.d.ts +109 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/json.d.ts +71 -0
- package/dist/types/number.d.ts +144 -0
- package/dist/types/string.d.ts +379 -0
- package/dist/types/testers.d.ts +31 -0
- package/package.json +28 -8
- package/src/datetime.js +373 -0
- package/src/index.js +31 -0
- package/src/json.js +90 -0
- package/src/number.js +219 -0
- package/src/string.js +548 -0
- package/src/testers.js +216 -0
- package/dist/index.js +0 -679
- package/dist/index.js.map +0 -7
- package/dist/index.min.js +0 -2
- package/dist/index.min.js.map +0 -7
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
export type JSONSchema = {
|
|
2
|
+
format?: string;
|
|
3
|
+
formatMinimum?: string;
|
|
4
|
+
formatExclusiveMinimum?: string;
|
|
5
|
+
formatMaximum?: string;
|
|
6
|
+
formatExclusiveMaximum?: string;
|
|
7
|
+
};
|
|
8
|
+
export type ValidationObject = {
|
|
9
|
+
options: {
|
|
10
|
+
skipErrors: boolean;
|
|
11
|
+
};
|
|
12
|
+
createErrorHandler: (expected: any, key: string, ...details: any[]) => (data: any, dataPath?: string) => boolean;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {{format?: string, formatMinimum?: string, formatExclusiveMinimum?: string, formatMaximum?: string, formatExclusiveMaximum?: string}} JSONSchema
|
|
16
|
+
* @typedef {{
|
|
17
|
+
* options: {skipErrors: boolean},
|
|
18
|
+
* createErrorHandler: (expected: any, key: string, ...details: any[]) => (data: any, dataPath?: string) => boolean
|
|
19
|
+
* }} ValidationObject
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Creates a string format compiler function.
|
|
23
|
+
*
|
|
24
|
+
* @param {string} formatName - The name of the format (e.g., 'email', 'uri')
|
|
25
|
+
* @param {(value: string) => boolean} isFormatTest - The function to test if a string matches the format
|
|
26
|
+
* @returns {(schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean} A compiler function that creates format validators
|
|
27
|
+
* @example
|
|
28
|
+
* const compiler = createStringFormatCompiler('email', isValidEmail);
|
|
29
|
+
* const validator = compiler(schemaObj, { format: 'email' });
|
|
30
|
+
* validator('user@example.com'); // true
|
|
31
|
+
*/
|
|
32
|
+
export declare function createStringFormatCompiler(formatName: string, isFormatTest: (value: string) => boolean): (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Compiles a validator for the 'alpha' format.
|
|
35
|
+
* Validates strings containing only alphabetic characters (a-z, A-Z).
|
|
36
|
+
*
|
|
37
|
+
* @param {ValidationObject} schemaObj - The validation object for error handling and options
|
|
38
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
39
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
40
|
+
* @example
|
|
41
|
+
* compileAlphaFormat(schemaObj, { format: 'alpha' })('HelloWorld'); // true
|
|
42
|
+
* compileAlphaFormat(schemaObj, { format: 'alpha' })('Hello123'); // false (with error)
|
|
43
|
+
*/
|
|
44
|
+
export declare const compileAlphaFormat: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Compiles a validator for the 'alphanumeric' format.
|
|
47
|
+
* Validates strings containing only alphabetic characters and digits (a-z, A-Z, 0-9).
|
|
48
|
+
*
|
|
49
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
50
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
51
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
52
|
+
* @example
|
|
53
|
+
* compileAlphaNumericFormat(schemaObj, { format: 'alphanumeric' })('Hello123'); // true
|
|
54
|
+
*/
|
|
55
|
+
export declare const compileAlphaNumericFormat: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Compiles a validator for the 'uppercase' format.
|
|
58
|
+
* Validates strings containing only uppercase characters.
|
|
59
|
+
*
|
|
60
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
61
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
62
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
63
|
+
*/
|
|
64
|
+
export declare const compileUppercaseFormat: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Compiles a validator for the 'lowercase' format.
|
|
67
|
+
* Validates strings containing only lowercase characters.
|
|
68
|
+
*
|
|
69
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
70
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
71
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
72
|
+
*/
|
|
73
|
+
export declare const compileLowercaseFormat: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Compiles a validator for the 'identifier' format.
|
|
76
|
+
* Validates general identifier strings (variable names, etc.).
|
|
77
|
+
*
|
|
78
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
79
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
80
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
81
|
+
*/
|
|
82
|
+
export declare const compileIdentifierFormat: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Compiles a validator for the 'html-identifier' format.
|
|
85
|
+
* Validates HTML element and attribute identifiers.
|
|
86
|
+
*
|
|
87
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
88
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
89
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
90
|
+
*/
|
|
91
|
+
export declare const compileHtmlIdentifierFormat: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Compiles a validator for the 'css-identifier' format.
|
|
94
|
+
* Validates CSS class and ID selectors.
|
|
95
|
+
*
|
|
96
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
97
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
98
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
99
|
+
*/
|
|
100
|
+
export declare const compileCssIdentifierFormat: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Compiles a validator for the 'hexadecimal' format.
|
|
103
|
+
* Validates hexadecimal number strings (0-9, a-f, A-F).
|
|
104
|
+
*
|
|
105
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
106
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
107
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
108
|
+
*/
|
|
109
|
+
export declare const compileHexadecimalFormat: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Compiles a validator for the 'numeric' format.
|
|
112
|
+
* Validates numeric strings containing only digits.
|
|
113
|
+
*
|
|
114
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
115
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
116
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
117
|
+
*/
|
|
118
|
+
export declare const compileNumericFormat: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Compiles a validator for the 'color' format.
|
|
121
|
+
* Validates hexadecimal color codes (e.g., #FFF, #FFFFFF).
|
|
122
|
+
*
|
|
123
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
124
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
125
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
126
|
+
*/
|
|
127
|
+
export declare const compileColorFormat: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
128
|
+
/**
|
|
129
|
+
* Compiles a validator for the 'regex' format.
|
|
130
|
+
* Validates that a string is a valid regular expression pattern.
|
|
131
|
+
*
|
|
132
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
133
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
134
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
135
|
+
*/
|
|
136
|
+
export declare const compileRegexFormat: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
137
|
+
/**
|
|
138
|
+
* Compiles a validator for the 'uri' format.
|
|
139
|
+
* Validates absolute URI strings per RFC 3986.
|
|
140
|
+
*
|
|
141
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
142
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
143
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
144
|
+
* @example
|
|
145
|
+
* compileUriFormat(schemaObj, { format: 'uri' })('https://example.com'); // true
|
|
146
|
+
*/
|
|
147
|
+
export declare const compileUriFormat: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
148
|
+
/**
|
|
149
|
+
* Compiles a validator for the 'uri--full' format.
|
|
150
|
+
* Validates absolute URI strings with stricter checking.
|
|
151
|
+
*
|
|
152
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
153
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
154
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
155
|
+
*/
|
|
156
|
+
export declare const compileUriFullFormat: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
157
|
+
/**
|
|
158
|
+
* Compiles a validator for the 'uri-reference' format.
|
|
159
|
+
* Validates URI reference strings (absolute or relative) per RFC 3986.
|
|
160
|
+
*
|
|
161
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
162
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
163
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
164
|
+
*/
|
|
165
|
+
export declare const compileUriReferenceFormat: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
166
|
+
/**
|
|
167
|
+
* Compiles a validator for the 'uri-reference--full' format.
|
|
168
|
+
* Validates URI reference strings with stricter checking.
|
|
169
|
+
*
|
|
170
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
171
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
172
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
173
|
+
*/
|
|
174
|
+
export declare const compileUriReferenceFullFormat: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
175
|
+
/**
|
|
176
|
+
* Compiles a validator for the 'uri-template' format.
|
|
177
|
+
* Validates URI template strings per RFC 6570.
|
|
178
|
+
*
|
|
179
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
180
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
181
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
182
|
+
*/
|
|
183
|
+
export declare const compileUriTemplateFormat: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
184
|
+
/**
|
|
185
|
+
* Compiles a validator for the 'url' format.
|
|
186
|
+
* Validates URL strings per the WHATWG URL Standard.
|
|
187
|
+
*
|
|
188
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
189
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
190
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
191
|
+
*/
|
|
192
|
+
export declare const compileUrlFormat: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
193
|
+
/**
|
|
194
|
+
* Compiles a validator for the 'url--full' format.
|
|
195
|
+
* Validates URL strings with stricter checking.
|
|
196
|
+
*
|
|
197
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
198
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
199
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
200
|
+
*/
|
|
201
|
+
export declare const compileUrlFullFormat: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
202
|
+
/**
|
|
203
|
+
* Compiles a validator for the 'iri' format.
|
|
204
|
+
* Validates IRI strings per RFC 3987.
|
|
205
|
+
*
|
|
206
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
207
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
208
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
209
|
+
*/
|
|
210
|
+
export declare const compileIriFormat: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
211
|
+
/**
|
|
212
|
+
* Compiles a validator for the 'iri-reference' format.
|
|
213
|
+
* Validates IRI reference strings (absolute or relative) per RFC 3987.
|
|
214
|
+
*
|
|
215
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
216
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
217
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
218
|
+
*/
|
|
219
|
+
export declare const compileIriReferenceFormat: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
220
|
+
/**
|
|
221
|
+
* Compiles a validator for the 'email' format.
|
|
222
|
+
* Validates email address strings per RFC 5321.
|
|
223
|
+
*
|
|
224
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
225
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
226
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
227
|
+
* @example
|
|
228
|
+
* compileEmailFormat(schemaObj, { format: 'email' })('user@example.com'); // true
|
|
229
|
+
*/
|
|
230
|
+
export declare const compileEmailFormat: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
231
|
+
/**
|
|
232
|
+
* Compiles a validator for the 'email--full' format.
|
|
233
|
+
* Validates email address strings with stricter checking.
|
|
234
|
+
*
|
|
235
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
236
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
237
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
238
|
+
*/
|
|
239
|
+
export declare const compileEmailFullFormat: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
240
|
+
/**
|
|
241
|
+
* Compiles a validator for the 'idn-email' format.
|
|
242
|
+
* Validates internationalized email addresses (EAI) per RFC 6531.
|
|
243
|
+
*
|
|
244
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
245
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
246
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
247
|
+
*/
|
|
248
|
+
export declare const compileIdnEmailFormat: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
249
|
+
/**
|
|
250
|
+
* Compiles a validator for the 'hostname' format.
|
|
251
|
+
* Validates hostname strings per RFC 1123.
|
|
252
|
+
*
|
|
253
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
254
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
255
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
256
|
+
*/
|
|
257
|
+
export declare const compileHostnameFormat: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
258
|
+
/**
|
|
259
|
+
* Compiles a validator for the 'idn-hostname' format.
|
|
260
|
+
* Validates internationalized domain names (IDN) per RFC 5890.
|
|
261
|
+
*
|
|
262
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
263
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
264
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
265
|
+
*/
|
|
266
|
+
export declare const compileIdnHostnameFormat: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
267
|
+
/**
|
|
268
|
+
* Compiles a validator for the 'ipv4' format.
|
|
269
|
+
* Validates IPv4 address strings.
|
|
270
|
+
*
|
|
271
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
272
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
273
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
274
|
+
* @example
|
|
275
|
+
* compileIpv4Format(schemaObj, { format: 'ipv4' })('192.168.1.1'); // true
|
|
276
|
+
*/
|
|
277
|
+
export declare const compileIpv4Format: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
278
|
+
/**
|
|
279
|
+
* Compiles a validator for the 'ipv6' format.
|
|
280
|
+
* Validates IPv6 address strings.
|
|
281
|
+
*
|
|
282
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
283
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
284
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
285
|
+
*/
|
|
286
|
+
export declare const compileIpv6Format: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
287
|
+
/**
|
|
288
|
+
* Compiles a validator for the 'uuid' format.
|
|
289
|
+
* Validates UUID strings per RFC 4122.
|
|
290
|
+
*
|
|
291
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
292
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
293
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
294
|
+
* @example
|
|
295
|
+
* compileUuidFormat(schemaObj, { format: 'uuid' })('550e8400-e29b-41d4-a716-446655440000'); // true
|
|
296
|
+
*/
|
|
297
|
+
export declare const compileUuidFormat: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
298
|
+
/**
|
|
299
|
+
* Compiles a validator for the 'guid' format.
|
|
300
|
+
* Validates GUID strings (Microsoft format).
|
|
301
|
+
*
|
|
302
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
303
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
304
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
305
|
+
*/
|
|
306
|
+
export declare const compileGuidFormat: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
307
|
+
/**
|
|
308
|
+
* Compiles a validator for the 'isbn10' format.
|
|
309
|
+
* Validates ISBN-10 identifier strings.
|
|
310
|
+
*
|
|
311
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
312
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
313
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
314
|
+
*/
|
|
315
|
+
export declare const compileIsbn10Format: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
316
|
+
/**
|
|
317
|
+
* Compiles a validator for the 'isbn13' format.
|
|
318
|
+
* Validates ISBN-13 identifier strings.
|
|
319
|
+
*
|
|
320
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
321
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
322
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
323
|
+
*/
|
|
324
|
+
export declare const compileIsbn13Format: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
325
|
+
/**
|
|
326
|
+
* Compiles a validator for the 'mac' format.
|
|
327
|
+
* Validates MAC address strings.
|
|
328
|
+
*
|
|
329
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
330
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
331
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
332
|
+
*/
|
|
333
|
+
export declare const compileMacFormat: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
334
|
+
/**
|
|
335
|
+
* Compiles a validator for the 'base64' format.
|
|
336
|
+
* Validates Base64 encoded strings.
|
|
337
|
+
*
|
|
338
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
339
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
340
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
341
|
+
*/
|
|
342
|
+
export declare const compileBase64Format: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
343
|
+
/**
|
|
344
|
+
* Compiles a validator for the 'byte' format.
|
|
345
|
+
* Alias for 'base64' format.
|
|
346
|
+
*
|
|
347
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
348
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
349
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
350
|
+
*/
|
|
351
|
+
export declare const compileByteFormat: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
352
|
+
/**
|
|
353
|
+
* Compiles a validator for the 'country2' format.
|
|
354
|
+
* Validates ISO 3166-1 alpha-2 country codes.
|
|
355
|
+
*
|
|
356
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
357
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
358
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
359
|
+
* @example
|
|
360
|
+
* compileCountry2Format(schemaObj, { format: 'country2' })('US'); // true
|
|
361
|
+
* compileCountry2Format(schemaObj, { format: 'country2' })('XX'); // false (with error)
|
|
362
|
+
*/
|
|
363
|
+
export declare const compileCountry2Format: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
364
|
+
/**
|
|
365
|
+
* Compiles a validator for the 'iban' format.
|
|
366
|
+
* Validates IBAN (International Bank Account Number) strings.
|
|
367
|
+
*
|
|
368
|
+
* @param {ValidationObject} schemaObj - The validation JSONSchema for error handling and options
|
|
369
|
+
* @param {JSONSchema} jsonSchema - The JSON schema containing the format definition
|
|
370
|
+
* @returns {(data: unknown, dataPath?: string) => boolean} A validator function
|
|
371
|
+
*/
|
|
372
|
+
export declare const compileIbanFormat: (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean;
|
|
373
|
+
/**
|
|
374
|
+
* Object mapping format names to their compiler functions.
|
|
375
|
+
* Used for backward compatibility and aggregate imports.
|
|
376
|
+
*
|
|
377
|
+
* @type {Record<string, (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean>}
|
|
378
|
+
*/
|
|
379
|
+
export declare const formatValidators: Record<string, (schemaObj: ValidationObject, jsonSchema: JSONSchema) => (data: unknown, dataPath?: string) => boolean>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type StringFormatTester = (value: string) => boolean;
|
|
2
|
+
export type NumberFormatTester = (value: number) => boolean;
|
|
3
|
+
/** @typedef {(value: string) => boolean} StringFormatTester */
|
|
4
|
+
/** @typedef {(value: number) => boolean} NumberFormatTester */
|
|
5
|
+
/**
|
|
6
|
+
* String format testers (the string.js compiler group).
|
|
7
|
+
* @type {Record<string, StringFormatTester>}
|
|
8
|
+
*/
|
|
9
|
+
export declare const stringFormatTesters: Record<string, StringFormatTester>;
|
|
10
|
+
/**
|
|
11
|
+
* JSON addressing format testers (the json.js compiler group).
|
|
12
|
+
* @type {Record<string, StringFormatTester>}
|
|
13
|
+
*/
|
|
14
|
+
export declare const jsonFormatTesters: Record<string, StringFormatTester>;
|
|
15
|
+
/**
|
|
16
|
+
* Date and time format testers - the boolean twins of the parse-based
|
|
17
|
+
* compilers in datetime.js.
|
|
18
|
+
* @type {Record<string, StringFormatTester>}
|
|
19
|
+
*/
|
|
20
|
+
export declare const dateTimeFormatTesters: Record<string, StringFormatTester>;
|
|
21
|
+
/**
|
|
22
|
+
* Number format testers (the number.js compiler group). These take the
|
|
23
|
+
* NUMBER value, not a string.
|
|
24
|
+
* @type {Record<string, NumberFormatTester>}
|
|
25
|
+
*/
|
|
26
|
+
export declare const numberFormatTesters: Record<string, NumberFormatTester>;
|
|
27
|
+
/**
|
|
28
|
+
* Every format tester this package knows, in one flat registry.
|
|
29
|
+
* @type {Record<string, (value: any) => boolean>}
|
|
30
|
+
*/
|
|
31
|
+
export declare const formatTesters: Record<string, (value: any) => boolean>;
|
package/package.json
CHANGED
|
@@ -1,29 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jarenjs/formats",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.9.2",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./
|
|
6
|
+
"main": "./src/index.js",
|
|
7
|
+
"types": "./dist/types/index.d.ts",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/types/index.d.ts",
|
|
12
|
+
"default": "./src/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./package.json": "./package.json"
|
|
15
|
+
},
|
|
7
16
|
"files": [
|
|
8
|
-
"dist"
|
|
17
|
+
"dist/types/",
|
|
18
|
+
"src/"
|
|
9
19
|
],
|
|
10
20
|
"description": "Jaren Formats for JSON Schema Validation",
|
|
11
21
|
"author": "joham",
|
|
12
22
|
"repository": {
|
|
13
23
|
"type": "git",
|
|
14
|
-
"url": "https://github.com/jklarenbeek/jarenjs.git",
|
|
24
|
+
"url": "git+https://github.com/jklarenbeek/jarenjs.git",
|
|
15
25
|
"directory": "packages/formats"
|
|
16
26
|
},
|
|
17
27
|
"license": "MIT",
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=22"
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public",
|
|
33
|
+
"registry": "https://registry.npmjs.org/"
|
|
34
|
+
},
|
|
18
35
|
"keywords": [
|
|
19
36
|
"jaren",
|
|
20
|
-
"json
|
|
37
|
+
"json-schema",
|
|
21
38
|
"formats"
|
|
22
39
|
],
|
|
23
40
|
"scripts": {
|
|
24
|
-
"build": "node esbuild.config.js"
|
|
41
|
+
"build": "node esbuild.config.js && npm run build:types",
|
|
42
|
+
"build:types": "tsc -p tsconfig.json",
|
|
43
|
+
"prepack": "npm run build:types"
|
|
25
44
|
},
|
|
26
|
-
"
|
|
27
|
-
"
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@jarenjs/core": "^0.9.2",
|
|
47
|
+
"@jarenjs/json": "^0.9.2"
|
|
28
48
|
}
|
|
29
49
|
}
|