@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,297 +0,0 @@
|
|
|
1
|
-
import { r as createRefinement, t as assert } from "./assert-CzMg5aO7.mjs";
|
|
2
|
-
import { isArray, isBigInt as isBigInt$1, isBlob as isBlob$1, isBoolean as isBoolean$1, isDate as isDate$1, isEmail as isEmail$1, isError as isError$1, isFile as isFile$1, isFiniteNumber as isFiniteNumber$1, isFunction as isFunction$1, isInteger as isInteger$1, isMap as isMap$1, isNaN as isNaN$1, isNull as isNull$1, isNumber as isNumber$1, isPromiseLike as isPromiseLike$1, isRegExp as isRegExp$1, isSafeInteger as isSafeInteger$1, isSet as isSet$1, isString as isString$1, isSymbol as isSymbol$1, isValidDate as isValidDate$1 } from "./predicates.mjs";
|
|
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__ */ assert(isBoolean$1, {
|
|
111
|
-
name: "isBoolean",
|
|
112
|
-
bail: true,
|
|
113
|
-
code: "type.boolean"
|
|
114
|
-
});
|
|
115
|
-
var isBigInt = /* @__PURE__ */ assert(isBigInt$1, {
|
|
116
|
-
name: "isBigInt",
|
|
117
|
-
bail: true,
|
|
118
|
-
code: "type.bigint"
|
|
119
|
-
});
|
|
120
|
-
var isBlob = /* @__PURE__ */ assert(isBlob$1, {
|
|
121
|
-
name: "isBlob",
|
|
122
|
-
bail: true,
|
|
123
|
-
code: "type.blob"
|
|
124
|
-
});
|
|
125
|
-
var isDate = /* @__PURE__ */ assert(isDate$1, {
|
|
126
|
-
name: "isDate",
|
|
127
|
-
bail: true,
|
|
128
|
-
code: "type.date"
|
|
129
|
-
});
|
|
130
|
-
var isDefined = /* @__PURE__ */ assert((value) => value !== void 0, {
|
|
131
|
-
name: "isDefined",
|
|
132
|
-
bail: true,
|
|
133
|
-
code: "value.defined"
|
|
134
|
-
});
|
|
135
|
-
var isEmail = /* @__PURE__ */ assert(isEmail$1, {
|
|
136
|
-
name: "isEmail",
|
|
137
|
-
bail: true,
|
|
138
|
-
code: "string.email"
|
|
139
|
-
});
|
|
140
|
-
var isError = /* @__PURE__ */ assert(isError$1, {
|
|
141
|
-
name: "isError",
|
|
142
|
-
bail: true,
|
|
143
|
-
code: "type.error"
|
|
144
|
-
});
|
|
145
|
-
var isFiniteNumber = /* @__PURE__ */ assert(isFiniteNumber$1, {
|
|
146
|
-
name: "isFiniteNumber",
|
|
147
|
-
bail: true,
|
|
148
|
-
code: "number.finite"
|
|
149
|
-
});
|
|
150
|
-
var isFile = /* @__PURE__ */ assert(isFile$1, {
|
|
151
|
-
name: "isFile",
|
|
152
|
-
bail: true,
|
|
153
|
-
code: "type.file"
|
|
154
|
-
});
|
|
155
|
-
var isFunction = /* @__PURE__ */ assert(isFunction$1, {
|
|
156
|
-
name: "isFunction",
|
|
157
|
-
bail: true,
|
|
158
|
-
code: "type.function"
|
|
159
|
-
});
|
|
160
|
-
var isInteger = /* @__PURE__ */ assert(isInteger$1, {
|
|
161
|
-
name: "isInteger",
|
|
162
|
-
bail: true,
|
|
163
|
-
code: "number.integer"
|
|
164
|
-
});
|
|
165
|
-
var isMap = /* @__PURE__ */ assert(isMap$1, {
|
|
166
|
-
name: "isMap",
|
|
167
|
-
bail: true,
|
|
168
|
-
code: "type.map"
|
|
169
|
-
});
|
|
170
|
-
var isNaN = /* @__PURE__ */ assert(isNaN$1, {
|
|
171
|
-
name: "isNaN",
|
|
172
|
-
bail: true,
|
|
173
|
-
code: "number.nan"
|
|
174
|
-
});
|
|
175
|
-
var isNull = /* @__PURE__ */ assert(isNull$1, {
|
|
176
|
-
name: "isNull",
|
|
177
|
-
bail: true,
|
|
178
|
-
code: "type.null"
|
|
179
|
-
});
|
|
180
|
-
var isNumber = /* @__PURE__ */ assert(isNumber$1, {
|
|
181
|
-
name: "isNumber",
|
|
182
|
-
bail: true,
|
|
183
|
-
code: "type.number"
|
|
184
|
-
});
|
|
185
|
-
var isPromiseLike = /* @__PURE__ */ assert(isPromiseLike$1, {
|
|
186
|
-
name: "isPromiseLike",
|
|
187
|
-
bail: true,
|
|
188
|
-
code: "type.promise-like"
|
|
189
|
-
});
|
|
190
|
-
var isRegExp = /* @__PURE__ */ assert(isRegExp$1, {
|
|
191
|
-
name: "isRegExp",
|
|
192
|
-
bail: true,
|
|
193
|
-
code: "type.regexp"
|
|
194
|
-
});
|
|
195
|
-
var isSafeInteger = /* @__PURE__ */ assert(isSafeInteger$1, {
|
|
196
|
-
name: "isSafeInteger",
|
|
197
|
-
bail: true,
|
|
198
|
-
code: "number.safe-integer"
|
|
199
|
-
});
|
|
200
|
-
var isSet = /* @__PURE__ */ assert(isSet$1, {
|
|
201
|
-
name: "isSet",
|
|
202
|
-
bail: true,
|
|
203
|
-
code: "type.set"
|
|
204
|
-
});
|
|
205
|
-
var isString = /* @__PURE__ */ assert(isString$1, {
|
|
206
|
-
name: "isString",
|
|
207
|
-
bail: true,
|
|
208
|
-
code: "type.string"
|
|
209
|
-
});
|
|
210
|
-
var isSymbol = /* @__PURE__ */ assert(isSymbol$1, {
|
|
211
|
-
name: "isSymbol",
|
|
212
|
-
bail: true,
|
|
213
|
-
code: "type.symbol"
|
|
214
|
-
});
|
|
215
|
-
var isValidDate = /* @__PURE__ */ assert(isValidDate$1, {
|
|
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__ */ 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__ */ createRefinement({
|
|
233
|
-
name: "hasSize",
|
|
234
|
-
bail,
|
|
235
|
-
code: "size.unsupported-type"
|
|
236
|
-
}, constraints);
|
|
237
|
-
};
|
|
238
|
-
var hasPattern = (pattern, { bail = false } = {}) => /* @__PURE__ */ 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__ */ 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__ */ 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__ */ createRefinement({
|
|
272
|
-
name: "hasValue",
|
|
273
|
-
bail,
|
|
274
|
-
code: "number.unsupported-type"
|
|
275
|
-
}, constraints);
|
|
276
|
-
};
|
|
277
|
-
var multipleOf = (step, { bail = false } = {}) => /* @__PURE__ */ 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 = isArray(values) ? values : Object.values(values);
|
|
289
|
-
return /* @__PURE__ */ 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
|
-
export { startsWith as A, isSafeInteger as C, isValidDate as D, isSymbol as E, multipleOf as O, isRegExp as S, isString as T, isMap as _, hasValue as a, isNumber as b, isBoolean as c, isEmail as d, isError as f, isInteger as g, isFunction as h, hasSize as i, oneOf as k, isDate as l, isFiniteNumber as m, hasLength as n, isBigInt as o, isFile as p, hasPattern as r, isBlob as s, endsWith as t, isDefined as u, isNaN as v, isSet as w, isPromiseLike as x, isNull as y };
|