@modulify/validator 0.3.0 → 0.3.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 +2 -0
- package/dist/assert.cjs +101 -7
- package/dist/assert.mjs +95 -1
- package/dist/assertions.cjs +309 -32
- package/dist/assertions.mjs +279 -2
- package/dist/checkers.cjs +23 -0
- package/dist/checkers.mjs +16 -0
- package/dist/combinators.cjs +24 -22
- package/dist/combinators.mjs +3 -1
- package/dist/constraints.cjs +23 -0
- package/dist/constraints.mjs +21 -0
- package/dist/extractors.cjs +6 -0
- package/dist/extractors.mjs +5 -0
- package/dist/index.cjs +14 -90
- package/dist/index.mjs +5 -81
- package/dist/json-schema.cjs +2 -2
- package/dist/json-schema.mjs +1 -1
- package/dist/metadata.cjs +98 -6
- package/dist/metadata.mjs +93 -1
- package/dist/violations.cjs +81 -0
- package/dist/violations.mjs +80 -0
- package/package.json +1 -1
- package/dist/assert-BDOtHdLx.cjs +0 -289
- package/dist/assert-CzMg5aO7.mjs +0 -206
- package/dist/assertions-DPYCHREw.mjs +0 -297
- package/dist/assertions-nfOKqcjs.cjs +0 -476
|
@@ -1,476 +0,0 @@
|
|
|
1
|
-
const require_assert = require("./assert-BDOtHdLx.cjs");
|
|
2
|
-
const require_predicates = require("./predicates.cjs");
|
|
3
|
-
//#region src/checkers.ts
|
|
4
|
-
var isEqual = (value, exact) => value === exact;
|
|
5
|
-
var isGte = (value, min) => value >= min;
|
|
6
|
-
var isLte = (value, max) => value <= max;
|
|
7
|
-
var inRange = (value, [min, max]) => value >= min && value <= max;
|
|
8
|
-
var startsWith$1 = (value, prefix) => value.startsWith(prefix);
|
|
9
|
-
var endsWith$1 = (value, suffix) => value.endsWith(suffix);
|
|
10
|
-
var matchesPattern = (value, pattern) => new RegExp(pattern.source, pattern.flags).test(value);
|
|
11
|
-
var isMultipleOf = (value, step) => {
|
|
12
|
-
if (step === 0) return false;
|
|
13
|
-
const quotient = value / step;
|
|
14
|
-
const delta = Math.abs(quotient - Math.round(quotient));
|
|
15
|
-
return Number.isFinite(quotient) && delta <= Number.EPSILON * Math.max(1, Math.abs(quotient)) * 16;
|
|
16
|
-
};
|
|
17
|
-
//#endregion
|
|
18
|
-
//#region src/extractors.ts
|
|
19
|
-
var length = (value) => value.length;
|
|
20
|
-
var size = (value) => value.size;
|
|
21
|
-
//#endregion
|
|
22
|
-
//#region src/assertions.ts
|
|
23
|
-
var buildLengthConstraints = (options) => {
|
|
24
|
-
const { exact = null, max = null, min = null, range = null } = options;
|
|
25
|
-
const constraints = [];
|
|
26
|
-
if (exact !== null) constraints.push([
|
|
27
|
-
length,
|
|
28
|
-
isEqual,
|
|
29
|
-
"length.exact",
|
|
30
|
-
exact
|
|
31
|
-
]);
|
|
32
|
-
if (max !== null) constraints.push([
|
|
33
|
-
length,
|
|
34
|
-
isLte,
|
|
35
|
-
"length.max",
|
|
36
|
-
max
|
|
37
|
-
]);
|
|
38
|
-
if (min !== null) constraints.push([
|
|
39
|
-
length,
|
|
40
|
-
isGte,
|
|
41
|
-
"length.min",
|
|
42
|
-
min
|
|
43
|
-
]);
|
|
44
|
-
if (range !== null) constraints.push([
|
|
45
|
-
length,
|
|
46
|
-
inRange,
|
|
47
|
-
"length.range",
|
|
48
|
-
range
|
|
49
|
-
]);
|
|
50
|
-
return constraints;
|
|
51
|
-
};
|
|
52
|
-
var buildSizeConstraints = (options) => {
|
|
53
|
-
const { exact = null, max = null, min = null, range = null } = options;
|
|
54
|
-
const constraints = [];
|
|
55
|
-
if (exact !== null) constraints.push([
|
|
56
|
-
size,
|
|
57
|
-
isEqual,
|
|
58
|
-
"size.exact",
|
|
59
|
-
exact
|
|
60
|
-
]);
|
|
61
|
-
if (max !== null) constraints.push([
|
|
62
|
-
size,
|
|
63
|
-
isLte,
|
|
64
|
-
"size.max",
|
|
65
|
-
max
|
|
66
|
-
]);
|
|
67
|
-
if (min !== null) constraints.push([
|
|
68
|
-
size,
|
|
69
|
-
isGte,
|
|
70
|
-
"size.min",
|
|
71
|
-
min
|
|
72
|
-
]);
|
|
73
|
-
if (range !== null) constraints.push([
|
|
74
|
-
size,
|
|
75
|
-
inRange,
|
|
76
|
-
"size.range",
|
|
77
|
-
range
|
|
78
|
-
]);
|
|
79
|
-
return constraints;
|
|
80
|
-
};
|
|
81
|
-
var buildValueConstraints = (options) => {
|
|
82
|
-
const { exact = null, max = null, min = null, range = null } = options;
|
|
83
|
-
const constraints = [];
|
|
84
|
-
if (exact !== null) constraints.push([
|
|
85
|
-
(value) => value,
|
|
86
|
-
isEqual,
|
|
87
|
-
"number.exact",
|
|
88
|
-
exact
|
|
89
|
-
]);
|
|
90
|
-
if (max !== null) constraints.push([
|
|
91
|
-
(value) => value,
|
|
92
|
-
isLte,
|
|
93
|
-
"number.max",
|
|
94
|
-
max
|
|
95
|
-
]);
|
|
96
|
-
if (min !== null) constraints.push([
|
|
97
|
-
(value) => value,
|
|
98
|
-
isGte,
|
|
99
|
-
"number.min",
|
|
100
|
-
min
|
|
101
|
-
]);
|
|
102
|
-
if (range !== null) constraints.push([
|
|
103
|
-
(value) => value,
|
|
104
|
-
inRange,
|
|
105
|
-
"number.range",
|
|
106
|
-
range
|
|
107
|
-
]);
|
|
108
|
-
return constraints;
|
|
109
|
-
};
|
|
110
|
-
var isBoolean = /* @__PURE__ */ require_assert.assert(require_predicates.isBoolean, {
|
|
111
|
-
name: "isBoolean",
|
|
112
|
-
bail: true,
|
|
113
|
-
code: "type.boolean"
|
|
114
|
-
});
|
|
115
|
-
var isBigInt = /* @__PURE__ */ require_assert.assert(require_predicates.isBigInt, {
|
|
116
|
-
name: "isBigInt",
|
|
117
|
-
bail: true,
|
|
118
|
-
code: "type.bigint"
|
|
119
|
-
});
|
|
120
|
-
var isBlob = /* @__PURE__ */ require_assert.assert(require_predicates.isBlob, {
|
|
121
|
-
name: "isBlob",
|
|
122
|
-
bail: true,
|
|
123
|
-
code: "type.blob"
|
|
124
|
-
});
|
|
125
|
-
var isDate = /* @__PURE__ */ require_assert.assert(require_predicates.isDate, {
|
|
126
|
-
name: "isDate",
|
|
127
|
-
bail: true,
|
|
128
|
-
code: "type.date"
|
|
129
|
-
});
|
|
130
|
-
var isDefined = /* @__PURE__ */ require_assert.assert((value) => value !== void 0, {
|
|
131
|
-
name: "isDefined",
|
|
132
|
-
bail: true,
|
|
133
|
-
code: "value.defined"
|
|
134
|
-
});
|
|
135
|
-
var isEmail = /* @__PURE__ */ require_assert.assert(require_predicates.isEmail, {
|
|
136
|
-
name: "isEmail",
|
|
137
|
-
bail: true,
|
|
138
|
-
code: "string.email"
|
|
139
|
-
});
|
|
140
|
-
var isError = /* @__PURE__ */ require_assert.assert(require_predicates.isError, {
|
|
141
|
-
name: "isError",
|
|
142
|
-
bail: true,
|
|
143
|
-
code: "type.error"
|
|
144
|
-
});
|
|
145
|
-
var isFiniteNumber = /* @__PURE__ */ require_assert.assert(require_predicates.isFiniteNumber, {
|
|
146
|
-
name: "isFiniteNumber",
|
|
147
|
-
bail: true,
|
|
148
|
-
code: "number.finite"
|
|
149
|
-
});
|
|
150
|
-
var isFile = /* @__PURE__ */ require_assert.assert(require_predicates.isFile, {
|
|
151
|
-
name: "isFile",
|
|
152
|
-
bail: true,
|
|
153
|
-
code: "type.file"
|
|
154
|
-
});
|
|
155
|
-
var isFunction = /* @__PURE__ */ require_assert.assert(require_predicates.isFunction, {
|
|
156
|
-
name: "isFunction",
|
|
157
|
-
bail: true,
|
|
158
|
-
code: "type.function"
|
|
159
|
-
});
|
|
160
|
-
var isInteger = /* @__PURE__ */ require_assert.assert(require_predicates.isInteger, {
|
|
161
|
-
name: "isInteger",
|
|
162
|
-
bail: true,
|
|
163
|
-
code: "number.integer"
|
|
164
|
-
});
|
|
165
|
-
var isMap = /* @__PURE__ */ require_assert.assert(require_predicates.isMap, {
|
|
166
|
-
name: "isMap",
|
|
167
|
-
bail: true,
|
|
168
|
-
code: "type.map"
|
|
169
|
-
});
|
|
170
|
-
var isNaN = /* @__PURE__ */ require_assert.assert(require_predicates.isNaN, {
|
|
171
|
-
name: "isNaN",
|
|
172
|
-
bail: true,
|
|
173
|
-
code: "number.nan"
|
|
174
|
-
});
|
|
175
|
-
var isNull = /* @__PURE__ */ require_assert.assert(require_predicates.isNull, {
|
|
176
|
-
name: "isNull",
|
|
177
|
-
bail: true,
|
|
178
|
-
code: "type.null"
|
|
179
|
-
});
|
|
180
|
-
var isNumber = /* @__PURE__ */ require_assert.assert(require_predicates.isNumber, {
|
|
181
|
-
name: "isNumber",
|
|
182
|
-
bail: true,
|
|
183
|
-
code: "type.number"
|
|
184
|
-
});
|
|
185
|
-
var isPromiseLike = /* @__PURE__ */ require_assert.assert(require_predicates.isPromiseLike, {
|
|
186
|
-
name: "isPromiseLike",
|
|
187
|
-
bail: true,
|
|
188
|
-
code: "type.promise-like"
|
|
189
|
-
});
|
|
190
|
-
var isRegExp = /* @__PURE__ */ require_assert.assert(require_predicates.isRegExp, {
|
|
191
|
-
name: "isRegExp",
|
|
192
|
-
bail: true,
|
|
193
|
-
code: "type.regexp"
|
|
194
|
-
});
|
|
195
|
-
var isSafeInteger = /* @__PURE__ */ require_assert.assert(require_predicates.isSafeInteger, {
|
|
196
|
-
name: "isSafeInteger",
|
|
197
|
-
bail: true,
|
|
198
|
-
code: "number.safe-integer"
|
|
199
|
-
});
|
|
200
|
-
var isSet = /* @__PURE__ */ require_assert.assert(require_predicates.isSet, {
|
|
201
|
-
name: "isSet",
|
|
202
|
-
bail: true,
|
|
203
|
-
code: "type.set"
|
|
204
|
-
});
|
|
205
|
-
var isString = /* @__PURE__ */ require_assert.assert(require_predicates.isString, {
|
|
206
|
-
name: "isString",
|
|
207
|
-
bail: true,
|
|
208
|
-
code: "type.string"
|
|
209
|
-
});
|
|
210
|
-
var isSymbol = /* @__PURE__ */ require_assert.assert(require_predicates.isSymbol, {
|
|
211
|
-
name: "isSymbol",
|
|
212
|
-
bail: true,
|
|
213
|
-
code: "type.symbol"
|
|
214
|
-
});
|
|
215
|
-
var isValidDate = /* @__PURE__ */ require_assert.assert(require_predicates.isValidDate, {
|
|
216
|
-
name: "isValidDate",
|
|
217
|
-
bail: true,
|
|
218
|
-
code: "date.valid"
|
|
219
|
-
});
|
|
220
|
-
var hasLength = (options = {}) => {
|
|
221
|
-
const { bail = false } = options;
|
|
222
|
-
const constraints = buildLengthConstraints(options);
|
|
223
|
-
return /* @__PURE__ */ require_assert.createRefinement({
|
|
224
|
-
name: "hasLength",
|
|
225
|
-
bail,
|
|
226
|
-
code: "length.unsupported-type"
|
|
227
|
-
}, constraints);
|
|
228
|
-
};
|
|
229
|
-
var hasSize = (options = {}) => {
|
|
230
|
-
const { bail = false } = options;
|
|
231
|
-
const constraints = buildSizeConstraints(options);
|
|
232
|
-
return /* @__PURE__ */ require_assert.createRefinement({
|
|
233
|
-
name: "hasSize",
|
|
234
|
-
bail,
|
|
235
|
-
code: "size.unsupported-type"
|
|
236
|
-
}, constraints);
|
|
237
|
-
};
|
|
238
|
-
var hasPattern = (pattern, { bail = false } = {}) => /* @__PURE__ */ require_assert.createRefinement({
|
|
239
|
-
name: "hasPattern",
|
|
240
|
-
bail,
|
|
241
|
-
code: "string.unsupported-type"
|
|
242
|
-
}, [[
|
|
243
|
-
(value) => value,
|
|
244
|
-
matchesPattern,
|
|
245
|
-
"string.pattern",
|
|
246
|
-
pattern
|
|
247
|
-
]]);
|
|
248
|
-
var startsWith = (prefix, { bail = false } = {}) => /* @__PURE__ */ require_assert.createRefinement({
|
|
249
|
-
name: "startsWith",
|
|
250
|
-
bail,
|
|
251
|
-
code: "string.unsupported-type"
|
|
252
|
-
}, [[
|
|
253
|
-
(value) => value,
|
|
254
|
-
startsWith$1,
|
|
255
|
-
"string.starts-with",
|
|
256
|
-
prefix
|
|
257
|
-
]]);
|
|
258
|
-
var endsWith = (suffix, { bail = false } = {}) => /* @__PURE__ */ require_assert.createRefinement({
|
|
259
|
-
name: "endsWith",
|
|
260
|
-
bail,
|
|
261
|
-
code: "string.unsupported-type"
|
|
262
|
-
}, [[
|
|
263
|
-
(value) => value,
|
|
264
|
-
endsWith$1,
|
|
265
|
-
"string.ends-with",
|
|
266
|
-
suffix
|
|
267
|
-
]]);
|
|
268
|
-
var hasValue = (options = {}) => {
|
|
269
|
-
const { bail = false } = options;
|
|
270
|
-
const constraints = buildValueConstraints(options);
|
|
271
|
-
return /* @__PURE__ */ require_assert.createRefinement({
|
|
272
|
-
name: "hasValue",
|
|
273
|
-
bail,
|
|
274
|
-
code: "number.unsupported-type"
|
|
275
|
-
}, constraints);
|
|
276
|
-
};
|
|
277
|
-
var multipleOf = (step, { bail = false } = {}) => /* @__PURE__ */ require_assert.createRefinement({
|
|
278
|
-
name: "multipleOf",
|
|
279
|
-
bail,
|
|
280
|
-
code: "number.unsupported-type"
|
|
281
|
-
}, [[
|
|
282
|
-
(value) => value,
|
|
283
|
-
isMultipleOf,
|
|
284
|
-
"number.multiple-of",
|
|
285
|
-
step
|
|
286
|
-
]]);
|
|
287
|
-
var oneOf = (values, { equalTo = (a, b) => a === b, bail = false } = {}) => {
|
|
288
|
-
const haystack = require_predicates.isArray(values) ? values : Object.values(values);
|
|
289
|
-
return /* @__PURE__ */ require_assert.assert((value) => haystack.some((item) => equalTo(item, value)), {
|
|
290
|
-
name: "oneOf",
|
|
291
|
-
bail,
|
|
292
|
-
code: "value.one-of",
|
|
293
|
-
args: [haystack]
|
|
294
|
-
});
|
|
295
|
-
};
|
|
296
|
-
//#endregion
|
|
297
|
-
Object.defineProperty(exports, "endsWith", {
|
|
298
|
-
enumerable: true,
|
|
299
|
-
get: function() {
|
|
300
|
-
return endsWith;
|
|
301
|
-
}
|
|
302
|
-
});
|
|
303
|
-
Object.defineProperty(exports, "hasLength", {
|
|
304
|
-
enumerable: true,
|
|
305
|
-
get: function() {
|
|
306
|
-
return hasLength;
|
|
307
|
-
}
|
|
308
|
-
});
|
|
309
|
-
Object.defineProperty(exports, "hasPattern", {
|
|
310
|
-
enumerable: true,
|
|
311
|
-
get: function() {
|
|
312
|
-
return hasPattern;
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
Object.defineProperty(exports, "hasSize", {
|
|
316
|
-
enumerable: true,
|
|
317
|
-
get: function() {
|
|
318
|
-
return hasSize;
|
|
319
|
-
}
|
|
320
|
-
});
|
|
321
|
-
Object.defineProperty(exports, "hasValue", {
|
|
322
|
-
enumerable: true,
|
|
323
|
-
get: function() {
|
|
324
|
-
return hasValue;
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
Object.defineProperty(exports, "isBigInt", {
|
|
328
|
-
enumerable: true,
|
|
329
|
-
get: function() {
|
|
330
|
-
return isBigInt;
|
|
331
|
-
}
|
|
332
|
-
});
|
|
333
|
-
Object.defineProperty(exports, "isBlob", {
|
|
334
|
-
enumerable: true,
|
|
335
|
-
get: function() {
|
|
336
|
-
return isBlob;
|
|
337
|
-
}
|
|
338
|
-
});
|
|
339
|
-
Object.defineProperty(exports, "isBoolean", {
|
|
340
|
-
enumerable: true,
|
|
341
|
-
get: function() {
|
|
342
|
-
return isBoolean;
|
|
343
|
-
}
|
|
344
|
-
});
|
|
345
|
-
Object.defineProperty(exports, "isDate", {
|
|
346
|
-
enumerable: true,
|
|
347
|
-
get: function() {
|
|
348
|
-
return isDate;
|
|
349
|
-
}
|
|
350
|
-
});
|
|
351
|
-
Object.defineProperty(exports, "isDefined", {
|
|
352
|
-
enumerable: true,
|
|
353
|
-
get: function() {
|
|
354
|
-
return isDefined;
|
|
355
|
-
}
|
|
356
|
-
});
|
|
357
|
-
Object.defineProperty(exports, "isEmail", {
|
|
358
|
-
enumerable: true,
|
|
359
|
-
get: function() {
|
|
360
|
-
return isEmail;
|
|
361
|
-
}
|
|
362
|
-
});
|
|
363
|
-
Object.defineProperty(exports, "isError", {
|
|
364
|
-
enumerable: true,
|
|
365
|
-
get: function() {
|
|
366
|
-
return isError;
|
|
367
|
-
}
|
|
368
|
-
});
|
|
369
|
-
Object.defineProperty(exports, "isFile", {
|
|
370
|
-
enumerable: true,
|
|
371
|
-
get: function() {
|
|
372
|
-
return isFile;
|
|
373
|
-
}
|
|
374
|
-
});
|
|
375
|
-
Object.defineProperty(exports, "isFiniteNumber", {
|
|
376
|
-
enumerable: true,
|
|
377
|
-
get: function() {
|
|
378
|
-
return isFiniteNumber;
|
|
379
|
-
}
|
|
380
|
-
});
|
|
381
|
-
Object.defineProperty(exports, "isFunction", {
|
|
382
|
-
enumerable: true,
|
|
383
|
-
get: function() {
|
|
384
|
-
return isFunction;
|
|
385
|
-
}
|
|
386
|
-
});
|
|
387
|
-
Object.defineProperty(exports, "isInteger", {
|
|
388
|
-
enumerable: true,
|
|
389
|
-
get: function() {
|
|
390
|
-
return isInteger;
|
|
391
|
-
}
|
|
392
|
-
});
|
|
393
|
-
Object.defineProperty(exports, "isMap", {
|
|
394
|
-
enumerable: true,
|
|
395
|
-
get: function() {
|
|
396
|
-
return isMap;
|
|
397
|
-
}
|
|
398
|
-
});
|
|
399
|
-
Object.defineProperty(exports, "isNaN", {
|
|
400
|
-
enumerable: true,
|
|
401
|
-
get: function() {
|
|
402
|
-
return isNaN;
|
|
403
|
-
}
|
|
404
|
-
});
|
|
405
|
-
Object.defineProperty(exports, "isNull", {
|
|
406
|
-
enumerable: true,
|
|
407
|
-
get: function() {
|
|
408
|
-
return isNull;
|
|
409
|
-
}
|
|
410
|
-
});
|
|
411
|
-
Object.defineProperty(exports, "isNumber", {
|
|
412
|
-
enumerable: true,
|
|
413
|
-
get: function() {
|
|
414
|
-
return isNumber;
|
|
415
|
-
}
|
|
416
|
-
});
|
|
417
|
-
Object.defineProperty(exports, "isPromiseLike", {
|
|
418
|
-
enumerable: true,
|
|
419
|
-
get: function() {
|
|
420
|
-
return isPromiseLike;
|
|
421
|
-
}
|
|
422
|
-
});
|
|
423
|
-
Object.defineProperty(exports, "isRegExp", {
|
|
424
|
-
enumerable: true,
|
|
425
|
-
get: function() {
|
|
426
|
-
return isRegExp;
|
|
427
|
-
}
|
|
428
|
-
});
|
|
429
|
-
Object.defineProperty(exports, "isSafeInteger", {
|
|
430
|
-
enumerable: true,
|
|
431
|
-
get: function() {
|
|
432
|
-
return isSafeInteger;
|
|
433
|
-
}
|
|
434
|
-
});
|
|
435
|
-
Object.defineProperty(exports, "isSet", {
|
|
436
|
-
enumerable: true,
|
|
437
|
-
get: function() {
|
|
438
|
-
return isSet;
|
|
439
|
-
}
|
|
440
|
-
});
|
|
441
|
-
Object.defineProperty(exports, "isString", {
|
|
442
|
-
enumerable: true,
|
|
443
|
-
get: function() {
|
|
444
|
-
return isString;
|
|
445
|
-
}
|
|
446
|
-
});
|
|
447
|
-
Object.defineProperty(exports, "isSymbol", {
|
|
448
|
-
enumerable: true,
|
|
449
|
-
get: function() {
|
|
450
|
-
return isSymbol;
|
|
451
|
-
}
|
|
452
|
-
});
|
|
453
|
-
Object.defineProperty(exports, "isValidDate", {
|
|
454
|
-
enumerable: true,
|
|
455
|
-
get: function() {
|
|
456
|
-
return isValidDate;
|
|
457
|
-
}
|
|
458
|
-
});
|
|
459
|
-
Object.defineProperty(exports, "multipleOf", {
|
|
460
|
-
enumerable: true,
|
|
461
|
-
get: function() {
|
|
462
|
-
return multipleOf;
|
|
463
|
-
}
|
|
464
|
-
});
|
|
465
|
-
Object.defineProperty(exports, "oneOf", {
|
|
466
|
-
enumerable: true,
|
|
467
|
-
get: function() {
|
|
468
|
-
return oneOf;
|
|
469
|
-
}
|
|
470
|
-
});
|
|
471
|
-
Object.defineProperty(exports, "startsWith", {
|
|
472
|
-
enumerable: true,
|
|
473
|
-
get: function() {
|
|
474
|
-
return startsWith;
|
|
475
|
-
}
|
|
476
|
-
});
|