quival 0.2.5 → 0.2.6
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/README.md +1 -1
- package/dist/locales/en.js +1 -1
- package/dist/locales/en.min.js +1 -1
- package/dist/locales/ms.js +1 -1
- package/dist/locales/ms.min.js +1 -1
- package/dist/quival.js +1269 -2769
- package/dist/quival.min.js +2 -2
- package/package.json +4 -2
- package/rollup.config.js +1 -1
- package/src/Validator.js +25 -17
- package/src/helpers.js +38 -2
- package/test/test.js +173 -0
package/dist/quival.js
CHANGED
|
@@ -1,613 +1,36 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* quival v0.2.
|
|
2
|
+
* quival v0.2.6 (https://github.com/apih/quival)
|
|
3
3
|
* (c) 2023 Mohd Hafizuddin M Marzuki <hafizuddin_83@yahoo.com>
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
var quival = (function (exports) {
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
-
function _iterableToArrayLimit(arr, i) {
|
|
10
|
-
var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
|
|
11
|
-
if (null != _i) {
|
|
12
|
-
var _s,
|
|
13
|
-
_e,
|
|
14
|
-
_x,
|
|
15
|
-
_r,
|
|
16
|
-
_arr = [],
|
|
17
|
-
_n = !0,
|
|
18
|
-
_d = !1;
|
|
19
|
-
try {
|
|
20
|
-
if (_x = (_i = _i.call(arr)).next, 0 === i) {
|
|
21
|
-
if (Object(_i) !== _i) return;
|
|
22
|
-
_n = !1;
|
|
23
|
-
} else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
|
|
24
|
-
} catch (err) {
|
|
25
|
-
_d = !0, _e = err;
|
|
26
|
-
} finally {
|
|
27
|
-
try {
|
|
28
|
-
if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return;
|
|
29
|
-
} finally {
|
|
30
|
-
if (_d) throw _e;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return _arr;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
function _regeneratorRuntime() {
|
|
37
|
-
_regeneratorRuntime = function () {
|
|
38
|
-
return exports;
|
|
39
|
-
};
|
|
40
|
-
var exports = {},
|
|
41
|
-
Op = Object.prototype,
|
|
42
|
-
hasOwn = Op.hasOwnProperty,
|
|
43
|
-
defineProperty = Object.defineProperty || function (obj, key, desc) {
|
|
44
|
-
obj[key] = desc.value;
|
|
45
|
-
},
|
|
46
|
-
$Symbol = "function" == typeof Symbol ? Symbol : {},
|
|
47
|
-
iteratorSymbol = $Symbol.iterator || "@@iterator",
|
|
48
|
-
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
|
|
49
|
-
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
|
|
50
|
-
function define(obj, key, value) {
|
|
51
|
-
return Object.defineProperty(obj, key, {
|
|
52
|
-
value: value,
|
|
53
|
-
enumerable: !0,
|
|
54
|
-
configurable: !0,
|
|
55
|
-
writable: !0
|
|
56
|
-
}), obj[key];
|
|
57
|
-
}
|
|
58
|
-
try {
|
|
59
|
-
define({}, "");
|
|
60
|
-
} catch (err) {
|
|
61
|
-
define = function (obj, key, value) {
|
|
62
|
-
return obj[key] = value;
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
function wrap(innerFn, outerFn, self, tryLocsList) {
|
|
66
|
-
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
|
|
67
|
-
generator = Object.create(protoGenerator.prototype),
|
|
68
|
-
context = new Context(tryLocsList || []);
|
|
69
|
-
return defineProperty(generator, "_invoke", {
|
|
70
|
-
value: makeInvokeMethod(innerFn, self, context)
|
|
71
|
-
}), generator;
|
|
72
|
-
}
|
|
73
|
-
function tryCatch(fn, obj, arg) {
|
|
74
|
-
try {
|
|
75
|
-
return {
|
|
76
|
-
type: "normal",
|
|
77
|
-
arg: fn.call(obj, arg)
|
|
78
|
-
};
|
|
79
|
-
} catch (err) {
|
|
80
|
-
return {
|
|
81
|
-
type: "throw",
|
|
82
|
-
arg: err
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
exports.wrap = wrap;
|
|
87
|
-
var ContinueSentinel = {};
|
|
88
|
-
function Generator() {}
|
|
89
|
-
function GeneratorFunction() {}
|
|
90
|
-
function GeneratorFunctionPrototype() {}
|
|
91
|
-
var IteratorPrototype = {};
|
|
92
|
-
define(IteratorPrototype, iteratorSymbol, function () {
|
|
93
|
-
return this;
|
|
94
|
-
});
|
|
95
|
-
var getProto = Object.getPrototypeOf,
|
|
96
|
-
NativeIteratorPrototype = getProto && getProto(getProto(values([])));
|
|
97
|
-
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
|
|
98
|
-
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
|
|
99
|
-
function defineIteratorMethods(prototype) {
|
|
100
|
-
["next", "throw", "return"].forEach(function (method) {
|
|
101
|
-
define(prototype, method, function (arg) {
|
|
102
|
-
return this._invoke(method, arg);
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
function AsyncIterator(generator, PromiseImpl) {
|
|
107
|
-
function invoke(method, arg, resolve, reject) {
|
|
108
|
-
var record = tryCatch(generator[method], generator, arg);
|
|
109
|
-
if ("throw" !== record.type) {
|
|
110
|
-
var result = record.arg,
|
|
111
|
-
value = result.value;
|
|
112
|
-
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
|
|
113
|
-
invoke("next", value, resolve, reject);
|
|
114
|
-
}, function (err) {
|
|
115
|
-
invoke("throw", err, resolve, reject);
|
|
116
|
-
}) : PromiseImpl.resolve(value).then(function (unwrapped) {
|
|
117
|
-
result.value = unwrapped, resolve(result);
|
|
118
|
-
}, function (error) {
|
|
119
|
-
return invoke("throw", error, resolve, reject);
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
reject(record.arg);
|
|
123
|
-
}
|
|
124
|
-
var previousPromise;
|
|
125
|
-
defineProperty(this, "_invoke", {
|
|
126
|
-
value: function (method, arg) {
|
|
127
|
-
function callInvokeWithMethodAndArg() {
|
|
128
|
-
return new PromiseImpl(function (resolve, reject) {
|
|
129
|
-
invoke(method, arg, resolve, reject);
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
function makeInvokeMethod(innerFn, self, context) {
|
|
137
|
-
var state = "suspendedStart";
|
|
138
|
-
return function (method, arg) {
|
|
139
|
-
if ("executing" === state) throw new Error("Generator is already running");
|
|
140
|
-
if ("completed" === state) {
|
|
141
|
-
if ("throw" === method) throw arg;
|
|
142
|
-
return doneResult();
|
|
143
|
-
}
|
|
144
|
-
for (context.method = method, context.arg = arg;;) {
|
|
145
|
-
var delegate = context.delegate;
|
|
146
|
-
if (delegate) {
|
|
147
|
-
var delegateResult = maybeInvokeDelegate(delegate, context);
|
|
148
|
-
if (delegateResult) {
|
|
149
|
-
if (delegateResult === ContinueSentinel) continue;
|
|
150
|
-
return delegateResult;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
|
|
154
|
-
if ("suspendedStart" === state) throw state = "completed", context.arg;
|
|
155
|
-
context.dispatchException(context.arg);
|
|
156
|
-
} else "return" === context.method && context.abrupt("return", context.arg);
|
|
157
|
-
state = "executing";
|
|
158
|
-
var record = tryCatch(innerFn, self, context);
|
|
159
|
-
if ("normal" === record.type) {
|
|
160
|
-
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
|
|
161
|
-
return {
|
|
162
|
-
value: record.arg,
|
|
163
|
-
done: context.done
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
function maybeInvokeDelegate(delegate, context) {
|
|
171
|
-
var methodName = context.method,
|
|
172
|
-
method = delegate.iterator[methodName];
|
|
173
|
-
if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
|
|
174
|
-
var record = tryCatch(method, delegate.iterator, context.arg);
|
|
175
|
-
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
|
|
176
|
-
var info = record.arg;
|
|
177
|
-
return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
|
|
178
|
-
}
|
|
179
|
-
function pushTryEntry(locs) {
|
|
180
|
-
var entry = {
|
|
181
|
-
tryLoc: locs[0]
|
|
182
|
-
};
|
|
183
|
-
1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
|
|
184
|
-
}
|
|
185
|
-
function resetTryEntry(entry) {
|
|
186
|
-
var record = entry.completion || {};
|
|
187
|
-
record.type = "normal", delete record.arg, entry.completion = record;
|
|
188
|
-
}
|
|
189
|
-
function Context(tryLocsList) {
|
|
190
|
-
this.tryEntries = [{
|
|
191
|
-
tryLoc: "root"
|
|
192
|
-
}], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
|
|
193
|
-
}
|
|
194
|
-
function values(iterable) {
|
|
195
|
-
if (iterable) {
|
|
196
|
-
var iteratorMethod = iterable[iteratorSymbol];
|
|
197
|
-
if (iteratorMethod) return iteratorMethod.call(iterable);
|
|
198
|
-
if ("function" == typeof iterable.next) return iterable;
|
|
199
|
-
if (!isNaN(iterable.length)) {
|
|
200
|
-
var i = -1,
|
|
201
|
-
next = function next() {
|
|
202
|
-
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
|
|
203
|
-
return next.value = undefined, next.done = !0, next;
|
|
204
|
-
};
|
|
205
|
-
return next.next = next;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
return {
|
|
209
|
-
next: doneResult
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
function doneResult() {
|
|
213
|
-
return {
|
|
214
|
-
value: undefined,
|
|
215
|
-
done: !0
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
|
|
219
|
-
value: GeneratorFunctionPrototype,
|
|
220
|
-
configurable: !0
|
|
221
|
-
}), defineProperty(GeneratorFunctionPrototype, "constructor", {
|
|
222
|
-
value: GeneratorFunction,
|
|
223
|
-
configurable: !0
|
|
224
|
-
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
|
|
225
|
-
var ctor = "function" == typeof genFun && genFun.constructor;
|
|
226
|
-
return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
|
|
227
|
-
}, exports.mark = function (genFun) {
|
|
228
|
-
return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
|
|
229
|
-
}, exports.awrap = function (arg) {
|
|
230
|
-
return {
|
|
231
|
-
__await: arg
|
|
232
|
-
};
|
|
233
|
-
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
|
|
234
|
-
return this;
|
|
235
|
-
}), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
|
|
236
|
-
void 0 === PromiseImpl && (PromiseImpl = Promise);
|
|
237
|
-
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
|
|
238
|
-
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
|
|
239
|
-
return result.done ? result.value : iter.next();
|
|
240
|
-
});
|
|
241
|
-
}, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
|
|
242
|
-
return this;
|
|
243
|
-
}), define(Gp, "toString", function () {
|
|
244
|
-
return "[object Generator]";
|
|
245
|
-
}), exports.keys = function (val) {
|
|
246
|
-
var object = Object(val),
|
|
247
|
-
keys = [];
|
|
248
|
-
for (var key in object) keys.push(key);
|
|
249
|
-
return keys.reverse(), function next() {
|
|
250
|
-
for (; keys.length;) {
|
|
251
|
-
var key = keys.pop();
|
|
252
|
-
if (key in object) return next.value = key, next.done = !1, next;
|
|
253
|
-
}
|
|
254
|
-
return next.done = !0, next;
|
|
255
|
-
};
|
|
256
|
-
}, exports.values = values, Context.prototype = {
|
|
257
|
-
constructor: Context,
|
|
258
|
-
reset: function (skipTempReset) {
|
|
259
|
-
if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
|
|
260
|
-
},
|
|
261
|
-
stop: function () {
|
|
262
|
-
this.done = !0;
|
|
263
|
-
var rootRecord = this.tryEntries[0].completion;
|
|
264
|
-
if ("throw" === rootRecord.type) throw rootRecord.arg;
|
|
265
|
-
return this.rval;
|
|
266
|
-
},
|
|
267
|
-
dispatchException: function (exception) {
|
|
268
|
-
if (this.done) throw exception;
|
|
269
|
-
var context = this;
|
|
270
|
-
function handle(loc, caught) {
|
|
271
|
-
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
|
|
272
|
-
}
|
|
273
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
274
|
-
var entry = this.tryEntries[i],
|
|
275
|
-
record = entry.completion;
|
|
276
|
-
if ("root" === entry.tryLoc) return handle("end");
|
|
277
|
-
if (entry.tryLoc <= this.prev) {
|
|
278
|
-
var hasCatch = hasOwn.call(entry, "catchLoc"),
|
|
279
|
-
hasFinally = hasOwn.call(entry, "finallyLoc");
|
|
280
|
-
if (hasCatch && hasFinally) {
|
|
281
|
-
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
|
|
282
|
-
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
|
|
283
|
-
} else if (hasCatch) {
|
|
284
|
-
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
|
|
285
|
-
} else {
|
|
286
|
-
if (!hasFinally) throw new Error("try statement without catch or finally");
|
|
287
|
-
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
},
|
|
292
|
-
abrupt: function (type, arg) {
|
|
293
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
294
|
-
var entry = this.tryEntries[i];
|
|
295
|
-
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
|
|
296
|
-
var finallyEntry = entry;
|
|
297
|
-
break;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
|
|
301
|
-
var record = finallyEntry ? finallyEntry.completion : {};
|
|
302
|
-
return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
|
|
303
|
-
},
|
|
304
|
-
complete: function (record, afterLoc) {
|
|
305
|
-
if ("throw" === record.type) throw record.arg;
|
|
306
|
-
return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
|
|
307
|
-
},
|
|
308
|
-
finish: function (finallyLoc) {
|
|
309
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
310
|
-
var entry = this.tryEntries[i];
|
|
311
|
-
if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
|
|
312
|
-
}
|
|
313
|
-
},
|
|
314
|
-
catch: function (tryLoc) {
|
|
315
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
316
|
-
var entry = this.tryEntries[i];
|
|
317
|
-
if (entry.tryLoc === tryLoc) {
|
|
318
|
-
var record = entry.completion;
|
|
319
|
-
if ("throw" === record.type) {
|
|
320
|
-
var thrown = record.arg;
|
|
321
|
-
resetTryEntry(entry);
|
|
322
|
-
}
|
|
323
|
-
return thrown;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
throw new Error("illegal catch attempt");
|
|
327
|
-
},
|
|
328
|
-
delegateYield: function (iterable, resultName, nextLoc) {
|
|
329
|
-
return this.delegate = {
|
|
330
|
-
iterator: values(iterable),
|
|
331
|
-
resultName: resultName,
|
|
332
|
-
nextLoc: nextLoc
|
|
333
|
-
}, "next" === this.method && (this.arg = undefined), ContinueSentinel;
|
|
334
|
-
}
|
|
335
|
-
}, exports;
|
|
336
|
-
}
|
|
337
|
-
function _typeof(obj) {
|
|
338
|
-
"@babel/helpers - typeof";
|
|
339
|
-
|
|
340
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
341
|
-
return typeof obj;
|
|
342
|
-
} : function (obj) {
|
|
343
|
-
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
344
|
-
}, _typeof(obj);
|
|
345
|
-
}
|
|
346
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
347
|
-
try {
|
|
348
|
-
var info = gen[key](arg);
|
|
349
|
-
var value = info.value;
|
|
350
|
-
} catch (error) {
|
|
351
|
-
reject(error);
|
|
352
|
-
return;
|
|
353
|
-
}
|
|
354
|
-
if (info.done) {
|
|
355
|
-
resolve(value);
|
|
356
|
-
} else {
|
|
357
|
-
Promise.resolve(value).then(_next, _throw);
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
function _asyncToGenerator(fn) {
|
|
361
|
-
return function () {
|
|
362
|
-
var self = this,
|
|
363
|
-
args = arguments;
|
|
364
|
-
return new Promise(function (resolve, reject) {
|
|
365
|
-
var gen = fn.apply(self, args);
|
|
366
|
-
function _next(value) {
|
|
367
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
368
|
-
}
|
|
369
|
-
function _throw(err) {
|
|
370
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
371
|
-
}
|
|
372
|
-
_next(undefined);
|
|
373
|
-
});
|
|
374
|
-
};
|
|
375
|
-
}
|
|
376
|
-
function _classCallCheck(instance, Constructor) {
|
|
377
|
-
if (!(instance instanceof Constructor)) {
|
|
378
|
-
throw new TypeError("Cannot call a class as a function");
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
function _defineProperties(target, props) {
|
|
382
|
-
for (var i = 0; i < props.length; i++) {
|
|
383
|
-
var descriptor = props[i];
|
|
384
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
385
|
-
descriptor.configurable = true;
|
|
386
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
387
|
-
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
function _createClass(Constructor, protoProps, staticProps) {
|
|
391
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
392
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
393
|
-
Object.defineProperty(Constructor, "prototype", {
|
|
394
|
-
writable: false
|
|
395
|
-
});
|
|
396
|
-
return Constructor;
|
|
397
|
-
}
|
|
398
|
-
function _defineProperty(obj, key, value) {
|
|
399
|
-
key = _toPropertyKey(key);
|
|
400
|
-
if (key in obj) {
|
|
401
|
-
Object.defineProperty(obj, key, {
|
|
402
|
-
value: value,
|
|
403
|
-
enumerable: true,
|
|
404
|
-
configurable: true,
|
|
405
|
-
writable: true
|
|
406
|
-
});
|
|
407
|
-
} else {
|
|
408
|
-
obj[key] = value;
|
|
409
|
-
}
|
|
410
|
-
return obj;
|
|
411
|
-
}
|
|
412
|
-
function _slicedToArray(arr, i) {
|
|
413
|
-
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
414
|
-
}
|
|
415
|
-
function _toConsumableArray(arr) {
|
|
416
|
-
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
417
|
-
}
|
|
418
|
-
function _arrayWithoutHoles(arr) {
|
|
419
|
-
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
420
|
-
}
|
|
421
|
-
function _arrayWithHoles(arr) {
|
|
422
|
-
if (Array.isArray(arr)) return arr;
|
|
423
|
-
}
|
|
424
|
-
function _iterableToArray(iter) {
|
|
425
|
-
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
426
|
-
}
|
|
427
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
428
|
-
if (!o) return;
|
|
429
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
430
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
431
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
432
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
433
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
434
|
-
}
|
|
435
|
-
function _arrayLikeToArray(arr, len) {
|
|
436
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
437
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
438
|
-
return arr2;
|
|
439
|
-
}
|
|
440
|
-
function _nonIterableSpread() {
|
|
441
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
442
|
-
}
|
|
443
|
-
function _nonIterableRest() {
|
|
444
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
445
|
-
}
|
|
446
|
-
function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
447
|
-
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
448
|
-
if (!it) {
|
|
449
|
-
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
450
|
-
if (it) o = it;
|
|
451
|
-
var i = 0;
|
|
452
|
-
var F = function () {};
|
|
453
|
-
return {
|
|
454
|
-
s: F,
|
|
455
|
-
n: function () {
|
|
456
|
-
if (i >= o.length) return {
|
|
457
|
-
done: true
|
|
458
|
-
};
|
|
459
|
-
return {
|
|
460
|
-
done: false,
|
|
461
|
-
value: o[i++]
|
|
462
|
-
};
|
|
463
|
-
},
|
|
464
|
-
e: function (e) {
|
|
465
|
-
throw e;
|
|
466
|
-
},
|
|
467
|
-
f: F
|
|
468
|
-
};
|
|
469
|
-
}
|
|
470
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
471
|
-
}
|
|
472
|
-
var normalCompletion = true,
|
|
473
|
-
didErr = false,
|
|
474
|
-
err;
|
|
475
|
-
return {
|
|
476
|
-
s: function () {
|
|
477
|
-
it = it.call(o);
|
|
478
|
-
},
|
|
479
|
-
n: function () {
|
|
480
|
-
var step = it.next();
|
|
481
|
-
normalCompletion = step.done;
|
|
482
|
-
return step;
|
|
483
|
-
},
|
|
484
|
-
e: function (e) {
|
|
485
|
-
didErr = true;
|
|
486
|
-
err = e;
|
|
487
|
-
},
|
|
488
|
-
f: function () {
|
|
489
|
-
try {
|
|
490
|
-
if (!normalCompletion && it.return != null) it.return();
|
|
491
|
-
} finally {
|
|
492
|
-
if (didErr) throw err;
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
};
|
|
496
|
-
}
|
|
497
|
-
function _toPrimitive(input, hint) {
|
|
498
|
-
if (typeof input !== "object" || input === null) return input;
|
|
499
|
-
var prim = input[Symbol.toPrimitive];
|
|
500
|
-
if (prim !== undefined) {
|
|
501
|
-
var res = prim.call(input, hint || "default");
|
|
502
|
-
if (typeof res !== "object") return res;
|
|
503
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
504
|
-
}
|
|
505
|
-
return (hint === "string" ? String : Number)(input);
|
|
506
|
-
}
|
|
507
|
-
function _toPropertyKey(arg) {
|
|
508
|
-
var key = _toPrimitive(arg, "string");
|
|
509
|
-
return typeof key === "symbol" ? key : String(key);
|
|
510
|
-
}
|
|
511
|
-
function _classPrivateFieldGet(receiver, privateMap) {
|
|
512
|
-
var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get");
|
|
513
|
-
return _classApplyDescriptorGet(receiver, descriptor);
|
|
514
|
-
}
|
|
515
|
-
function _classPrivateFieldSet(receiver, privateMap, value) {
|
|
516
|
-
var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set");
|
|
517
|
-
_classApplyDescriptorSet(receiver, descriptor, value);
|
|
518
|
-
return value;
|
|
519
|
-
}
|
|
520
|
-
function _classExtractFieldDescriptor(receiver, privateMap, action) {
|
|
521
|
-
if (!privateMap.has(receiver)) {
|
|
522
|
-
throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
523
|
-
}
|
|
524
|
-
return privateMap.get(receiver);
|
|
525
|
-
}
|
|
526
|
-
function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) {
|
|
527
|
-
_classCheckPrivateStaticAccess(receiver, classConstructor);
|
|
528
|
-
_classCheckPrivateStaticFieldDescriptor(descriptor, "get");
|
|
529
|
-
return _classApplyDescriptorGet(receiver, descriptor);
|
|
530
|
-
}
|
|
531
|
-
function _classStaticPrivateFieldSpecSet(receiver, classConstructor, descriptor, value) {
|
|
532
|
-
_classCheckPrivateStaticAccess(receiver, classConstructor);
|
|
533
|
-
_classCheckPrivateStaticFieldDescriptor(descriptor, "set");
|
|
534
|
-
_classApplyDescriptorSet(receiver, descriptor, value);
|
|
535
|
-
return value;
|
|
536
|
-
}
|
|
537
|
-
function _classApplyDescriptorGet(receiver, descriptor) {
|
|
538
|
-
if (descriptor.get) {
|
|
539
|
-
return descriptor.get.call(receiver);
|
|
540
|
-
}
|
|
541
|
-
return descriptor.value;
|
|
542
|
-
}
|
|
543
|
-
function _classApplyDescriptorSet(receiver, descriptor, value) {
|
|
544
|
-
if (descriptor.set) {
|
|
545
|
-
descriptor.set.call(receiver, value);
|
|
546
|
-
} else {
|
|
547
|
-
if (!descriptor.writable) {
|
|
548
|
-
throw new TypeError("attempted to set read only private field");
|
|
549
|
-
}
|
|
550
|
-
descriptor.value = value;
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
function _classCheckPrivateStaticAccess(receiver, classConstructor) {
|
|
554
|
-
if (receiver !== classConstructor) {
|
|
555
|
-
throw new TypeError("Private static access of wrong provenance");
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
function _classCheckPrivateStaticFieldDescriptor(descriptor, action) {
|
|
559
|
-
if (descriptor === undefined) {
|
|
560
|
-
throw new TypeError("attempted to " + action + " private static field before its declaration");
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
function _checkPrivateRedeclaration(obj, privateCollection) {
|
|
564
|
-
if (privateCollection.has(obj)) {
|
|
565
|
-
throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
function _classPrivateFieldInitSpec(obj, privateMap, value) {
|
|
569
|
-
_checkPrivateRedeclaration(obj, privateMap);
|
|
570
|
-
privateMap.set(obj, value);
|
|
571
|
-
}
|
|
572
|
-
|
|
573
9
|
function toCamelCase(string) {
|
|
574
|
-
return string.replace(/(
|
|
575
|
-
return match[1].toUpperCase();
|
|
576
|
-
});
|
|
10
|
+
return string.replace(/[-_]/g, ' ').replace(/\s+/, ' ').trim().replace(/(\s\w)/g, match => match[1].toUpperCase());
|
|
577
11
|
}
|
|
578
12
|
function toSnakeCase(string) {
|
|
579
|
-
return string.replace(/
|
|
580
|
-
return match[0] + '_' + match[1].toLowerCase();
|
|
581
|
-
}).toLowerCase();
|
|
13
|
+
return string.replace(/(.)(?=[A-Z])/g, match => match + '_').toLowerCase();
|
|
582
14
|
}
|
|
583
15
|
function escapeRegExp(string) {
|
|
584
16
|
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
585
17
|
}
|
|
586
18
|
function getByPath(obj, path, defaultValue) {
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
593
|
-
var key = _step.value;
|
|
594
|
-
if (!current.hasOwnProperty(key)) {
|
|
595
|
-
return defaultValue;
|
|
596
|
-
}
|
|
597
|
-
current = current[key];
|
|
19
|
+
const keys = path.split('.');
|
|
20
|
+
let current = obj;
|
|
21
|
+
for (const key of keys) {
|
|
22
|
+
if (!current.hasOwnProperty(key)) {
|
|
23
|
+
return defaultValue;
|
|
598
24
|
}
|
|
599
|
-
|
|
600
|
-
_iterator.e(err);
|
|
601
|
-
} finally {
|
|
602
|
-
_iterator.f();
|
|
25
|
+
current = current[key];
|
|
603
26
|
}
|
|
604
27
|
return current;
|
|
605
28
|
}
|
|
606
29
|
function flattenObject(obj) {
|
|
607
|
-
|
|
608
|
-
return Object.keys(obj).reduce(
|
|
609
|
-
|
|
610
|
-
if (
|
|
30
|
+
let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
31
|
+
return Object.keys(obj).reduce((accumulator, key) => {
|
|
32
|
+
const prefixedKey = prefix ? `${prefix}.${key}` : key;
|
|
33
|
+
if (typeof obj[key] === 'object' && obj[key] !== null) {
|
|
611
34
|
Object.assign(accumulator, flattenObject(obj[key], prefixedKey));
|
|
612
35
|
} else {
|
|
613
36
|
accumulator[prefixedKey] = obj[key];
|
|
@@ -615,81 +38,54 @@ var quival = (function (exports) {
|
|
|
615
38
|
return accumulator;
|
|
616
39
|
}, {});
|
|
617
40
|
}
|
|
41
|
+
function parseCsvString(value) {
|
|
42
|
+
const result = [];
|
|
43
|
+
let current = '';
|
|
44
|
+
let insideQuotes = false;
|
|
45
|
+
for (let i = 0; i < value.length; i++) {
|
|
46
|
+
const char = value[i];
|
|
47
|
+
if (char === '"') {
|
|
48
|
+
if (insideQuotes && value[i + 1] === '"') {
|
|
49
|
+
current += '"';
|
|
50
|
+
i++;
|
|
51
|
+
} else {
|
|
52
|
+
insideQuotes = !insideQuotes;
|
|
53
|
+
if (insideQuotes) {
|
|
54
|
+
current = current.trim();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
} else if (char === ',' && !insideQuotes) {
|
|
58
|
+
result.push(current);
|
|
59
|
+
current = '';
|
|
60
|
+
} else {
|
|
61
|
+
current += char;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
result.push(current);
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
618
67
|
function parseDate(value) {
|
|
619
68
|
if (isEmpty(value) || typeof value !== 'string') {
|
|
620
69
|
return new Date('');
|
|
621
70
|
} else if (value instanceof Date) {
|
|
622
71
|
return value;
|
|
623
72
|
}
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
return value && /^\d*$/.test(value) ? parseInt(value) : value;
|
|
627
|
-
};
|
|
73
|
+
let match, years, months, days, hours, minutes, seconds, meridiem;
|
|
74
|
+
const castToIntegers = value => value && /^\d*$/.test(value) ? parseInt(value) : value;
|
|
628
75
|
if ((match = value.match(/^(\d{1,2})[.\/-](\d{1,2})[.\/-](\d{2,4})\s?((\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?)?/i)) !== null) {
|
|
629
|
-
|
|
630
|
-
var _match$map2 = _slicedToArray(_match$map, 10);
|
|
631
|
-
days = _match$map2[1];
|
|
632
|
-
months = _match$map2[2];
|
|
633
|
-
years = _match$map2[3];
|
|
634
|
-
var _match$map2$ = _match$map2[5];
|
|
635
|
-
hours = _match$map2$ === void 0 ? 0 : _match$map2$;
|
|
636
|
-
var _match$map2$2 = _match$map2[6];
|
|
637
|
-
minutes = _match$map2$2 === void 0 ? 0 : _match$map2$2;
|
|
638
|
-
var _match$map2$3 = _match$map2[8];
|
|
639
|
-
seconds = _match$map2$3 === void 0 ? 0 : _match$map2$3;
|
|
640
|
-
var _match$map2$4 = _match$map2[9];
|
|
641
|
-
meridiem = _match$map2$4 === void 0 ? 'am' : _match$map2$4;
|
|
76
|
+
[, days, months, years,, hours = 0, minutes = 0,, seconds = 0, meridiem = 'am'] = match.map(castToIntegers);
|
|
642
77
|
} else if ((match = value.match(/^(\d{2,4})[.\/-](\d{1,2})[.\/-](\d{1,2})\s?((\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?)?/i)) !== null || (match = value.match(/^(\d{4})(\d{2})(\d{2})\s?((\d{2})(\d{2})((\d{2}))?\s?(am|pm)?)?/i)) !== null) {
|
|
643
|
-
|
|
644
|
-
var _match$map4 = _slicedToArray(_match$map3, 10);
|
|
645
|
-
years = _match$map4[1];
|
|
646
|
-
months = _match$map4[2];
|
|
647
|
-
days = _match$map4[3];
|
|
648
|
-
var _match$map4$ = _match$map4[5];
|
|
649
|
-
hours = _match$map4$ === void 0 ? 0 : _match$map4$;
|
|
650
|
-
var _match$map4$2 = _match$map4[6];
|
|
651
|
-
minutes = _match$map4$2 === void 0 ? 0 : _match$map4$2;
|
|
652
|
-
var _match$map4$3 = _match$map4[8];
|
|
653
|
-
seconds = _match$map4$3 === void 0 ? 0 : _match$map4$3;
|
|
654
|
-
var _match$map4$4 = _match$map4[9];
|
|
655
|
-
meridiem = _match$map4$4 === void 0 ? 'am' : _match$map4$4;
|
|
78
|
+
[, years, months, days,, hours = 0, minutes = 0,, seconds = 0, meridiem = 'am'] = match.map(castToIntegers);
|
|
656
79
|
} else if (match = value.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{4})[.\/-](\d{2})[.\/-](\d{2})/i)) {
|
|
657
|
-
|
|
658
|
-
var _match$map6 = _slicedToArray(_match$map5, 9);
|
|
659
|
-
hours = _match$map6[1];
|
|
660
|
-
minutes = _match$map6[2];
|
|
661
|
-
seconds = _match$map6[4];
|
|
662
|
-
var _match$map6$ = _match$map6[5];
|
|
663
|
-
meridiem = _match$map6$ === void 0 ? 'am' : _match$map6$;
|
|
664
|
-
years = _match$map6[6];
|
|
665
|
-
months = _match$map6[7];
|
|
666
|
-
days = _match$map6[8];
|
|
80
|
+
[, hours, minutes,, seconds, meridiem = 'am', years, months, days] = match.map(castToIntegers);
|
|
667
81
|
} else if (match = value.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{2})[.\/-](\d{2})[.\/-](\d{4})/i)) {
|
|
668
|
-
|
|
669
|
-
var _match$map8 = _slicedToArray(_match$map7, 9);
|
|
670
|
-
hours = _match$map8[1];
|
|
671
|
-
minutes = _match$map8[2];
|
|
672
|
-
seconds = _match$map8[4];
|
|
673
|
-
var _match$map8$ = _match$map8[5];
|
|
674
|
-
meridiem = _match$map8$ === void 0 ? 'am' : _match$map8$;
|
|
675
|
-
days = _match$map8[6];
|
|
676
|
-
months = _match$map8[7];
|
|
677
|
-
years = _match$map8[8];
|
|
82
|
+
[, hours, minutes,, seconds, meridiem = 'am', days, months, years] = match.map(castToIntegers);
|
|
678
83
|
} else if (match = value.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?/i)) {
|
|
679
|
-
|
|
84
|
+
const current = new Date();
|
|
680
85
|
years = current.getFullYear();
|
|
681
86
|
months = current.getMonth() + 1;
|
|
682
87
|
days = current.getDate();
|
|
683
|
-
|
|
684
|
-
var _match$map10 = _slicedToArray(_match$map9, 6);
|
|
685
|
-
var _match$map10$ = _match$map10[1];
|
|
686
|
-
hours = _match$map10$ === void 0 ? 0 : _match$map10$;
|
|
687
|
-
var _match$map10$2 = _match$map10[2];
|
|
688
|
-
minutes = _match$map10$2 === void 0 ? 0 : _match$map10$2;
|
|
689
|
-
var _match$map10$3 = _match$map10[4];
|
|
690
|
-
seconds = _match$map10$3 === void 0 ? 0 : _match$map10$3;
|
|
691
|
-
var _match$map10$4 = _match$map10[5];
|
|
692
|
-
meridiem = _match$map10$4 === void 0 ? 'am' : _match$map10$4;
|
|
88
|
+
[, hours = 0, minutes = 0,, seconds = 0, meridiem = 'am'] = match.map(castToIntegers);
|
|
693
89
|
} else {
|
|
694
90
|
return new Date(value);
|
|
695
91
|
}
|
|
@@ -699,15 +95,14 @@ var quival = (function (exports) {
|
|
|
699
95
|
if (meridiem.toLowerCase() === 'pm' && hours < 12) {
|
|
700
96
|
hours += 12;
|
|
701
97
|
}
|
|
702
|
-
return new Date(
|
|
98
|
+
return new Date(`${years}-${months}-${days} ${hours}:${minutes}:${seconds}`);
|
|
703
99
|
}
|
|
704
100
|
function parseDateByFormat(value, format) {
|
|
705
|
-
var _match$indices$hours, _match$indices$minute, _match$indices$second, _match$indices$meridi;
|
|
706
101
|
if (isEmpty(value)) {
|
|
707
102
|
return new Date('');
|
|
708
103
|
}
|
|
709
104
|
format = format.split('');
|
|
710
|
-
|
|
105
|
+
const formats = {
|
|
711
106
|
Y: '(\\d{4})',
|
|
712
107
|
y: '(\\d{2})',
|
|
713
108
|
m: '(\\d{2})',
|
|
@@ -723,8 +118,8 @@ var quival = (function (exports) {
|
|
|
723
118
|
A: '(AM|PM)',
|
|
724
119
|
a: '(am|pm)'
|
|
725
120
|
};
|
|
726
|
-
|
|
727
|
-
|
|
121
|
+
let pattern = '^';
|
|
122
|
+
let indices = {
|
|
728
123
|
years: -1,
|
|
729
124
|
months: -1,
|
|
730
125
|
days: -1,
|
|
@@ -733,54 +128,43 @@ var quival = (function (exports) {
|
|
|
733
128
|
seconds: -1,
|
|
734
129
|
meridiem: -1
|
|
735
130
|
};
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
if (
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
} else if (char === 's') {
|
|
755
|
-
indices.seconds = index++;
|
|
756
|
-
} else if (['A', 'a'].indexOf(char) !== -1) {
|
|
757
|
-
indices.meridiem = index++;
|
|
758
|
-
}
|
|
759
|
-
} else {
|
|
760
|
-
pattern += '\\' + char;
|
|
131
|
+
let index = 1;
|
|
132
|
+
for (const char of format) {
|
|
133
|
+
if (formats.hasOwnProperty(char)) {
|
|
134
|
+
pattern += formats[char];
|
|
135
|
+
if (['Y', 'y'].indexOf(char) !== -1) {
|
|
136
|
+
indices.years = index++;
|
|
137
|
+
} else if (['m', 'n'].indexOf(char) !== -1) {
|
|
138
|
+
indices.months = index++;
|
|
139
|
+
} else if (['d', 'j'].indexOf(char) !== -1) {
|
|
140
|
+
indices.days = index++;
|
|
141
|
+
} else if (['G', 'g', 'H', 'h'].indexOf(char) !== -1) {
|
|
142
|
+
indices.hours = index++;
|
|
143
|
+
} else if (char === 'i') {
|
|
144
|
+
indices.minutes = index++;
|
|
145
|
+
} else if (char === 's') {
|
|
146
|
+
indices.seconds = index++;
|
|
147
|
+
} else if (['A', 'a'].indexOf(char) !== -1) {
|
|
148
|
+
indices.meridiem = index++;
|
|
761
149
|
}
|
|
150
|
+
} else {
|
|
151
|
+
pattern += '\\' + char;
|
|
762
152
|
}
|
|
763
|
-
} catch (err) {
|
|
764
|
-
_iterator3.e(err);
|
|
765
|
-
} finally {
|
|
766
|
-
_iterator3.f();
|
|
767
153
|
}
|
|
768
154
|
pattern += '$';
|
|
769
|
-
|
|
155
|
+
let match = value.match(new RegExp(pattern));
|
|
770
156
|
if (match === null) {
|
|
771
157
|
return new Date('');
|
|
772
158
|
}
|
|
773
|
-
match = match.map(
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
var seconds = (_match$indices$second = match[indices.seconds]) !== null && _match$indices$second !== void 0 ? _match$indices$second : 0;
|
|
783
|
-
var meridiem = (_match$indices$meridi = match[indices.meridiem]) !== null && _match$indices$meridi !== void 0 ? _match$indices$meridi : 'am';
|
|
159
|
+
match = match.map(value => value && /^\d*$/.test(value) ? parseInt(value) : value);
|
|
160
|
+
const current = new Date();
|
|
161
|
+
let years = match[indices.years];
|
|
162
|
+
let months = match[indices.months];
|
|
163
|
+
let days = match[indices.days];
|
|
164
|
+
let hours = match[indices.hours] ?? 0;
|
|
165
|
+
let minutes = match[indices.minutes] ?? 0;
|
|
166
|
+
let seconds = match[indices.seconds] ?? 0;
|
|
167
|
+
let meridiem = match[indices.meridiem] ?? 'am';
|
|
784
168
|
if (!years && !months && !days) {
|
|
785
169
|
years = current.getFullYear();
|
|
786
170
|
months = current.getMonth() + 1;
|
|
@@ -801,7 +185,7 @@ var quival = (function (exports) {
|
|
|
801
185
|
if (meridiem.toLowerCase() === 'pm' && hours < 12) {
|
|
802
186
|
hours += 12;
|
|
803
187
|
}
|
|
804
|
-
return new Date(
|
|
188
|
+
return new Date(`${years}-${months}-${days} ${hours}:${minutes}:${seconds}`);
|
|
805
189
|
}
|
|
806
190
|
function isDigits(value) {
|
|
807
191
|
return String(value).search(/[^0-9]/) === -1;
|
|
@@ -810,7 +194,7 @@ var quival = (function (exports) {
|
|
|
810
194
|
return value === '' || value === null || typeof value === 'undefined';
|
|
811
195
|
}
|
|
812
196
|
function isNumeric(value) {
|
|
813
|
-
|
|
197
|
+
const number = Number(value);
|
|
814
198
|
return value !== null && typeof value !== 'boolean' && typeof number === 'number' && !isNaN(number);
|
|
815
199
|
}
|
|
816
200
|
function isPlainObject(value) {
|
|
@@ -820,2216 +204,1332 @@ var quival = (function (exports) {
|
|
|
820
204
|
return value instanceof Date && value.toDateString() !== 'Invalid Date';
|
|
821
205
|
}
|
|
822
206
|
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
_defineProperty(this, "validator", void 0);
|
|
829
|
-
_classPrivateFieldInitSpec(this, _distinctCache, {
|
|
830
|
-
writable: true,
|
|
831
|
-
value: {}
|
|
832
|
-
});
|
|
833
|
-
_classPrivateFieldInitSpec(this, _imageCache, {
|
|
834
|
-
writable: true,
|
|
835
|
-
value: {}
|
|
836
|
-
});
|
|
207
|
+
class Checkers {
|
|
208
|
+
validator;
|
|
209
|
+
#distinctCache = {};
|
|
210
|
+
#imageCache = {};
|
|
211
|
+
constructor(validator) {
|
|
837
212
|
this.validator = validator;
|
|
838
213
|
}
|
|
839
214
|
|
|
840
215
|
// Internal helpers
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
});
|
|
216
|
+
clearCaches() {
|
|
217
|
+
this.#distinctCache = {};
|
|
218
|
+
this.#imageCache = {};
|
|
219
|
+
}
|
|
220
|
+
isDependent(parameters) {
|
|
221
|
+
const other = this.validator.getValue(parameters[0]);
|
|
222
|
+
return parameters.slice(1).some(value => value == other);
|
|
223
|
+
}
|
|
224
|
+
collectRequiredsThenTest(attribute, value, parameters, callback) {
|
|
225
|
+
let result = [];
|
|
226
|
+
for (const other of parameters) {
|
|
227
|
+
result.push(this.checkRequired(other, this.validator.getValue(other)));
|
|
854
228
|
}
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
value: function collectRequiredsThenTest(attribute, value, parameters, callback) {
|
|
858
|
-
var result = [];
|
|
859
|
-
var _iterator = _createForOfIteratorHelper(parameters),
|
|
860
|
-
_step;
|
|
861
|
-
try {
|
|
862
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
863
|
-
var other = _step.value;
|
|
864
|
-
result.push(this.checkRequired(other, this.validator.getValue(other)));
|
|
865
|
-
}
|
|
866
|
-
} catch (err) {
|
|
867
|
-
_iterator.e(err);
|
|
868
|
-
} finally {
|
|
869
|
-
_iterator.f();
|
|
870
|
-
}
|
|
871
|
-
if (callback(result)) {
|
|
872
|
-
return this.checkRequired(attribute, value);
|
|
873
|
-
}
|
|
874
|
-
return true;
|
|
229
|
+
if (callback(result)) {
|
|
230
|
+
return this.checkRequired(attribute, value);
|
|
875
231
|
}
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
try {
|
|
883
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
884
|
-
var other = _step2.value;
|
|
885
|
-
result.push(this.checkMissing(other));
|
|
886
|
-
}
|
|
887
|
-
} catch (err) {
|
|
888
|
-
_iterator2.e(err);
|
|
889
|
-
} finally {
|
|
890
|
-
_iterator2.f();
|
|
891
|
-
}
|
|
892
|
-
if (callback(result)) {
|
|
893
|
-
return this.checkMissing(attribute);
|
|
894
|
-
}
|
|
895
|
-
return true;
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
collectMissingsThenTest(attribute, value, parameters, callback) {
|
|
235
|
+
let result = [];
|
|
236
|
+
for (const other of parameters) {
|
|
237
|
+
result.push(this.checkMissing(other));
|
|
896
238
|
}
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
value: function testStringUsingRegex(attribute, value, asciiRegex, unicodeRegex) {
|
|
900
|
-
var isAscii = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
901
|
-
if (typeof value !== 'string' && typeof value !== 'number') {
|
|
902
|
-
return false;
|
|
903
|
-
}
|
|
904
|
-
value = String(value);
|
|
905
|
-
if (isAscii || this.validator.hasRule(attribute, 'ascii')) {
|
|
906
|
-
return asciiRegex.test(value);
|
|
907
|
-
}
|
|
908
|
-
return unicodeRegex.test(value);
|
|
239
|
+
if (callback(result)) {
|
|
240
|
+
return this.checkMissing(attribute);
|
|
909
241
|
}
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
}
|
|
917
|
-
var other = (_parameters$ = parameters[0]) !== null && _parameters$ !== void 0 ? _parameters$ : '';
|
|
918
|
-
var otherValue = this.validator.getValue(other);
|
|
919
|
-
if (typeof otherValue === 'undefined') {
|
|
920
|
-
if (isNumeric(other)) {
|
|
921
|
-
otherValue = parseFloat(other, 10);
|
|
922
|
-
} else {
|
|
923
|
-
otherValue = null;
|
|
924
|
-
}
|
|
925
|
-
} else {
|
|
926
|
-
otherValue = this.validator.getSize(other, otherValue);
|
|
927
|
-
}
|
|
928
|
-
if (isEmpty(otherValue)) {
|
|
929
|
-
return false;
|
|
930
|
-
}
|
|
931
|
-
return callback(this.validator.getSize(attribute, value), otherValue);
|
|
932
|
-
}
|
|
933
|
-
}, {
|
|
934
|
-
key: "compareDates",
|
|
935
|
-
value: function compareDates(attribute, value, parameters, callback) {
|
|
936
|
-
var _parameters$2;
|
|
937
|
-
var rule = this.validator.getRule(attribute);
|
|
938
|
-
value = rule.hasOwnProperty('date_format') ? parseDateByFormat(value, rule.date_format[0]) : parseDate(value);
|
|
939
|
-
if (!isValidDate(value)) {
|
|
940
|
-
return false;
|
|
941
|
-
}
|
|
942
|
-
var other = (_parameters$2 = parameters[0]) !== null && _parameters$2 !== void 0 ? _parameters$2 : '';
|
|
943
|
-
var otherValue = this.validator.getValue(other);
|
|
944
|
-
if (typeof otherValue === 'undefined') {
|
|
945
|
-
otherValue = parseDate(other);
|
|
946
|
-
} else {
|
|
947
|
-
var otherRule = this.validator.getRule(other);
|
|
948
|
-
otherValue = otherRule.hasOwnProperty('date_format') ? parseDateByFormat(otherValue, otherRule.date_format[0]) : parseDate(otherValue);
|
|
949
|
-
}
|
|
950
|
-
if (!isValidDate(otherValue)) {
|
|
951
|
-
return false;
|
|
952
|
-
}
|
|
953
|
-
return callback(value.getTime(), otherValue.getTime());
|
|
242
|
+
return true;
|
|
243
|
+
}
|
|
244
|
+
testStringUsingRegex(attribute, value, asciiRegex, unicodeRegex) {
|
|
245
|
+
let isAscii = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
246
|
+
if (typeof value !== 'string' && typeof value !== 'number') {
|
|
247
|
+
return false;
|
|
954
248
|
}
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
key: "checkArray",
|
|
959
|
-
value: function checkArray(attribute, value, parameters) {
|
|
960
|
-
if (!(Array.isArray(value) || isPlainObject(value))) {
|
|
961
|
-
return false;
|
|
962
|
-
}
|
|
963
|
-
if (parameters && parameters.length > 0) {
|
|
964
|
-
for (var _i = 0, _Object$keys = Object.keys(value); _i < _Object$keys.length; _i++) {
|
|
965
|
-
var key = _Object$keys[_i];
|
|
966
|
-
if (!parameters.includes(key)) {
|
|
967
|
-
return false;
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
return true;
|
|
249
|
+
value = String(value);
|
|
250
|
+
if (isAscii || this.validator.hasRule(attribute, 'ascii')) {
|
|
251
|
+
return asciiRegex.test(value);
|
|
972
252
|
}
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
253
|
+
return unicodeRegex.test(value);
|
|
254
|
+
}
|
|
255
|
+
compareValues(attribute, value, parameters, callback) {
|
|
256
|
+
if (isEmpty(value)) {
|
|
257
|
+
return false;
|
|
977
258
|
}
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
259
|
+
const other = parameters[0] ?? '';
|
|
260
|
+
let otherValue = this.validator.getValue(other);
|
|
261
|
+
if (typeof otherValue === 'undefined') {
|
|
262
|
+
if (isNumeric(other)) {
|
|
263
|
+
otherValue = parseFloat(other, 10);
|
|
264
|
+
} else {
|
|
265
|
+
otherValue = null;
|
|
266
|
+
}
|
|
267
|
+
} else {
|
|
268
|
+
otherValue = this.validator.getSize(other, otherValue);
|
|
982
269
|
}
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
value: function checkFile(attribute, value, parameters) {
|
|
986
|
-
return value instanceof File;
|
|
270
|
+
if (isEmpty(otherValue)) {
|
|
271
|
+
return false;
|
|
987
272
|
}
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
273
|
+
return callback(this.validator.getSize(attribute, value), otherValue);
|
|
274
|
+
}
|
|
275
|
+
compareDates(attribute, value, parameters, callback) {
|
|
276
|
+
const rule = this.validator.getRule(attribute);
|
|
277
|
+
value = rule.hasOwnProperty('date_format') ? parseDateByFormat(value, rule.date_format[0]) : parseDate(value);
|
|
278
|
+
if (!isValidDate(value)) {
|
|
279
|
+
return false;
|
|
992
280
|
}
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
281
|
+
const other = parameters[0] ?? '';
|
|
282
|
+
let otherValue = this.validator.getValue(other);
|
|
283
|
+
if (typeof otherValue === 'undefined') {
|
|
284
|
+
otherValue = parseDate(other);
|
|
285
|
+
} else {
|
|
286
|
+
const otherRule = this.validator.getRule(other);
|
|
287
|
+
otherValue = otherRule.hasOwnProperty('date_format') ? parseDateByFormat(otherValue, otherRule.date_format[0]) : parseDate(otherValue);
|
|
997
288
|
}
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
value: function checkString(attribute, value, parameters) {
|
|
1001
|
-
return typeof value === 'string';
|
|
289
|
+
if (!isValidDate(otherValue)) {
|
|
290
|
+
return false;
|
|
1002
291
|
}
|
|
292
|
+
return callback(value.getTime(), otherValue.getTime());
|
|
293
|
+
}
|
|
1003
294
|
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
var _String$split$;
|
|
1009
|
-
if (!this.checkNumeric(attribute, value)) {
|
|
1010
|
-
return false;
|
|
1011
|
-
}
|
|
1012
|
-
var decimals = ((_String$split$ = String(value).split('.')[1]) !== null && _String$split$ !== void 0 ? _String$split$ : '').length;
|
|
1013
|
-
if (parameters.length === 1) {
|
|
1014
|
-
return decimals == parameters[0];
|
|
1015
|
-
}
|
|
1016
|
-
return decimals >= parameters[0] && decimals <= parameters[1];
|
|
295
|
+
// Type
|
|
296
|
+
checkArray(attribute, value, parameters) {
|
|
297
|
+
if (!(Array.isArray(value) || isPlainObject(value))) {
|
|
298
|
+
return false;
|
|
1017
299
|
}
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
}
|
|
1024
|
-
var numerator = parseInt(value, 10);
|
|
1025
|
-
var denominator = parseInt(parameters[0], 10);
|
|
1026
|
-
if (numerator === 0 && denominator === 0) {
|
|
1027
|
-
return false;
|
|
1028
|
-
} else if (numerator === 0) {
|
|
1029
|
-
return true;
|
|
1030
|
-
} else if (denominator === 0) {
|
|
1031
|
-
return false;
|
|
300
|
+
if (parameters && parameters.length > 0) {
|
|
301
|
+
for (const key of Object.keys(value)) {
|
|
302
|
+
if (!parameters.includes(key)) {
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
1032
305
|
}
|
|
1033
|
-
return numerator % denominator === 0;
|
|
1034
306
|
}
|
|
307
|
+
return true;
|
|
308
|
+
}
|
|
309
|
+
checkBoolean(attribute, value, parameters) {
|
|
310
|
+
return [true, false, 0, 1, '0', '1'].includes(value);
|
|
311
|
+
}
|
|
312
|
+
checkDate(attribute, value, parameters) {
|
|
313
|
+
return isValidDate(parseDate(value));
|
|
314
|
+
}
|
|
315
|
+
checkFile(attribute, value, parameters) {
|
|
316
|
+
return value instanceof File;
|
|
317
|
+
}
|
|
318
|
+
checkInteger(attribute, value, parameters) {
|
|
319
|
+
return String(parseInt(value, 10)) === String(value);
|
|
320
|
+
}
|
|
321
|
+
checkNumeric(attribute, value, parameters) {
|
|
322
|
+
return isNumeric(value);
|
|
323
|
+
}
|
|
324
|
+
checkString(attribute, value, parameters) {
|
|
325
|
+
return typeof value === 'string';
|
|
326
|
+
}
|
|
1035
327
|
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
return ['yes', 'on', '1', 1, true, 'true'].includes(value);
|
|
1041
|
-
}
|
|
1042
|
-
}, {
|
|
1043
|
-
key: "checkAcceptedIf",
|
|
1044
|
-
value: function checkAcceptedIf(attribute, value, parameters) {
|
|
1045
|
-
if (this.isDependent(parameters)) {
|
|
1046
|
-
return this.checkAccepted(attribute, value, parameters);
|
|
1047
|
-
}
|
|
1048
|
-
return true;
|
|
328
|
+
// Numeric
|
|
329
|
+
checkDecimal(attribute, value, parameters) {
|
|
330
|
+
if (!this.checkNumeric(attribute, value)) {
|
|
331
|
+
return false;
|
|
1049
332
|
}
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
return ['no', 'off', '0', 0, false, 'false'].includes(value);
|
|
333
|
+
const decimals = (String(value).split('.')[1] ?? '').length;
|
|
334
|
+
if (parameters.length === 1) {
|
|
335
|
+
return decimals == parameters[0];
|
|
1054
336
|
}
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
337
|
+
return decimals >= parameters[0] && decimals <= parameters[1];
|
|
338
|
+
}
|
|
339
|
+
checkMultipleOf(attribute, value, parameters) {
|
|
340
|
+
if (!isNumeric(value) || !isNumeric(parameters[0])) {
|
|
341
|
+
return false;
|
|
342
|
+
}
|
|
343
|
+
const numerator = parseInt(value, 10);
|
|
344
|
+
const denominator = parseInt(parameters[0], 10);
|
|
345
|
+
if (numerator === 0 && denominator === 0) {
|
|
346
|
+
return false;
|
|
347
|
+
} else if (numerator === 0) {
|
|
1061
348
|
return true;
|
|
349
|
+
} else if (denominator === 0) {
|
|
350
|
+
return false;
|
|
1062
351
|
}
|
|
352
|
+
return numerator % denominator === 0;
|
|
353
|
+
}
|
|
1063
354
|
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
return value.length > 0;
|
|
1072
|
-
} else if (value instanceof File) {
|
|
1073
|
-
return value.size > 0;
|
|
1074
|
-
}
|
|
1075
|
-
value = String(value).replace(/\s/g, '');
|
|
1076
|
-
return value.length > 0;
|
|
355
|
+
// Agreement
|
|
356
|
+
checkAccepted(attribute, value, parameters) {
|
|
357
|
+
return ['yes', 'on', '1', 1, true, 'true'].includes(value);
|
|
358
|
+
}
|
|
359
|
+
checkAcceptedIf(attribute, value, parameters) {
|
|
360
|
+
if (this.isDependent(parameters)) {
|
|
361
|
+
return this.checkAccepted(attribute, value, parameters);
|
|
1077
362
|
}
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
_step3;
|
|
1087
|
-
try {
|
|
1088
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
1089
|
-
var parameter = _step3.value;
|
|
1090
|
-
if (!keys.includes(parameter)) {
|
|
1091
|
-
return false;
|
|
1092
|
-
}
|
|
1093
|
-
}
|
|
1094
|
-
} catch (err) {
|
|
1095
|
-
_iterator3.e(err);
|
|
1096
|
-
} finally {
|
|
1097
|
-
_iterator3.f();
|
|
1098
|
-
}
|
|
1099
|
-
return true;
|
|
363
|
+
return true;
|
|
364
|
+
}
|
|
365
|
+
checkDeclined(attribute, value, parameters) {
|
|
366
|
+
return ['no', 'off', '0', 0, false, 'false'].includes(value);
|
|
367
|
+
}
|
|
368
|
+
checkDeclinedIf(attribute, value, parameters) {
|
|
369
|
+
if (this.isDependent(parameters)) {
|
|
370
|
+
return this.checkDeclined(attribute, value, parameters);
|
|
1100
371
|
}
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
return
|
|
372
|
+
return true;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// Existence
|
|
376
|
+
checkRequired(attribute, value, parameters) {
|
|
377
|
+
if (isEmpty(value)) {
|
|
378
|
+
return false;
|
|
379
|
+
} else if (Array.isArray(value)) {
|
|
380
|
+
return value.length > 0;
|
|
381
|
+
} else if (value instanceof File) {
|
|
382
|
+
return value.size > 0;
|
|
1108
383
|
}
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
return true;
|
|
384
|
+
value = String(value).replace(/\s/g, '');
|
|
385
|
+
return value.length > 0;
|
|
386
|
+
}
|
|
387
|
+
checkRequiredArrayKeys(attribute, value, parameters) {
|
|
388
|
+
if (!this.checkArray(attribute, value)) {
|
|
389
|
+
return false;
|
|
1116
390
|
}
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
return this.checkRequired(attribute, value);
|
|
391
|
+
const keys = Object.keys(value);
|
|
392
|
+
for (const parameter of parameters) {
|
|
393
|
+
if (!keys.includes(parameter)) {
|
|
394
|
+
return false;
|
|
1122
395
|
}
|
|
1123
|
-
return true;
|
|
1124
396
|
}
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
});
|
|
1131
|
-
}
|
|
1132
|
-
}, {
|
|
1133
|
-
key: "checkRequiredWithAll",
|
|
1134
|
-
value: function checkRequiredWithAll(attribute, value, parameters) {
|
|
1135
|
-
return this.collectRequiredsThenTest(attribute, value, parameters, function (result) {
|
|
1136
|
-
return !result.includes(false);
|
|
1137
|
-
});
|
|
1138
|
-
}
|
|
1139
|
-
}, {
|
|
1140
|
-
key: "checkRequiredWithout",
|
|
1141
|
-
value: function checkRequiredWithout(attribute, value, parameters) {
|
|
1142
|
-
return this.collectRequiredsThenTest(attribute, value, parameters, function (result) {
|
|
1143
|
-
return result.includes(false);
|
|
1144
|
-
});
|
|
397
|
+
return true;
|
|
398
|
+
}
|
|
399
|
+
checkRequiredIf(attribute, value, parameters) {
|
|
400
|
+
if (this.isDependent(parameters)) {
|
|
401
|
+
return this.checkRequired(attribute, value);
|
|
1145
402
|
}
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
});
|
|
403
|
+
return true;
|
|
404
|
+
}
|
|
405
|
+
checkRequiredIfAccepted(attribute, value, parameters) {
|
|
406
|
+
if (this.checkAccepted(parameters[0], this.validator.getValue(parameters[0]))) {
|
|
407
|
+
return this.checkRequired(attribute, value);
|
|
1152
408
|
}
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
}
|
|
1159
|
-
return true;
|
|
409
|
+
return true;
|
|
410
|
+
}
|
|
411
|
+
checkRequiredUnless(attribute, value, parameters) {
|
|
412
|
+
if (!this.isDependent(parameters)) {
|
|
413
|
+
return this.checkRequired(attribute, value);
|
|
1160
414
|
}
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
415
|
+
return true;
|
|
416
|
+
}
|
|
417
|
+
checkRequiredWith(attribute, value, parameters) {
|
|
418
|
+
return this.collectRequiredsThenTest(attribute, value, parameters, result => result.includes(true));
|
|
419
|
+
}
|
|
420
|
+
checkRequiredWithAll(attribute, value, parameters) {
|
|
421
|
+
return this.collectRequiredsThenTest(attribute, value, parameters, result => !result.includes(false));
|
|
422
|
+
}
|
|
423
|
+
checkRequiredWithout(attribute, value, parameters) {
|
|
424
|
+
return this.collectRequiredsThenTest(attribute, value, parameters, result => result.includes(false));
|
|
425
|
+
}
|
|
426
|
+
checkRequiredWithoutAll(attribute, value, parameters) {
|
|
427
|
+
return this.collectRequiredsThenTest(attribute, value, parameters, result => !result.includes(true));
|
|
428
|
+
}
|
|
429
|
+
checkFilled(attribute, value, parameters) {
|
|
430
|
+
if (typeof value !== 'undefined') {
|
|
431
|
+
return this.checkRequired(attribute, value);
|
|
1165
432
|
}
|
|
433
|
+
return true;
|
|
434
|
+
}
|
|
435
|
+
checkPresent(attribute, value, parameters) {
|
|
436
|
+
return typeof value !== 'undefined';
|
|
437
|
+
}
|
|
1166
438
|
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
key: "checkMissingIf",
|
|
1175
|
-
value: function checkMissingIf(attribute, value, parameters) {
|
|
1176
|
-
if (this.isDependent(parameters)) {
|
|
1177
|
-
return this.checkMissing(attribute);
|
|
1178
|
-
}
|
|
1179
|
-
return true;
|
|
1180
|
-
}
|
|
1181
|
-
}, {
|
|
1182
|
-
key: "checkMissingUnless",
|
|
1183
|
-
value: function checkMissingUnless(attribute, value, parameters) {
|
|
1184
|
-
if (!this.isDependent(parameters)) {
|
|
1185
|
-
return this.checkMissing(attribute);
|
|
1186
|
-
}
|
|
1187
|
-
return true;
|
|
1188
|
-
}
|
|
1189
|
-
}, {
|
|
1190
|
-
key: "checkMissingWith",
|
|
1191
|
-
value: function checkMissingWith(attribute, value, parameters) {
|
|
1192
|
-
return this.collectMissingsThenTest(attribute, value, parameters, function (result) {
|
|
1193
|
-
return result.includes(false);
|
|
1194
|
-
});
|
|
439
|
+
// Missing
|
|
440
|
+
checkMissing(attribute, value, parameters) {
|
|
441
|
+
return !this.validator.hasAttribute(attribute);
|
|
442
|
+
}
|
|
443
|
+
checkMissingIf(attribute, value, parameters) {
|
|
444
|
+
if (this.isDependent(parameters)) {
|
|
445
|
+
return this.checkMissing(attribute);
|
|
1195
446
|
}
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
});
|
|
447
|
+
return true;
|
|
448
|
+
}
|
|
449
|
+
checkMissingUnless(attribute, value, parameters) {
|
|
450
|
+
if (!this.isDependent(parameters)) {
|
|
451
|
+
return this.checkMissing(attribute);
|
|
1202
452
|
}
|
|
453
|
+
return true;
|
|
454
|
+
}
|
|
455
|
+
checkMissingWith(attribute, value, parameters) {
|
|
456
|
+
return this.collectMissingsThenTest(attribute, value, parameters, result => result.includes(false));
|
|
457
|
+
}
|
|
458
|
+
checkMissingWithAll(attribute, value, parameters) {
|
|
459
|
+
return this.collectMissingsThenTest(attribute, value, parameters, result => !result.includes(true));
|
|
460
|
+
}
|
|
1203
461
|
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
462
|
+
// Prohibition
|
|
463
|
+
checkProhibited(attribute, value, parameters) {
|
|
464
|
+
return !this.checkRequired(attribute, value);
|
|
465
|
+
}
|
|
466
|
+
checkProhibitedIf(attribute, value, parameters) {
|
|
467
|
+
if (this.isDependent(parameters)) {
|
|
1208
468
|
return !this.checkRequired(attribute, value);
|
|
1209
469
|
}
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
}
|
|
1216
|
-
return true;
|
|
1217
|
-
}
|
|
1218
|
-
}, {
|
|
1219
|
-
key: "checkProhibitedUnless",
|
|
1220
|
-
value: function checkProhibitedUnless(attribute, value, parameters) {
|
|
1221
|
-
if (!this.isDependent(parameters)) {
|
|
1222
|
-
return !this.checkRequired(attribute, value);
|
|
1223
|
-
}
|
|
1224
|
-
return true;
|
|
470
|
+
return true;
|
|
471
|
+
}
|
|
472
|
+
checkProhibitedUnless(attribute, value, parameters) {
|
|
473
|
+
if (!this.isDependent(parameters)) {
|
|
474
|
+
return !this.checkRequired(attribute, value);
|
|
1225
475
|
}
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
1234
|
-
var parameter = _step4.value;
|
|
1235
|
-
if (this.checkRequired(parameter, this.validator.getValue(parameter))) {
|
|
1236
|
-
return false;
|
|
1237
|
-
}
|
|
1238
|
-
}
|
|
1239
|
-
} catch (err) {
|
|
1240
|
-
_iterator4.e(err);
|
|
1241
|
-
} finally {
|
|
1242
|
-
_iterator4.f();
|
|
476
|
+
return true;
|
|
477
|
+
}
|
|
478
|
+
checkProhibits(attribute, value, parameters) {
|
|
479
|
+
if (this.checkRequired(attribute, value)) {
|
|
480
|
+
for (const parameter of parameters) {
|
|
481
|
+
if (this.checkRequired(parameter, this.validator.getValue(parameter))) {
|
|
482
|
+
return false;
|
|
1243
483
|
}
|
|
1244
484
|
}
|
|
1245
|
-
return true;
|
|
1246
485
|
}
|
|
486
|
+
return true;
|
|
487
|
+
}
|
|
1247
488
|
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
}
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
value: function checkMax(attribute, value, parameters) {
|
|
1262
|
-
return this.validator.getSize(attribute, value) <= parseFloat(parameters[0]);
|
|
1263
|
-
}
|
|
1264
|
-
}, {
|
|
1265
|
-
key: "checkBetween",
|
|
1266
|
-
value: function checkBetween(attribute, value, parameters) {
|
|
1267
|
-
return this.checkMin(attribute, value, [parameters[0]]) && this.checkMax(attribute, value, [parameters[1]]);
|
|
1268
|
-
}
|
|
489
|
+
// Size
|
|
490
|
+
checkSize(attribute, value, parameters) {
|
|
491
|
+
return this.validator.getSize(attribute, value) === parseFloat(parameters[0]);
|
|
492
|
+
}
|
|
493
|
+
checkMin(attribute, value, parameters) {
|
|
494
|
+
return this.validator.getSize(attribute, value) >= parseFloat(parameters[0]);
|
|
495
|
+
}
|
|
496
|
+
checkMax(attribute, value, parameters) {
|
|
497
|
+
return this.validator.getSize(attribute, value) <= parseFloat(parameters[0]);
|
|
498
|
+
}
|
|
499
|
+
checkBetween(attribute, value, parameters) {
|
|
500
|
+
return this.checkMin(attribute, value, [parameters[0]]) && this.checkMax(attribute, value, [parameters[1]]);
|
|
501
|
+
}
|
|
1269
502
|
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
value
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
return length === value;
|
|
1277
|
-
};
|
|
1278
|
-
value = String((_value = value) !== null && _value !== void 0 ? _value : '');
|
|
1279
|
-
if (!isDigits(value)) {
|
|
1280
|
-
return false;
|
|
1281
|
-
}
|
|
1282
|
-
return callback(value.length, parseInt(parameters[0], 10), parseInt((_parameters$3 = parameters[1]) !== null && _parameters$3 !== void 0 ? _parameters$3 : 0, 10));
|
|
1283
|
-
}
|
|
1284
|
-
}, {
|
|
1285
|
-
key: "checkMinDigits",
|
|
1286
|
-
value: function checkMinDigits(attribute, value, parameters) {
|
|
1287
|
-
return this.checkDigits(attribute, value, parameters, function (length, value) {
|
|
1288
|
-
return length >= value;
|
|
1289
|
-
});
|
|
1290
|
-
}
|
|
1291
|
-
}, {
|
|
1292
|
-
key: "checkMaxDigits",
|
|
1293
|
-
value: function checkMaxDigits(attribute, value, parameters) {
|
|
1294
|
-
return this.checkDigits(attribute, value, parameters, function (length, value) {
|
|
1295
|
-
return length <= value;
|
|
1296
|
-
});
|
|
1297
|
-
}
|
|
1298
|
-
}, {
|
|
1299
|
-
key: "checkDigitsBetween",
|
|
1300
|
-
value: function checkDigitsBetween(attribute, value, parameters) {
|
|
1301
|
-
return this.checkDigits(attribute, value, parameters, function (length, value1, value2) {
|
|
1302
|
-
return length >= value1 && length <= value2;
|
|
1303
|
-
});
|
|
503
|
+
// Digits
|
|
504
|
+
checkDigits(attribute, value, parameters) {
|
|
505
|
+
let callback = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : (length, value) => length === value;
|
|
506
|
+
value = String(value ?? '');
|
|
507
|
+
if (!isDigits(value)) {
|
|
508
|
+
return false;
|
|
1304
509
|
}
|
|
510
|
+
return callback(value.length, parseInt(parameters[0], 10), parseInt(parameters[1] ?? 0, 10));
|
|
511
|
+
}
|
|
512
|
+
checkMinDigits(attribute, value, parameters) {
|
|
513
|
+
return this.checkDigits(attribute, value, parameters, (length, value) => length >= value);
|
|
514
|
+
}
|
|
515
|
+
checkMaxDigits(attribute, value, parameters) {
|
|
516
|
+
return this.checkDigits(attribute, value, parameters, (length, value) => length <= value);
|
|
517
|
+
}
|
|
518
|
+
checkDigitsBetween(attribute, value, parameters) {
|
|
519
|
+
return this.checkDigits(attribute, value, parameters, (length, value1, value2) => length >= value1 && length <= value2);
|
|
520
|
+
}
|
|
1305
521
|
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
}
|
|
1312
|
-
}
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
return this.testStringUsingRegex(attribute, value, /^[a-z0-9_-]+$/i, /^(?:[\x2D0-9A-Z_a-z\xAA\xB2\xB3\xB5\xB9\xBA\xBC-\xBE\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u052F\u0531-\u0556\u0559\u0560-\u0588\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05EF-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u07FD\u0800-\u082D\u0840-\u085B\u0860-\u086A\u0870-\u0887\u0889-\u088E\u0898-\u08E1\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u09F4-\u09F9\u09FC\u09FE\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9-\u0AFF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B55-\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71-\u0B77\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BF2\u0C00-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3C-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C5D\u0C60-\u0C63\u0C66-\u0C6F\u0C78-\u0C7E\u0C80-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDD\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1-\u0CF3\u0D00-\u0D0C\u0D0E-\u0D10\u0D12-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D54-\u0D63\u0D66-\u0D78\u0D7A-\u0D7F\u0D81-\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECE\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F33\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1369-\u137C\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u1715\u171F-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u17F0-\u17F9\u180B-\u180D\u180F-\u1819\u1820-\u1878\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19DA\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ACE\u1B00-\u1B4C\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1C80-\u1C88\u1C90-\u1CBA\u1CBD-\u1CBF\u1CD0-\u1CD2\u1CD4-\u1CFA\u1D00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2070\u2071\u2074-\u2079\u207F-\u2089\u2090-\u209C\u20D0-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2150-\u2189\u2460-\u249B\u24EA-\u24FF\u2776-\u2793\u2C00-\u2CE4\u2CEB-\u2CF3\u2CFD\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u2E2F\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099\u309A\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u3192-\u3195\u31A0-\u31BF\u31F0-\u31FF\u3220-\u3229\u3248-\u324F\u3251-\u325F\u3280-\u3289\u32B1-\u32BF\u3400-\u4DBF\u4E00-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA672\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7CA\uA7D0\uA7D1\uA7D3\uA7D5-\uA7D9\uA7F2-\uA827\uA82C\uA830-\uA835\uA840-\uA873\uA880-\uA8C5\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB69\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD07-\uDD33\uDD40-\uDD78\uDD8A\uDD8B\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0-\uDEFB\uDF00-\uDF23\uDF2D-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDD70-\uDD7A\uDD7C-\uDD8A\uDD8C-\uDD92\uDD94\uDD95\uDD97-\uDDA1\uDDA3-\uDDB1\uDDB3-\uDDB9\uDDBB\uDDBC\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67\uDF80-\uDF85\uDF87-\uDFB0\uDFB2-\uDFBA]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC58-\uDC76\uDC79-\uDC9E\uDCA7-\uDCAF\uDCE0-\uDCF2\uDCF4\uDCF5\uDCFB-\uDD1B\uDD20-\uDD39\uDD80-\uDDB7\uDDBC-\uDDCF\uDDD2-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE35\uDE38-\uDE3A\uDE3F-\uDE48\uDE60-\uDE7E\uDE80-\uDE9F\uDEC0-\uDEC7\uDEC9-\uDEE6\uDEEB-\uDEEF\uDF00-\uDF35\uDF40-\uDF55\uDF58-\uDF72\uDF78-\uDF91\uDFA9-\uDFAF]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2\uDCFA-\uDD27\uDD30-\uDD39\uDE60-\uDE7E\uDE80-\uDEA9\uDEAB\uDEAC\uDEB0\uDEB1\uDEFD-\uDF27\uDF30-\uDF54\uDF70-\uDF85\uDFB0-\uDFCB\uDFE0-\uDFF6]|\uD804[\uDC00-\uDC46\uDC52-\uDC75\uDC7F-\uDCBA\uDCC2\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD44-\uDD47\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDC9-\uDDCC\uDDCE-\uDDDA\uDDDC\uDDE1-\uDDF4\uDE00-\uDE11\uDE13-\uDE37\uDE3E-\uDE41\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3B-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC00-\uDC4A\uDC50-\uDC59\uDC5E-\uDC61\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB8\uDEC0-\uDEC9\uDF00-\uDF1A\uDF1D-\uDF2B\uDF30-\uDF3B\uDF40-\uDF46]|\uD806[\uDC00-\uDC3A\uDCA0-\uDCF2\uDCFF-\uDD06\uDD09\uDD0C-\uDD13\uDD15\uDD16\uDD18-\uDD35\uDD37\uDD38\uDD3B-\uDD43\uDD50-\uDD59\uDDA0-\uDDA7\uDDAA-\uDDD7\uDDDA-\uDDE1\uDDE3\uDDE4\uDE00-\uDE3E\uDE47\uDE50-\uDE99\uDE9D\uDEB0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC36\uDC38-\uDC40\uDC50-\uDC6C\uDC72-\uDC8F\uDC92-\uDCA7\uDCA9-\uDCB6\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD36\uDD3A\uDD3C\uDD3D\uDD3F-\uDD47\uDD50-\uDD59\uDD60-\uDD65\uDD67\uDD68\uDD6A-\uDD8E\uDD90\uDD91\uDD93-\uDD98\uDDA0-\uDDA9\uDEE0-\uDEF6\uDF00-\uDF10\uDF12-\uDF3A\uDF3E-\uDF42\uDF50-\uDF59\uDFB0\uDFC0-\uDFD4]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|\uD80B[\uDF90-\uDFF0]|[\uD80C\uD81C-\uD820\uD822\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879\uD880-\uD883\uD885-\uD887][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2F\uDC40-\uDC55]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDE70-\uDEBE\uDEC0-\uDEC9\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF5B-\uDF61\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDE40-\uDE96\uDF00-\uDF4A\uDF4F-\uDF87\uDF8F-\uDF9F\uDFE0\uDFE1\uDFE3\uDFE4\uDFF0\uDFF1]|\uD821[\uDC00-\uDFF7]|\uD823[\uDC00-\uDCD5\uDD00-\uDD08]|\uD82B[\uDFF0-\uDFF3\uDFF5-\uDFFB\uDFFD\uDFFE]|\uD82C[\uDC00-\uDD22\uDD32\uDD50-\uDD52\uDD55\uDD64-\uDD67\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD833[\uDF00-\uDF2D\uDF30-\uDF46]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44\uDEC0-\uDED3\uDEE0-\uDEF3\uDF60-\uDF78]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD837[\uDF00-\uDF1E\uDF25-\uDF2A]|\uD838[\uDC00-\uDC06\uDC08-\uDC18\uDC1B-\uDC21\uDC23\uDC24\uDC26-\uDC2A\uDC30-\uDC6D\uDC8F\uDD00-\uDD2C\uDD30-\uDD3D\uDD40-\uDD49\uDD4E\uDE90-\uDEAE\uDEC0-\uDEF9]|\uD839[\uDCD0-\uDCF9\uDFE0-\uDFE6\uDFE8-\uDFEB\uDFED\uDFEE\uDFF0-\uDFFE]|\uD83A[\uDC00-\uDCC4\uDCC7-\uDCD6\uDD00-\uDD4B\uDD50-\uDD59]|\uD83B[\uDC71-\uDCAB\uDCAD-\uDCAF\uDCB1-\uDCB4\uDD01-\uDD2D\uDD2F-\uDD3D\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD83C[\uDD00-\uDD0C]|\uD83E[\uDFF0-\uDFF9]|\uD869[\uDC00-\uDEDF\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF39\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uD884[\uDC00-\uDF4A\uDF50-\uDFFF]|\uD888[\uDC00-\uDFAF]|\uDB40[\uDD00-\uDDEF])+$/, parameters.includes('ascii'));
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
return this.testStringUsingRegex(attribute, value, /^[a-z0-9]+$/i, /^(?:[0-9A-Za-z\xAA\xB2\xB3\xB5\xB9\xBA\xBC-\xBE\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u052F\u0531-\u0556\u0559\u0560-\u0588\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05EF-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u07FD\u0800-\u082D\u0840-\u085B\u0860-\u086A\u0870-\u0887\u0889-\u088E\u0898-\u08E1\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u09F4-\u09F9\u09FC\u09FE\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9-\u0AFF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B55-\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71-\u0B77\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BF2\u0C00-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3C-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C5D\u0C60-\u0C63\u0C66-\u0C6F\u0C78-\u0C7E\u0C80-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDD\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1-\u0CF3\u0D00-\u0D0C\u0D0E-\u0D10\u0D12-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D54-\u0D63\u0D66-\u0D78\u0D7A-\u0D7F\u0D81-\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECE\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F33\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1369-\u137C\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u1715\u171F-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u17F0-\u17F9\u180B-\u180D\u180F-\u1819\u1820-\u1878\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19DA\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ACE\u1B00-\u1B4C\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1C80-\u1C88\u1C90-\u1CBA\u1CBD-\u1CBF\u1CD0-\u1CD2\u1CD4-\u1CFA\u1D00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2070\u2071\u2074-\u2079\u207F-\u2089\u2090-\u209C\u20D0-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2150-\u2189\u2460-\u249B\u24EA-\u24FF\u2776-\u2793\u2C00-\u2CE4\u2CEB-\u2CF3\u2CFD\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u2E2F\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099\u309A\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u3192-\u3195\u31A0-\u31BF\u31F0-\u31FF\u3220-\u3229\u3248-\u324F\u3251-\u325F\u3280-\u3289\u32B1-\u32BF\u3400-\u4DBF\u4E00-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA672\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7CA\uA7D0\uA7D1\uA7D3\uA7D5-\uA7D9\uA7F2-\uA827\uA82C\uA830-\uA835\uA840-\uA873\uA880-\uA8C5\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB69\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD07-\uDD33\uDD40-\uDD78\uDD8A\uDD8B\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0-\uDEFB\uDF00-\uDF23\uDF2D-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDD70-\uDD7A\uDD7C-\uDD8A\uDD8C-\uDD92\uDD94\uDD95\uDD97-\uDDA1\uDDA3-\uDDB1\uDDB3-\uDDB9\uDDBB\uDDBC\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67\uDF80-\uDF85\uDF87-\uDFB0\uDFB2-\uDFBA]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC58-\uDC76\uDC79-\uDC9E\uDCA7-\uDCAF\uDCE0-\uDCF2\uDCF4\uDCF5\uDCFB-\uDD1B\uDD20-\uDD39\uDD80-\uDDB7\uDDBC-\uDDCF\uDDD2-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE35\uDE38-\uDE3A\uDE3F-\uDE48\uDE60-\uDE7E\uDE80-\uDE9F\uDEC0-\uDEC7\uDEC9-\uDEE6\uDEEB-\uDEEF\uDF00-\uDF35\uDF40-\uDF55\uDF58-\uDF72\uDF78-\uDF91\uDFA9-\uDFAF]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2\uDCFA-\uDD27\uDD30-\uDD39\uDE60-\uDE7E\uDE80-\uDEA9\uDEAB\uDEAC\uDEB0\uDEB1\uDEFD-\uDF27\uDF30-\uDF54\uDF70-\uDF85\uDFB0-\uDFCB\uDFE0-\uDFF6]|\uD804[\uDC00-\uDC46\uDC52-\uDC75\uDC7F-\uDCBA\uDCC2\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD44-\uDD47\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDC9-\uDDCC\uDDCE-\uDDDA\uDDDC\uDDE1-\uDDF4\uDE00-\uDE11\uDE13-\uDE37\uDE3E-\uDE41\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3B-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC00-\uDC4A\uDC50-\uDC59\uDC5E-\uDC61\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB8\uDEC0-\uDEC9\uDF00-\uDF1A\uDF1D-\uDF2B\uDF30-\uDF3B\uDF40-\uDF46]|\uD806[\uDC00-\uDC3A\uDCA0-\uDCF2\uDCFF-\uDD06\uDD09\uDD0C-\uDD13\uDD15\uDD16\uDD18-\uDD35\uDD37\uDD38\uDD3B-\uDD43\uDD50-\uDD59\uDDA0-\uDDA7\uDDAA-\uDDD7\uDDDA-\uDDE1\uDDE3\uDDE4\uDE00-\uDE3E\uDE47\uDE50-\uDE99\uDE9D\uDEB0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC36\uDC38-\uDC40\uDC50-\uDC6C\uDC72-\uDC8F\uDC92-\uDCA7\uDCA9-\uDCB6\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD36\uDD3A\uDD3C\uDD3D\uDD3F-\uDD47\uDD50-\uDD59\uDD60-\uDD65\uDD67\uDD68\uDD6A-\uDD8E\uDD90\uDD91\uDD93-\uDD98\uDDA0-\uDDA9\uDEE0-\uDEF6\uDF00-\uDF10\uDF12-\uDF3A\uDF3E-\uDF42\uDF50-\uDF59\uDFB0\uDFC0-\uDFD4]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|\uD80B[\uDF90-\uDFF0]|[\uD80C\uD81C-\uD820\uD822\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879\uD880-\uD883\uD885-\uD887][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2F\uDC40-\uDC55]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDE70-\uDEBE\uDEC0-\uDEC9\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF5B-\uDF61\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDE40-\uDE96\uDF00-\uDF4A\uDF4F-\uDF87\uDF8F-\uDF9F\uDFE0\uDFE1\uDFE3\uDFE4\uDFF0\uDFF1]|\uD821[\uDC00-\uDFF7]|\uD823[\uDC00-\uDCD5\uDD00-\uDD08]|\uD82B[\uDFF0-\uDFF3\uDFF5-\uDFFB\uDFFD\uDFFE]|\uD82C[\uDC00-\uDD22\uDD32\uDD50-\uDD52\uDD55\uDD64-\uDD67\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD833[\uDF00-\uDF2D\uDF30-\uDF46]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44\uDEC0-\uDED3\uDEE0-\uDEF3\uDF60-\uDF78]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD837[\uDF00-\uDF1E\uDF25-\uDF2A]|\uD838[\uDC00-\uDC06\uDC08-\uDC18\uDC1B-\uDC21\uDC23\uDC24\uDC26-\uDC2A\uDC30-\uDC6D\uDC8F\uDD00-\uDD2C\uDD30-\uDD3D\uDD40-\uDD49\uDD4E\uDE90-\uDEAE\uDEC0-\uDEF9]|\uD839[\uDCD0-\uDCF9\uDFE0-\uDFE6\uDFE8-\uDFEB\uDFED\uDFEE\uDFF0-\uDFFE]|\uD83A[\uDC00-\uDCC4\uDCC7-\uDCD6\uDD00-\uDD4B\uDD50-\uDD59]|\uD83B[\uDC71-\uDCAB\uDCAD-\uDCAF\uDCB1-\uDCB4\uDD01-\uDD2D\uDD2F-\uDD3D\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD83C[\uDD00-\uDD0C]|\uD83E[\uDFF0-\uDFF9]|\uD869[\uDC00-\uDEDF\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF39\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uD884[\uDC00-\uDF4A\uDF50-\uDFFF]|\uD888[\uDC00-\uDFAF]|\uDB40[\uDD00-\uDDEF])+$/, parameters.includes('ascii'));
|
|
1321
|
-
|
|
1322
|
-
}, {
|
|
1323
|
-
key: "checkAscii",
|
|
1324
|
-
value: function checkAscii(attribute, value, parameters) {
|
|
1325
|
-
return !/[^\x09\x10\x13\x0A\x0D\x20-\x7E]/.test(value);
|
|
1326
|
-
}
|
|
1327
|
-
}, {
|
|
1328
|
-
key: "checkRegex",
|
|
1329
|
-
value: function checkRegex(attribute, value, parameters) {
|
|
1330
|
-
var _expression$match;
|
|
1331
|
-
var invert = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
1332
|
-
if (!(typeof value === 'string' || isNumeric(value))) {
|
|
1333
|
-
return false;
|
|
1334
|
-
}
|
|
1335
|
-
var expression = parameters.join(',');
|
|
1336
|
-
var _ref = (_expression$match = expression.match(/^\/(.*)\/([gimu]*)$/)) !== null && _expression$match !== void 0 ? _expression$match : [],
|
|
1337
|
-
_ref2 = _slicedToArray(_ref, 3),
|
|
1338
|
-
whole = _ref2[0],
|
|
1339
|
-
pattern = _ref2[1],
|
|
1340
|
-
flags = _ref2[2];
|
|
1341
|
-
if (isEmpty(whole)) {
|
|
1342
|
-
throw new Error("Invalid regular expression pattern: ".concat(expression));
|
|
1343
|
-
}
|
|
1344
|
-
if (flags.includes('u')) {
|
|
1345
|
-
pattern = pattern.replace(/\\A/g, '^').replace(/\\z/gi, '$').replace(/\\([pP])([CLMNPSZ])/g, '\\$1{$2}').replace(/\\\x\{([0-9a-f]+)\}/g, "\\u{$1}");
|
|
1346
|
-
}
|
|
1347
|
-
var result = new RegExp(pattern, flags).test(value);
|
|
1348
|
-
return invert ? !result : result;
|
|
1349
|
-
}
|
|
1350
|
-
}, {
|
|
1351
|
-
key: "checkNotRegex",
|
|
1352
|
-
value: function checkNotRegex(attribute, value, parameters) {
|
|
1353
|
-
return this.checkRegex(attribute, value, parameters, true);
|
|
1354
|
-
}
|
|
1355
|
-
}, {
|
|
1356
|
-
key: "checkLowercase",
|
|
1357
|
-
value: function checkLowercase(attribute, value, parameters) {
|
|
1358
|
-
return value === String(value).toLocaleLowerCase();
|
|
1359
|
-
}
|
|
1360
|
-
}, {
|
|
1361
|
-
key: "checkUppercase",
|
|
1362
|
-
value: function checkUppercase(attribute, value, parameters) {
|
|
1363
|
-
return value === String(value).toLocaleUpperCase();
|
|
1364
|
-
}
|
|
1365
|
-
}, {
|
|
1366
|
-
key: "checkStartsWith",
|
|
1367
|
-
value: function checkStartsWith(attribute, value, parameters) {
|
|
1368
|
-
value = String(value);
|
|
1369
|
-
var _iterator5 = _createForOfIteratorHelper(parameters),
|
|
1370
|
-
_step5;
|
|
1371
|
-
try {
|
|
1372
|
-
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
1373
|
-
var parameter = _step5.value;
|
|
1374
|
-
if (value.startsWith(parameter)) {
|
|
1375
|
-
return true;
|
|
1376
|
-
}
|
|
1377
|
-
}
|
|
1378
|
-
} catch (err) {
|
|
1379
|
-
_iterator5.e(err);
|
|
1380
|
-
} finally {
|
|
1381
|
-
_iterator5.f();
|
|
1382
|
-
}
|
|
522
|
+
// String
|
|
523
|
+
checkAlpha(attribute, value, parameters) {
|
|
524
|
+
return this.testStringUsingRegex(attribute, value, /^[a-z]+$/i, /^[\p{L}\p{M}]+$/u, parameters.includes('ascii'));
|
|
525
|
+
}
|
|
526
|
+
checkAlphaDash(attribute, value, parameters) {
|
|
527
|
+
return this.testStringUsingRegex(attribute, value, /^[a-z0-9_-]+$/i, /^[\p{L}\p{M}\p{N}_-]+$/u, parameters.includes('ascii'));
|
|
528
|
+
}
|
|
529
|
+
checkAlphaNum(attribute, value, parameters) {
|
|
530
|
+
return this.testStringUsingRegex(attribute, value, /^[a-z0-9]+$/i, /^[\p{L}\p{M}\p{N}]+$/u, parameters.includes('ascii'));
|
|
531
|
+
}
|
|
532
|
+
checkAscii(attribute, value, parameters) {
|
|
533
|
+
return !/[^\x09\x10\x13\x0A\x0D\x20-\x7E]/.test(value);
|
|
534
|
+
}
|
|
535
|
+
checkRegex(attribute, value, parameters) {
|
|
536
|
+
let invert = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
537
|
+
if (!(typeof value === 'string' || isNumeric(value))) {
|
|
1383
538
|
return false;
|
|
1384
539
|
}
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
}
|
|
1390
|
-
}, {
|
|
1391
|
-
key: "checkEndsWith",
|
|
1392
|
-
value: function checkEndsWith(attribute, value, parameters) {
|
|
1393
|
-
value = String(value);
|
|
1394
|
-
var _iterator6 = _createForOfIteratorHelper(parameters),
|
|
1395
|
-
_step6;
|
|
1396
|
-
try {
|
|
1397
|
-
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
1398
|
-
var parameter = _step6.value;
|
|
1399
|
-
if (value.endsWith(parameter)) {
|
|
1400
|
-
return true;
|
|
1401
|
-
}
|
|
1402
|
-
}
|
|
1403
|
-
} catch (err) {
|
|
1404
|
-
_iterator6.e(err);
|
|
1405
|
-
} finally {
|
|
1406
|
-
_iterator6.f();
|
|
1407
|
-
}
|
|
1408
|
-
return false;
|
|
540
|
+
const expression = parameters.join(',');
|
|
541
|
+
let [whole, pattern, flags] = expression.match(/^\/(.*)\/([gimu]*)$/) ?? [];
|
|
542
|
+
if (isEmpty(whole)) {
|
|
543
|
+
throw new Error(`Invalid regular expression pattern: ${expression}`);
|
|
1409
544
|
}
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
value: function checkDoesntEndWith(attribute, value, parameters) {
|
|
1413
|
-
return !this.checkEndsWith(attribute, value, parameters);
|
|
545
|
+
if (flags.includes('u')) {
|
|
546
|
+
pattern = pattern.replace(/\\A/g, '^').replace(/\\z/gi, '$').replace(/\\([pP])([CLMNPSZ])/g, '\\$1{$2}').replace(/\\\x\{([0-9a-f]+)\}/g, '\\u{$1}');
|
|
1414
547
|
}
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
}
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
}
|
|
1424
|
-
|
|
1425
|
-
value
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
if (typeof other !== 'undefined' && value === other) {
|
|
1433
|
-
return false;
|
|
1434
|
-
}
|
|
1435
|
-
}
|
|
1436
|
-
} catch (err) {
|
|
1437
|
-
_iterator7.e(err);
|
|
1438
|
-
} finally {
|
|
1439
|
-
_iterator7.f();
|
|
548
|
+
const result = new RegExp(pattern, flags).test(value);
|
|
549
|
+
return invert ? !result : result;
|
|
550
|
+
}
|
|
551
|
+
checkNotRegex(attribute, value, parameters) {
|
|
552
|
+
return this.checkRegex(attribute, value, parameters, true);
|
|
553
|
+
}
|
|
554
|
+
checkLowercase(attribute, value, parameters) {
|
|
555
|
+
return value === String(value).toLocaleLowerCase();
|
|
556
|
+
}
|
|
557
|
+
checkUppercase(attribute, value, parameters) {
|
|
558
|
+
return value === String(value).toLocaleUpperCase();
|
|
559
|
+
}
|
|
560
|
+
checkStartsWith(attribute, value, parameters) {
|
|
561
|
+
value = String(value);
|
|
562
|
+
for (const parameter of parameters) {
|
|
563
|
+
if (value.startsWith(parameter)) {
|
|
564
|
+
return true;
|
|
1440
565
|
}
|
|
1441
|
-
return true;
|
|
1442
|
-
}
|
|
1443
|
-
}, {
|
|
1444
|
-
key: "checkConfirmed",
|
|
1445
|
-
value: function checkConfirmed(attribute, value, parameters) {
|
|
1446
|
-
return this.checkSame(attribute, value, [attribute + '_confirmation']);
|
|
1447
566
|
}
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
return val1 >= val2;
|
|
1460
|
-
});
|
|
1461
|
-
}
|
|
1462
|
-
}, {
|
|
1463
|
-
key: "checkLt",
|
|
1464
|
-
value: function checkLt(attribute, value, parameters) {
|
|
1465
|
-
return this.compareValues(attribute, value, parameters, function (val1, val2) {
|
|
1466
|
-
return val1 < val2;
|
|
1467
|
-
});
|
|
1468
|
-
}
|
|
1469
|
-
}, {
|
|
1470
|
-
key: "checkLte",
|
|
1471
|
-
value: function checkLte(attribute, value, parameters) {
|
|
1472
|
-
return this.compareValues(attribute, value, parameters, function (val1, val2) {
|
|
1473
|
-
return val1 <= val2;
|
|
1474
|
-
});
|
|
567
|
+
return false;
|
|
568
|
+
}
|
|
569
|
+
checkDoesntStartWith(attribute, value, parameters) {
|
|
570
|
+
return !this.checkStartsWith(attribute, value, parameters);
|
|
571
|
+
}
|
|
572
|
+
checkEndsWith(attribute, value, parameters) {
|
|
573
|
+
value = String(value);
|
|
574
|
+
for (const parameter of parameters) {
|
|
575
|
+
if (value.endsWith(parameter)) {
|
|
576
|
+
return true;
|
|
577
|
+
}
|
|
1475
578
|
}
|
|
579
|
+
return false;
|
|
580
|
+
}
|
|
581
|
+
checkDoesntEndWith(attribute, value, parameters) {
|
|
582
|
+
return !this.checkEndsWith(attribute, value, parameters);
|
|
583
|
+
}
|
|
1476
584
|
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
value: function checkAfterOrEqual(attribute, value, parameters) {
|
|
1488
|
-
return this.compareDates(attribute, value, parameters, function (val1, val2) {
|
|
1489
|
-
return val1 >= val2;
|
|
1490
|
-
});
|
|
1491
|
-
}
|
|
1492
|
-
}, {
|
|
1493
|
-
key: "checkBefore",
|
|
1494
|
-
value: function checkBefore(attribute, value, parameters) {
|
|
1495
|
-
return this.compareDates(attribute, value, parameters, function (val1, val2) {
|
|
1496
|
-
return val1 < val2;
|
|
1497
|
-
});
|
|
1498
|
-
}
|
|
1499
|
-
}, {
|
|
1500
|
-
key: "checkBeforeOrEqual",
|
|
1501
|
-
value: function checkBeforeOrEqual(attribute, value, parameters) {
|
|
1502
|
-
return this.compareDates(attribute, value, parameters, function (val1, val2) {
|
|
1503
|
-
return val1 <= val2;
|
|
1504
|
-
});
|
|
1505
|
-
}
|
|
1506
|
-
}, {
|
|
1507
|
-
key: "checkDateEquals",
|
|
1508
|
-
value: function checkDateEquals(attribute, value, parameters) {
|
|
1509
|
-
return this.compareDates(attribute, value, parameters, function (val1, val2) {
|
|
1510
|
-
return val1 === val2;
|
|
1511
|
-
});
|
|
1512
|
-
}
|
|
1513
|
-
}, {
|
|
1514
|
-
key: "checkDateFormat",
|
|
1515
|
-
value: function checkDateFormat(attribute, value, parameters) {
|
|
1516
|
-
var format = parameters[0].split('');
|
|
1517
|
-
var formats = {
|
|
1518
|
-
Y: '(\\d{4})',
|
|
1519
|
-
y: '(\\d{2})',
|
|
1520
|
-
m: '(\\d{2})',
|
|
1521
|
-
n: '([1-9]\\d?)',
|
|
1522
|
-
d: '(\\d{2})',
|
|
1523
|
-
j: '([1-9]\\d?)',
|
|
1524
|
-
G: '([1-9]\\d?)',
|
|
1525
|
-
g: '([1-9]\\d?)',
|
|
1526
|
-
H: '(\\d{2})',
|
|
1527
|
-
h: '(\\d{2})',
|
|
1528
|
-
i: '(\\d{2})',
|
|
1529
|
-
s: '(\\d{2})',
|
|
1530
|
-
A: '(AM|PM)',
|
|
1531
|
-
a: '(am|pm)'
|
|
1532
|
-
};
|
|
1533
|
-
var pattern = '^';
|
|
1534
|
-
var _iterator8 = _createForOfIteratorHelper(format),
|
|
1535
|
-
_step8;
|
|
1536
|
-
try {
|
|
1537
|
-
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
1538
|
-
var char = _step8.value;
|
|
1539
|
-
if (formats.hasOwnProperty(char)) {
|
|
1540
|
-
pattern += formats[char];
|
|
1541
|
-
} else {
|
|
1542
|
-
pattern += '\\' + char;
|
|
1543
|
-
}
|
|
1544
|
-
}
|
|
1545
|
-
} catch (err) {
|
|
1546
|
-
_iterator8.e(err);
|
|
1547
|
-
} finally {
|
|
1548
|
-
_iterator8.f();
|
|
585
|
+
// Compare values
|
|
586
|
+
checkSame(attribute, value, parameters) {
|
|
587
|
+
const other = this.validator.getValue(parameters[0]);
|
|
588
|
+
return value === other;
|
|
589
|
+
}
|
|
590
|
+
checkDifferent(attribute, value, parameters) {
|
|
591
|
+
for (const parameter of parameters) {
|
|
592
|
+
const other = this.validator.getValue(parameter);
|
|
593
|
+
if (typeof other !== 'undefined' && value === other) {
|
|
594
|
+
return false;
|
|
1549
595
|
}
|
|
1550
|
-
pattern += '$';
|
|
1551
|
-
return new RegExp(pattern).test(value);
|
|
1552
596
|
}
|
|
597
|
+
return true;
|
|
598
|
+
}
|
|
599
|
+
checkConfirmed(attribute, value, parameters) {
|
|
600
|
+
return this.checkSame(attribute, value, [attribute + '_confirmation']);
|
|
601
|
+
}
|
|
602
|
+
checkGt(attribute, value, parameters) {
|
|
603
|
+
return this.compareValues(attribute, value, parameters, (val1, val2) => val1 > val2);
|
|
604
|
+
}
|
|
605
|
+
checkGte(attribute, value, parameters) {
|
|
606
|
+
return this.compareValues(attribute, value, parameters, (val1, val2) => val1 >= val2);
|
|
607
|
+
}
|
|
608
|
+
checkLt(attribute, value, parameters) {
|
|
609
|
+
return this.compareValues(attribute, value, parameters, (val1, val2) => val1 < val2);
|
|
610
|
+
}
|
|
611
|
+
checkLte(attribute, value, parameters) {
|
|
612
|
+
return this.compareValues(attribute, value, parameters, (val1, val2) => val1 <= val2);
|
|
613
|
+
}
|
|
1553
614
|
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
615
|
+
// Dates
|
|
616
|
+
checkAfter(attribute, value, parameters) {
|
|
617
|
+
return this.compareDates(attribute, value, parameters, (val1, val2) => val1 > val2);
|
|
618
|
+
}
|
|
619
|
+
checkAfterOrEqual(attribute, value, parameters) {
|
|
620
|
+
return this.compareDates(attribute, value, parameters, (val1, val2) => val1 >= val2);
|
|
621
|
+
}
|
|
622
|
+
checkBefore(attribute, value, parameters) {
|
|
623
|
+
return this.compareDates(attribute, value, parameters, (val1, val2) => val1 < val2);
|
|
624
|
+
}
|
|
625
|
+
checkBeforeOrEqual(attribute, value, parameters) {
|
|
626
|
+
return this.compareDates(attribute, value, parameters, (val1, val2) => val1 <= val2);
|
|
627
|
+
}
|
|
628
|
+
checkDateEquals(attribute, value, parameters) {
|
|
629
|
+
return this.compareDates(attribute, value, parameters, (val1, val2) => val1 === val2);
|
|
630
|
+
}
|
|
631
|
+
checkDateFormat(attribute, value, parameters) {
|
|
632
|
+
const format = parameters[0].split('');
|
|
633
|
+
const formats = {
|
|
634
|
+
Y: '(\\d{4})',
|
|
635
|
+
y: '(\\d{2})',
|
|
636
|
+
m: '(\\d{2})',
|
|
637
|
+
n: '([1-9]\\d?)',
|
|
638
|
+
d: '(\\d{2})',
|
|
639
|
+
j: '([1-9]\\d?)',
|
|
640
|
+
G: '([1-9]\\d?)',
|
|
641
|
+
g: '([1-9]\\d?)',
|
|
642
|
+
H: '(\\d{2})',
|
|
643
|
+
h: '(\\d{2})',
|
|
644
|
+
i: '(\\d{2})',
|
|
645
|
+
s: '(\\d{2})',
|
|
646
|
+
A: '(AM|PM)',
|
|
647
|
+
a: '(am|pm)'
|
|
648
|
+
};
|
|
649
|
+
let pattern = '^';
|
|
650
|
+
for (const char of format) {
|
|
651
|
+
if (formats.hasOwnProperty(char)) {
|
|
652
|
+
pattern += formats[char];
|
|
1584
653
|
} else {
|
|
1585
|
-
pattern +=
|
|
1586
|
-
}
|
|
1587
|
-
pattern += '[,}]+';
|
|
1588
|
-
counter += (_stringified$match$le = (_stringified$match = stringified.match(new RegExp(pattern, 'g' + (ignoreCase ? 'i' : '')))) === null || _stringified$match === void 0 ? void 0 : _stringified$match.length) !== null && _stringified$match$le !== void 0 ? _stringified$match$le : 0;
|
|
1589
|
-
return counter === 1;
|
|
1590
|
-
}
|
|
1591
|
-
}, {
|
|
1592
|
-
key: "checkInArray",
|
|
1593
|
-
value: function checkInArray(attribute, value, parameters) {
|
|
1594
|
-
var _this$validator$getVa2;
|
|
1595
|
-
var unparsed = this.validator.getPrimaryAttribute(parameters[0]);
|
|
1596
|
-
if (!unparsed.includes('*')) {
|
|
1597
|
-
return false;
|
|
654
|
+
pattern += '\\' + char;
|
|
1598
655
|
}
|
|
1599
|
-
var data = (_this$validator$getVa2 = this.validator.getValue(unparsed.split('.*')[0])) !== null && _this$validator$getVa2 !== void 0 ? _this$validator$getVa2 : {};
|
|
1600
|
-
return Object.values(flattenObject(data)).some(function (item) {
|
|
1601
|
-
return item == value;
|
|
1602
|
-
});
|
|
1603
656
|
}
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
var _loop = function _loop() {
|
|
1613
|
-
var item = _Object$values[_i2];
|
|
1614
|
-
if (!parameters.some(function (parameter) {
|
|
1615
|
-
return parameter == item;
|
|
1616
|
-
})) {
|
|
1617
|
-
return {
|
|
1618
|
-
v: false
|
|
1619
|
-
};
|
|
1620
|
-
}
|
|
1621
|
-
};
|
|
1622
|
-
for (var _i2 = 0, _Object$values = Object.values(value); _i2 < _Object$values.length; _i2++) {
|
|
1623
|
-
var _ret = _loop();
|
|
1624
|
-
if (_typeof(_ret) === "object") return _ret.v;
|
|
1625
|
-
}
|
|
657
|
+
pattern += '$';
|
|
658
|
+
return new RegExp(pattern).test(value);
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
// Array / Object
|
|
662
|
+
checkDistinct(attribute, value, parameters) {
|
|
663
|
+
const unparsed = this.validator.getPrimaryAttribute(attribute);
|
|
664
|
+
if (!unparsed.includes('*')) {
|
|
1626
665
|
return true;
|
|
1627
666
|
}
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
667
|
+
const index = unparsed.indexOf('*');
|
|
668
|
+
const parentPath = unparsed.substring(0, index - 1);
|
|
669
|
+
let stringified;
|
|
670
|
+
if (this.#distinctCache.hasOwnProperty(parentPath)) {
|
|
671
|
+
stringified = this.#distinctCache[parentPath];
|
|
672
|
+
} else {
|
|
673
|
+
stringified = JSON.stringify(flattenObject(this.validator.getValue(parentPath) ?? {}));
|
|
674
|
+
this.#distinctCache[parentPath] = stringified;
|
|
675
|
+
}
|
|
676
|
+
const ignoreCase = parameters.includes('ignore_case');
|
|
677
|
+
const isStrict = !ignoreCase && parameters.includes('strict');
|
|
678
|
+
const escapedValue = escapeRegExp(String(value));
|
|
679
|
+
let pattern = `"${escapeRegExp(unparsed.substring(index)).replaceAll('\\*', '[^."]+')}":`;
|
|
680
|
+
let counter = 0;
|
|
681
|
+
if (isStrict) {
|
|
682
|
+
if (typeof value === 'string') {
|
|
683
|
+
pattern += `"${escapedValue}"`;
|
|
684
|
+
} else {
|
|
685
|
+
pattern += `${escapedValue}`;
|
|
1640
686
|
}
|
|
1641
|
-
|
|
687
|
+
} else {
|
|
688
|
+
pattern += `(${escapedValue}|"${escapedValue}")`;
|
|
1642
689
|
}
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
690
|
+
pattern += '[,}]+';
|
|
691
|
+
counter += stringified.match(new RegExp(pattern, 'g' + (ignoreCase ? 'i' : '')))?.length ?? 0;
|
|
692
|
+
return counter === 1;
|
|
693
|
+
}
|
|
694
|
+
checkInArray(attribute, value, parameters) {
|
|
695
|
+
const unparsed = this.validator.getPrimaryAttribute(parameters[0]);
|
|
696
|
+
if (!unparsed.includes('*')) {
|
|
1649
697
|
return false;
|
|
1650
698
|
}
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
1658
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
1659
|
-
case 0:
|
|
1660
|
-
result = this.checkMimes(attribute, value, ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'svg', 'webp']);
|
|
1661
|
-
if (!(!result || typeof FileReader === 'undefined')) {
|
|
1662
|
-
_context2.next = 3;
|
|
1663
|
-
break;
|
|
1664
|
-
}
|
|
1665
|
-
return _context2.abrupt("return", result);
|
|
1666
|
-
case 3:
|
|
1667
|
-
_context2.next = 5;
|
|
1668
|
-
return new Promise(function (resolve, reject) {
|
|
1669
|
-
var reader = new FileReader();
|
|
1670
|
-
reader.onload = function (event) {
|
|
1671
|
-
return resolve(event.target.result);
|
|
1672
|
-
};
|
|
1673
|
-
reader.onerror = reject;
|
|
1674
|
-
reader.readAsDataURL(value);
|
|
1675
|
-
}).then( /*#__PURE__*/function () {
|
|
1676
|
-
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(data) {
|
|
1677
|
-
var image;
|
|
1678
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1679
|
-
while (1) switch (_context.prev = _context.next) {
|
|
1680
|
-
case 0:
|
|
1681
|
-
image = new Image();
|
|
1682
|
-
image.src = data;
|
|
1683
|
-
_context.next = 4;
|
|
1684
|
-
return image.decode();
|
|
1685
|
-
case 4:
|
|
1686
|
-
_classPrivateFieldGet(_this, _imageCache)[attribute] = image;
|
|
1687
|
-
case 5:
|
|
1688
|
-
case "end":
|
|
1689
|
-
return _context.stop();
|
|
1690
|
-
}
|
|
1691
|
-
}, _callee);
|
|
1692
|
-
}));
|
|
1693
|
-
return function (_x4) {
|
|
1694
|
-
return _ref3.apply(this, arguments);
|
|
1695
|
-
};
|
|
1696
|
-
}()).catch(function () {
|
|
1697
|
-
result = false;
|
|
1698
|
-
});
|
|
1699
|
-
case 5:
|
|
1700
|
-
return _context2.abrupt("return", result);
|
|
1701
|
-
case 6:
|
|
1702
|
-
case "end":
|
|
1703
|
-
return _context2.stop();
|
|
1704
|
-
}
|
|
1705
|
-
}, _callee2, this);
|
|
1706
|
-
}));
|
|
1707
|
-
function checkImage(_x, _x2, _x3) {
|
|
1708
|
-
return _checkImage.apply(this, arguments);
|
|
1709
|
-
}
|
|
1710
|
-
return checkImage;
|
|
1711
|
-
}()
|
|
1712
|
-
}, {
|
|
1713
|
-
key: "checkDimensions",
|
|
1714
|
-
value: function () {
|
|
1715
|
-
var _checkDimensions = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(attribute, value, parameters) {
|
|
1716
|
-
var constraints, _iterator9, _step9, parameter, _parameter$split, _parameter$split2, key, _value2, _value2$split$map, _value2$split$map2, numerator, denominator, image, width, height;
|
|
1717
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
1718
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
1719
|
-
case 0:
|
|
1720
|
-
if (!(!this.checkImage(attribute, value) || !_classPrivateFieldGet(this, _imageCache).hasOwnProperty(attribute))) {
|
|
1721
|
-
_context3.next = 2;
|
|
1722
|
-
break;
|
|
1723
|
-
}
|
|
1724
|
-
return _context3.abrupt("return", false);
|
|
1725
|
-
case 2:
|
|
1726
|
-
constraints = {};
|
|
1727
|
-
_iterator9 = _createForOfIteratorHelper(parameters);
|
|
1728
|
-
try {
|
|
1729
|
-
for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
|
|
1730
|
-
parameter = _step9.value;
|
|
1731
|
-
_parameter$split = parameter.split('=', 2), _parameter$split2 = _slicedToArray(_parameter$split, 2), key = _parameter$split2[0], _value2 = _parameter$split2[1];
|
|
1732
|
-
if (key === 'ratio' && _value2.includes('/')) {
|
|
1733
|
-
_value2$split$map = _value2.split('/', 2).map(function (part) {
|
|
1734
|
-
return parseFloat(part, 10);
|
|
1735
|
-
}), _value2$split$map2 = _slicedToArray(_value2$split$map, 2), numerator = _value2$split$map2[0], denominator = _value2$split$map2[1];
|
|
1736
|
-
constraints[key] = numerator / denominator;
|
|
1737
|
-
} else {
|
|
1738
|
-
constraints[key] = parseFloat(_value2, 10);
|
|
1739
|
-
}
|
|
1740
|
-
}
|
|
1741
|
-
} catch (err) {
|
|
1742
|
-
_iterator9.e(err);
|
|
1743
|
-
} finally {
|
|
1744
|
-
_iterator9.f();
|
|
1745
|
-
}
|
|
1746
|
-
image = _classPrivateFieldGet(this, _imageCache)[attribute];
|
|
1747
|
-
width = image.naturalWidth;
|
|
1748
|
-
height = image.naturalHeight;
|
|
1749
|
-
if (!(constraints.hasOwnProperty('width') && constraints.width !== width || constraints.hasOwnProperty('height') && constraints.height !== height || constraints.hasOwnProperty('min_width') && constraints.min_width > width || constraints.hasOwnProperty('min_height') && constraints.min_height > height || constraints.hasOwnProperty('max_width') && constraints.max_width < width || constraints.hasOwnProperty('max_height') && constraints.max_height < height)) {
|
|
1750
|
-
_context3.next = 10;
|
|
1751
|
-
break;
|
|
1752
|
-
}
|
|
1753
|
-
return _context3.abrupt("return", false);
|
|
1754
|
-
case 10:
|
|
1755
|
-
if (!constraints.hasOwnProperty('ratio')) {
|
|
1756
|
-
_context3.next = 12;
|
|
1757
|
-
break;
|
|
1758
|
-
}
|
|
1759
|
-
return _context3.abrupt("return", Math.abs(constraints.ratio - width / height) <= 1 / (Math.max(width, height) + 1));
|
|
1760
|
-
case 12:
|
|
1761
|
-
return _context3.abrupt("return", true);
|
|
1762
|
-
case 13:
|
|
1763
|
-
case "end":
|
|
1764
|
-
return _context3.stop();
|
|
1765
|
-
}
|
|
1766
|
-
}, _callee3, this);
|
|
1767
|
-
}));
|
|
1768
|
-
function checkDimensions(_x5, _x6, _x7) {
|
|
1769
|
-
return _checkDimensions.apply(this, arguments);
|
|
1770
|
-
}
|
|
1771
|
-
return checkDimensions;
|
|
1772
|
-
}() // Miscellaneous
|
|
1773
|
-
}, {
|
|
1774
|
-
key: "checkEmail",
|
|
1775
|
-
value: function checkEmail(attribute, value, parameters) {
|
|
1776
|
-
var firstRegex = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
1777
|
-
if (!firstRegex.test(value)) {
|
|
1778
|
-
var secondRegex = /^((?:[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]|[^\u0000-\u007F])+@(?:[a-zA-Z0-9]|[^\u0000-\u007F])(?:(?:[a-zA-Z0-9-]|[^\u0000-\u007F]){0,61}(?:[a-zA-Z0-9]|[^\u0000-\u007F]))?(?:\.(?:[a-zA-Z0-9]|[^\u0000-\u007F])(?:(?:[a-zA-Z0-9-]|[^\u0000-\u007F]){0,61}(?:[a-zA-Z0-9]|[^\u0000-\u007F]))?)+)*$/;
|
|
1779
|
-
return secondRegex.test(value);
|
|
1780
|
-
}
|
|
1781
|
-
return true;
|
|
699
|
+
const data = this.validator.getValue(unparsed.split('.*')[0]) ?? {};
|
|
700
|
+
return Object.values(flattenObject(data)).some(item => item == value);
|
|
701
|
+
}
|
|
702
|
+
checkIn(attribute, value, parameters) {
|
|
703
|
+
if (!(this.checkArray(attribute, value) && this.validator.hasRule(attribute, 'array'))) {
|
|
704
|
+
return parameters.some(parameter => parameter == value);
|
|
1782
705
|
}
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
value: function checkJson(attribute, value, parameters) {
|
|
1786
|
-
try {
|
|
1787
|
-
JSON.parse(value);
|
|
1788
|
-
} catch (error) {
|
|
706
|
+
for (const item of Object.values(value)) {
|
|
707
|
+
if (!parameters.some(parameter => parameter == item)) {
|
|
1789
708
|
return false;
|
|
1790
709
|
}
|
|
1791
|
-
return true;
|
|
1792
710
|
}
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
for (var _i3 = 0, _Object$entries = Object.entries(separators); _i3 < _Object$entries.length; _i3++) {
|
|
1804
|
-
var _Object$entries$_i = _slicedToArray(_Object$entries[_i3], 2);
|
|
1805
|
-
separator = _Object$entries$_i[0];
|
|
1806
|
-
digits = _Object$entries$_i[1];
|
|
1807
|
-
if (value.includes(separator)) {
|
|
1808
|
-
break;
|
|
1809
|
-
}
|
|
1810
|
-
}
|
|
1811
|
-
var blocks = value.split(separator);
|
|
1812
|
-
if (blocks.length !== 12 / digits) {
|
|
1813
|
-
return false;
|
|
1814
|
-
}
|
|
1815
|
-
var _iterator10 = _createForOfIteratorHelper(blocks),
|
|
1816
|
-
_step10;
|
|
1817
|
-
try {
|
|
1818
|
-
for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
|
|
1819
|
-
var block = _step10.value;
|
|
1820
|
-
if (!new RegExp('^[0-9a-f]{' + digits + '}$', 'i').test(block)) {
|
|
1821
|
-
return false;
|
|
1822
|
-
}
|
|
1823
|
-
}
|
|
1824
|
-
} catch (err) {
|
|
1825
|
-
_iterator10.e(err);
|
|
1826
|
-
} finally {
|
|
1827
|
-
_iterator10.f();
|
|
1828
|
-
}
|
|
1829
|
-
return true;
|
|
711
|
+
return true;
|
|
712
|
+
}
|
|
713
|
+
checkNotIn(attribute, value, parameters) {
|
|
714
|
+
return !this.checkIn(attribute, value, parameters);
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
// File
|
|
718
|
+
checkMimetypes(attribute, value, parameters) {
|
|
719
|
+
if (this.checkFile(attribute, value)) {
|
|
720
|
+
return parameters.includes(value.type);
|
|
1830
721
|
}
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
}
|
|
1837
|
-
var blocks = String(value).split('.');
|
|
1838
|
-
if (blocks.length !== 4) {
|
|
1839
|
-
return false;
|
|
1840
|
-
}
|
|
1841
|
-
var _iterator11 = _createForOfIteratorHelper(blocks),
|
|
1842
|
-
_step11;
|
|
1843
|
-
try {
|
|
1844
|
-
for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
|
|
1845
|
-
var block = _step11.value;
|
|
1846
|
-
if (block < 0 || block > 255) {
|
|
1847
|
-
return false;
|
|
1848
|
-
}
|
|
1849
|
-
}
|
|
1850
|
-
} catch (err) {
|
|
1851
|
-
_iterator11.e(err);
|
|
1852
|
-
} finally {
|
|
1853
|
-
_iterator11.f();
|
|
1854
|
-
}
|
|
1855
|
-
return true;
|
|
722
|
+
return false;
|
|
723
|
+
}
|
|
724
|
+
checkMimes(attribute, value, parameters) {
|
|
725
|
+
if (this.checkFile(attribute, value)) {
|
|
726
|
+
return parameters.includes(value.name.split('.').pop().toLowerCase());
|
|
1856
727
|
}
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
}
|
|
1864
|
-
var blocks = value.split(':');
|
|
1865
|
-
if (blocks.length < 3 || blocks.length > 8) {
|
|
1866
|
-
return false;
|
|
1867
|
-
}
|
|
1868
|
-
var _iterator12 = _createForOfIteratorHelper(blocks),
|
|
1869
|
-
_step12;
|
|
1870
|
-
try {
|
|
1871
|
-
for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
|
|
1872
|
-
var block = _step12.value;
|
|
1873
|
-
if (block !== '' && !/^[0-9a-f]{1,4}$/i.test(block)) {
|
|
1874
|
-
return false;
|
|
1875
|
-
}
|
|
1876
|
-
}
|
|
1877
|
-
} catch (err) {
|
|
1878
|
-
_iterator12.e(err);
|
|
1879
|
-
} finally {
|
|
1880
|
-
_iterator12.f();
|
|
1881
|
-
}
|
|
1882
|
-
return true;
|
|
728
|
+
return false;
|
|
729
|
+
}
|
|
730
|
+
async checkImage(attribute, value, parameters) {
|
|
731
|
+
let result = this.checkMimes(attribute, value, ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'svg', 'webp']);
|
|
732
|
+
if (!result || typeof FileReader === 'undefined') {
|
|
733
|
+
return result;
|
|
1883
734
|
}
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
return
|
|
735
|
+
await new Promise((resolve, reject) => {
|
|
736
|
+
const reader = new FileReader();
|
|
737
|
+
reader.onload = event => resolve(event.target.result);
|
|
738
|
+
reader.onerror = reject;
|
|
739
|
+
reader.readAsDataURL(value);
|
|
740
|
+
}).then(async data => {
|
|
741
|
+
const image = new Image();
|
|
742
|
+
image.src = data;
|
|
743
|
+
await image.decode();
|
|
744
|
+
this.#imageCache[attribute] = image;
|
|
745
|
+
}).catch(() => {
|
|
746
|
+
result = false;
|
|
747
|
+
});
|
|
748
|
+
return result;
|
|
749
|
+
}
|
|
750
|
+
async checkDimensions(attribute, value, parameters) {
|
|
751
|
+
if (!this.checkImage(attribute, value) || !this.#imageCache.hasOwnProperty(attribute)) {
|
|
752
|
+
return false;
|
|
1902
753
|
}
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
754
|
+
const constraints = {};
|
|
755
|
+
for (const parameter of parameters) {
|
|
756
|
+
const [key, value] = parameter.split('=', 2);
|
|
757
|
+
if (key === 'ratio' && value.includes('/')) {
|
|
758
|
+
const [numerator, denominator] = value.split('/', 2).map(part => parseFloat(part, 10));
|
|
759
|
+
constraints[key] = numerator / denominator;
|
|
760
|
+
} else {
|
|
761
|
+
constraints[key] = parseFloat(value, 10);
|
|
1910
762
|
}
|
|
1911
|
-
return true;
|
|
1912
763
|
}
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
764
|
+
const image = this.#imageCache[attribute];
|
|
765
|
+
const width = image.naturalWidth;
|
|
766
|
+
const height = image.naturalHeight;
|
|
767
|
+
if (constraints.hasOwnProperty('width') && constraints.width !== width || constraints.hasOwnProperty('height') && constraints.height !== height || constraints.hasOwnProperty('min_width') && constraints.min_width > width || constraints.hasOwnProperty('min_height') && constraints.min_height > height || constraints.hasOwnProperty('max_width') && constraints.max_width < width || constraints.hasOwnProperty('max_height') && constraints.max_height < height) {
|
|
768
|
+
return false;
|
|
1917
769
|
}
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
value: function checkUuid(attribute, value, parameters) {
|
|
1921
|
-
return /[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}/.test(value);
|
|
770
|
+
if (constraints.hasOwnProperty('ratio')) {
|
|
771
|
+
return Math.abs(constraints.ratio - width / height) <= 1 / (Math.max(width, height) + 1);
|
|
1922
772
|
}
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
}();
|
|
773
|
+
return true;
|
|
774
|
+
}
|
|
1926
775
|
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
776
|
+
// Miscellaneous
|
|
777
|
+
checkEmail(attribute, value, parameters) {
|
|
778
|
+
const firstRegex = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
779
|
+
if (!firstRegex.test(value)) {
|
|
780
|
+
const secondRegex = /^((?:[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]|[^\u0000-\u007F])+@(?:[a-zA-Z0-9]|[^\u0000-\u007F])(?:(?:[a-zA-Z0-9-]|[^\u0000-\u007F]){0,61}(?:[a-zA-Z0-9]|[^\u0000-\u007F]))?(?:\.(?:[a-zA-Z0-9]|[^\u0000-\u007F])(?:(?:[a-zA-Z0-9-]|[^\u0000-\u007F]){0,61}(?:[a-zA-Z0-9]|[^\u0000-\u007F]))?)+)*$/;
|
|
781
|
+
return secondRegex.test(value);
|
|
782
|
+
}
|
|
783
|
+
return true;
|
|
1935
784
|
}
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
}, {
|
|
1942
|
-
key: "values",
|
|
1943
|
-
value: function values() {
|
|
1944
|
-
return Object.values(_classPrivateFieldGet(this, _data$1));
|
|
1945
|
-
}
|
|
1946
|
-
}, {
|
|
1947
|
-
key: "entries",
|
|
1948
|
-
value: function entries() {
|
|
1949
|
-
return Object.entries(_classPrivateFieldGet(this, _data$1));
|
|
1950
|
-
}
|
|
1951
|
-
}, {
|
|
1952
|
-
key: "add",
|
|
1953
|
-
value: function add(key, message) {
|
|
1954
|
-
if (_classPrivateFieldGet(this, _data$1).hasOwnProperty(key)) {
|
|
1955
|
-
_classPrivateFieldGet(this, _data$1)[key].push(message);
|
|
1956
|
-
} else {
|
|
1957
|
-
_classPrivateFieldGet(this, _data$1)[key] = [message];
|
|
1958
|
-
}
|
|
1959
|
-
}
|
|
1960
|
-
}, {
|
|
1961
|
-
key: "get",
|
|
1962
|
-
value: function get(key) {
|
|
1963
|
-
if (!key.includes('*')) {
|
|
1964
|
-
return _classPrivateFieldGet(this, _data$1).hasOwnProperty(key) ? _classPrivateFieldGet(this, _data$1)[key] : {};
|
|
1965
|
-
}
|
|
1966
|
-
var pattern = new RegExp('^' + key.replaceAll('*', '.*?') + '$');
|
|
1967
|
-
var result = {};
|
|
1968
|
-
var _iterator = _createForOfIteratorHelper(this.entries()),
|
|
1969
|
-
_step;
|
|
1970
|
-
try {
|
|
1971
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
1972
|
-
var _step$value = _slicedToArray(_step.value, 2),
|
|
1973
|
-
_key = _step$value[0],
|
|
1974
|
-
value = _step$value[1];
|
|
1975
|
-
if (pattern.test(_key)) {
|
|
1976
|
-
result[_key] = value;
|
|
1977
|
-
}
|
|
1978
|
-
}
|
|
1979
|
-
} catch (err) {
|
|
1980
|
-
_iterator.e(err);
|
|
1981
|
-
} finally {
|
|
1982
|
-
_iterator.f();
|
|
1983
|
-
}
|
|
1984
|
-
return result;
|
|
785
|
+
checkJson(attribute, value, parameters) {
|
|
786
|
+
try {
|
|
787
|
+
JSON.parse(value);
|
|
788
|
+
} catch (error) {
|
|
789
|
+
return false;
|
|
1985
790
|
}
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
791
|
+
return true;
|
|
792
|
+
}
|
|
793
|
+
checkMacAddress(attribute, value, parameters) {
|
|
794
|
+
value = String(value);
|
|
795
|
+
const separators = {
|
|
796
|
+
'-': 2,
|
|
797
|
+
':': 2,
|
|
798
|
+
'.': 4
|
|
799
|
+
};
|
|
800
|
+
let separator, digits;
|
|
801
|
+
for ([separator, digits] of Object.entries(separators)) {
|
|
802
|
+
if (value.includes(separator)) {
|
|
803
|
+
break;
|
|
1992
804
|
}
|
|
1993
|
-
return '';
|
|
1994
|
-
}
|
|
1995
|
-
}, {
|
|
1996
|
-
key: "has",
|
|
1997
|
-
value: function has(key) {
|
|
1998
|
-
return this.first(key) !== '';
|
|
1999
|
-
}
|
|
2000
|
-
}, {
|
|
2001
|
-
key: "messages",
|
|
2002
|
-
value: function messages() {
|
|
2003
|
-
return _classPrivateFieldGet(this, _data$1);
|
|
2004
|
-
}
|
|
2005
|
-
}, {
|
|
2006
|
-
key: "all",
|
|
2007
|
-
value: function all() {
|
|
2008
|
-
var result = [];
|
|
2009
|
-
this.values().forEach(function (messages) {
|
|
2010
|
-
return result.push.apply(result, _toConsumableArray(messages));
|
|
2011
|
-
});
|
|
2012
|
-
return result;
|
|
2013
805
|
}
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
var count = 0;
|
|
2018
|
-
this.values().forEach(function (messages) {
|
|
2019
|
-
return count += messages.length;
|
|
2020
|
-
});
|
|
2021
|
-
return count;
|
|
2022
|
-
}
|
|
2023
|
-
}, {
|
|
2024
|
-
key: "isEmpty",
|
|
2025
|
-
value: function isEmpty() {
|
|
2026
|
-
return this.keys().length === 0;
|
|
2027
|
-
}
|
|
2028
|
-
}, {
|
|
2029
|
-
key: "isNotEmpty",
|
|
2030
|
-
value: function isNotEmpty() {
|
|
2031
|
-
return !this.isEmpty();
|
|
806
|
+
const blocks = value.split(separator);
|
|
807
|
+
if (blocks.length !== 12 / digits) {
|
|
808
|
+
return false;
|
|
2032
809
|
}
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
var Lang = /*#__PURE__*/function () {
|
|
2038
|
-
function Lang() {
|
|
2039
|
-
_classCallCheck(this, Lang);
|
|
2040
|
-
}
|
|
2041
|
-
_createClass(Lang, null, [{
|
|
2042
|
-
key: "locale",
|
|
2043
|
-
value: function locale(_locale2) {
|
|
2044
|
-
_classStaticPrivateFieldSpecSet(this, Lang, _locale, _locale2);
|
|
2045
|
-
}
|
|
2046
|
-
}, {
|
|
2047
|
-
key: "setMessages",
|
|
2048
|
-
value: function setMessages(locale, messages) {
|
|
2049
|
-
_classStaticPrivateFieldSpecGet(this, Lang, _messages)[locale] = flattenObject(messages);
|
|
2050
|
-
}
|
|
2051
|
-
}, {
|
|
2052
|
-
key: "get",
|
|
2053
|
-
value: function get(path) {
|
|
2054
|
-
if (_classStaticPrivateFieldSpecGet(this, Lang, _messages)[_classStaticPrivateFieldSpecGet(this, Lang, _locale)] && _classStaticPrivateFieldSpecGet(this, Lang, _messages)[_classStaticPrivateFieldSpecGet(this, Lang, _locale)][path]) {
|
|
2055
|
-
return _classStaticPrivateFieldSpecGet(this, Lang, _messages)[_classStaticPrivateFieldSpecGet(this, Lang, _locale)][path];
|
|
2056
|
-
}
|
|
2057
|
-
return;
|
|
2058
|
-
}
|
|
2059
|
-
}, {
|
|
2060
|
-
key: "has",
|
|
2061
|
-
value: function has(path) {
|
|
2062
|
-
return typeof this.get(path) === 'undefined' ? false : true;
|
|
2063
|
-
}
|
|
2064
|
-
}, {
|
|
2065
|
-
key: "set",
|
|
2066
|
-
value: function set(path, value) {
|
|
2067
|
-
if (isPlainObject(value)) {
|
|
2068
|
-
Object.assign(_classStaticPrivateFieldSpecGet(this, Lang, _messages)[_classStaticPrivateFieldSpecGet(this, Lang, _locale)], flattenObject(value, path));
|
|
2069
|
-
} else if (typeof value === 'string') {
|
|
2070
|
-
_classStaticPrivateFieldSpecGet(this, Lang, _messages)[_classStaticPrivateFieldSpecGet(this, Lang, _locale)][path] = value;
|
|
810
|
+
for (const block of blocks) {
|
|
811
|
+
if (!new RegExp('^[0-9a-f]{' + digits + '}$', 'i').test(block)) {
|
|
812
|
+
return false;
|
|
2071
813
|
}
|
|
2072
814
|
}
|
|
2073
|
-
|
|
2074
|
-
return Lang;
|
|
2075
|
-
}();
|
|
2076
|
-
var _locale = {
|
|
2077
|
-
writable: true,
|
|
2078
|
-
value: void 0
|
|
2079
|
-
};
|
|
2080
|
-
var _messages = {
|
|
2081
|
-
writable: true,
|
|
2082
|
-
value: {}
|
|
2083
|
-
};
|
|
2084
|
-
|
|
2085
|
-
var Replacers = /*#__PURE__*/function () {
|
|
2086
|
-
function Replacers(validator) {
|
|
2087
|
-
_classCallCheck(this, Replacers);
|
|
2088
|
-
_defineProperty(this, "validator", void 0);
|
|
2089
|
-
this.validator = validator;
|
|
815
|
+
return true;
|
|
2090
816
|
}
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
Object.entries(data).forEach(function (_ref) {
|
|
2095
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
2096
|
-
key = _ref2[0],
|
|
2097
|
-
value = _ref2[1];
|
|
2098
|
-
return message = message.replaceAll(':' + key, value);
|
|
2099
|
-
});
|
|
2100
|
-
return message;
|
|
2101
|
-
}
|
|
2102
|
-
|
|
2103
|
-
// Numeric
|
|
2104
|
-
}, {
|
|
2105
|
-
key: "replaceDecimal",
|
|
2106
|
-
value: function replaceDecimal(message, attribute, rule, parameters) {
|
|
2107
|
-
return this.replace(message, {
|
|
2108
|
-
decimal: parameters.join('-')
|
|
2109
|
-
});
|
|
2110
|
-
}
|
|
2111
|
-
}, {
|
|
2112
|
-
key: "replaceMultipleOf",
|
|
2113
|
-
value: function replaceMultipleOf(message, attribute, rule, parameters) {
|
|
2114
|
-
return this.replace(message, {
|
|
2115
|
-
value: parameters[0]
|
|
2116
|
-
});
|
|
2117
|
-
}
|
|
2118
|
-
|
|
2119
|
-
// Agreement
|
|
2120
|
-
}, {
|
|
2121
|
-
key: "replaceAcceptedIf",
|
|
2122
|
-
value: function replaceAcceptedIf(message, attribute, rule, parameters) {
|
|
2123
|
-
return this.replace(message, {
|
|
2124
|
-
other: this.validator.getDisplayableAttribute(parameters[0]),
|
|
2125
|
-
value: this.validator.getDisplayableValue(parameters[0], this.validator.getValue(parameters[0]))
|
|
2126
|
-
});
|
|
2127
|
-
}
|
|
2128
|
-
}, {
|
|
2129
|
-
key: "replaceDeclinedIf",
|
|
2130
|
-
value: function replaceDeclinedIf(message, attribute, rule, parameters) {
|
|
2131
|
-
return this.replaceAcceptedIf(message, attribute, rule, parameters);
|
|
2132
|
-
}
|
|
2133
|
-
|
|
2134
|
-
// Existence
|
|
2135
|
-
}, {
|
|
2136
|
-
key: "replaceRequiredArrayKeys",
|
|
2137
|
-
value: function replaceRequiredArrayKeys(message, attribute, rule, parameters) {
|
|
2138
|
-
var _this = this;
|
|
2139
|
-
return this.replace(message, {
|
|
2140
|
-
values: parameters.map(function (value) {
|
|
2141
|
-
return _this.validator.getDisplayableValue(attribute, value);
|
|
2142
|
-
}).join(', ')
|
|
2143
|
-
});
|
|
817
|
+
checkIpv4(attribute, value, parameters) {
|
|
818
|
+
if (/[^\d.]/.test(value)) {
|
|
819
|
+
return false;
|
|
2144
820
|
}
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
return this.replaceAcceptedIf(message, attribute, rule, parameters);
|
|
2149
|
-
}
|
|
2150
|
-
}, {
|
|
2151
|
-
key: "replaceRequiredIfAccepted",
|
|
2152
|
-
value: function replaceRequiredIfAccepted(message, attribute, rule, parameters) {
|
|
2153
|
-
return this.replaceAcceptedIf(message, attribute, rule, parameters);
|
|
2154
|
-
}
|
|
2155
|
-
}, {
|
|
2156
|
-
key: "replaceRequiredUnless",
|
|
2157
|
-
value: function replaceRequiredUnless(message, attribute, rule, parameters) {
|
|
2158
|
-
var _this2 = this;
|
|
2159
|
-
return this.replace(message, {
|
|
2160
|
-
other: this.validator.getDisplayableAttribute(parameters[0]),
|
|
2161
|
-
values: parameters.slice(1).map(function (value) {
|
|
2162
|
-
return _this2.validator.getDisplayableValue(parameters[0], value);
|
|
2163
|
-
}).join(', ')
|
|
2164
|
-
});
|
|
821
|
+
const blocks = String(value).split('.');
|
|
822
|
+
if (blocks.length !== 4) {
|
|
823
|
+
return false;
|
|
2165
824
|
}
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
return this.replace(message, {
|
|
2171
|
-
values: parameters.map(function (value) {
|
|
2172
|
-
return _this3.validator.getDisplayableAttribute(value);
|
|
2173
|
-
}).join(' / ')
|
|
2174
|
-
});
|
|
825
|
+
for (const block of blocks) {
|
|
826
|
+
if (block < 0 || block > 255) {
|
|
827
|
+
return false;
|
|
828
|
+
}
|
|
2175
829
|
}
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
830
|
+
return true;
|
|
831
|
+
}
|
|
832
|
+
checkIpv6(attribute, value, parameters) {
|
|
833
|
+
value = String(value);
|
|
834
|
+
if (value.includes(':::') || value.split('::').length > 2) {
|
|
835
|
+
return false;
|
|
2180
836
|
}
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
return this.replaceRequiredWith(message, attribute, rule, parameters);
|
|
837
|
+
const blocks = value.split(':');
|
|
838
|
+
if (blocks.length < 3 || blocks.length > 8) {
|
|
839
|
+
return false;
|
|
2185
840
|
}
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
841
|
+
for (const block of blocks) {
|
|
842
|
+
if (block !== '' && !/^[0-9a-f]{1,4}$/i.test(block)) {
|
|
843
|
+
return false;
|
|
844
|
+
}
|
|
2190
845
|
}
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
value: function replaceMissingUnless(message, attribute, rule, parameters) {
|
|
2201
|
-
return this.replace(this.replaceRequiredUnless(message, attribute, rule, parameters), {
|
|
2202
|
-
value: this.validator.getDisplayableValue(parameters[0], parameters[1])
|
|
846
|
+
return true;
|
|
847
|
+
}
|
|
848
|
+
checkIp(attribute, value, parameters) {
|
|
849
|
+
return this.checkIpv4(attribute, value, parameters) || this.checkIpv6(attribute, value, parameters);
|
|
850
|
+
}
|
|
851
|
+
checkTimezone(attribute, value, parameters) {
|
|
852
|
+
try {
|
|
853
|
+
Intl.DateTimeFormat(undefined, {
|
|
854
|
+
timeZone: value
|
|
2203
855
|
});
|
|
856
|
+
} catch (error) {
|
|
857
|
+
if (String(error).toLowerCase().includes('invalid time zone')) {
|
|
858
|
+
return false;
|
|
859
|
+
}
|
|
2204
860
|
}
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
value: function replaceMissingWithAll(message, attribute, rule, parameters) {
|
|
2213
|
-
return this.replaceRequiredWith(message, attribute, rule, parameters);
|
|
2214
|
-
}
|
|
2215
|
-
|
|
2216
|
-
// Prohibition
|
|
2217
|
-
}, {
|
|
2218
|
-
key: "replaceProhibitedIf",
|
|
2219
|
-
value: function replaceProhibitedIf(message, attribute, rule, parameters) {
|
|
2220
|
-
return this.replaceAcceptedIf(message, attribute, rule, parameters);
|
|
2221
|
-
}
|
|
2222
|
-
}, {
|
|
2223
|
-
key: "replaceProhibitedUnless",
|
|
2224
|
-
value: function replaceProhibitedUnless(message, attribute, rule, parameters) {
|
|
2225
|
-
return this.replaceRequiredUnless(message, attribute, rule, parameters);
|
|
2226
|
-
}
|
|
2227
|
-
}, {
|
|
2228
|
-
key: "replaceProhibits",
|
|
2229
|
-
value: function replaceProhibits(message, attribute, rule, parameters) {
|
|
2230
|
-
var _this4 = this;
|
|
2231
|
-
return this.replace(message, {
|
|
2232
|
-
other: parameters.map(function (value) {
|
|
2233
|
-
return _this4.validator.getDisplayableAttribute(value);
|
|
2234
|
-
}).join(' / ')
|
|
2235
|
-
});
|
|
861
|
+
return true;
|
|
862
|
+
}
|
|
863
|
+
checkUrl(attribute, value, parameters) {
|
|
864
|
+
try {
|
|
865
|
+
new URL(value);
|
|
866
|
+
} catch (error) {
|
|
867
|
+
return false;
|
|
2236
868
|
}
|
|
869
|
+
return true;
|
|
870
|
+
}
|
|
871
|
+
checkUlid(attribute, value, parameters) {
|
|
872
|
+
return /[0-7][0-9A-HJKMNP-TV-Z]{25}/.test(value);
|
|
873
|
+
}
|
|
874
|
+
checkUuid(attribute, value, parameters) {
|
|
875
|
+
return /[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}/.test(value);
|
|
876
|
+
}
|
|
877
|
+
}
|
|
2237
878
|
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
879
|
+
class ErrorBag {
|
|
880
|
+
#data = {};
|
|
881
|
+
keys() {
|
|
882
|
+
return Object.keys(this.#data);
|
|
883
|
+
}
|
|
884
|
+
values() {
|
|
885
|
+
return Object.values(this.#data);
|
|
886
|
+
}
|
|
887
|
+
entries() {
|
|
888
|
+
return Object.entries(this.#data);
|
|
889
|
+
}
|
|
890
|
+
add(key, message) {
|
|
891
|
+
if (this.#data.hasOwnProperty(key)) {
|
|
892
|
+
this.#data[key].push(message);
|
|
893
|
+
} else {
|
|
894
|
+
this.#data[key] = [message];
|
|
2245
895
|
}
|
|
2246
|
-
}
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
return this.
|
|
2250
|
-
min: parameters[0]
|
|
2251
|
-
});
|
|
896
|
+
}
|
|
897
|
+
get(key) {
|
|
898
|
+
if (!key.includes('*')) {
|
|
899
|
+
return this.#data.hasOwnProperty(key) ? this.#data[key] : {};
|
|
2252
900
|
}
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
}
|
|
901
|
+
const pattern = new RegExp('^' + key.replaceAll('*', '.*?') + '$');
|
|
902
|
+
const result = {};
|
|
903
|
+
for (const [key, value] of this.entries()) {
|
|
904
|
+
if (pattern.test(key)) {
|
|
905
|
+
result[key] = value;
|
|
906
|
+
}
|
|
2259
907
|
}
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
max: parameters[1]
|
|
2266
|
-
});
|
|
908
|
+
return result;
|
|
909
|
+
}
|
|
910
|
+
first(key) {
|
|
911
|
+
for (const message of Object.values(this.get(key))) {
|
|
912
|
+
return Array.isArray(message) ? message[0] : message;
|
|
2267
913
|
}
|
|
914
|
+
return '';
|
|
915
|
+
}
|
|
916
|
+
has(key) {
|
|
917
|
+
return this.first(key) !== '';
|
|
918
|
+
}
|
|
919
|
+
messages() {
|
|
920
|
+
return this.#data;
|
|
921
|
+
}
|
|
922
|
+
all() {
|
|
923
|
+
const result = [];
|
|
924
|
+
this.values().forEach(messages => result.push(...messages));
|
|
925
|
+
return result;
|
|
926
|
+
}
|
|
927
|
+
count() {
|
|
928
|
+
let count = 0;
|
|
929
|
+
this.values().forEach(messages => count += messages.length);
|
|
930
|
+
return count;
|
|
931
|
+
}
|
|
932
|
+
isEmpty() {
|
|
933
|
+
return this.keys().length === 0;
|
|
934
|
+
}
|
|
935
|
+
isNotEmpty() {
|
|
936
|
+
return !this.isEmpty();
|
|
937
|
+
}
|
|
938
|
+
}
|
|
2268
939
|
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
}
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
return this
|
|
2281
|
-
}
|
|
2282
|
-
}, {
|
|
2283
|
-
key: "replaceMaxDigits",
|
|
2284
|
-
value: function replaceMaxDigits(message, attribute, rule, parameters) {
|
|
2285
|
-
return this.replaceMax(message, attribute, rule, parameters);
|
|
2286
|
-
}
|
|
2287
|
-
}, {
|
|
2288
|
-
key: "replaceDigitsBetween",
|
|
2289
|
-
value: function replaceDigitsBetween(message, attribute, rule, parameters) {
|
|
2290
|
-
return this.replaceBetween(message, attribute, rule, parameters);
|
|
940
|
+
class Lang {
|
|
941
|
+
static #locale;
|
|
942
|
+
static #messages = {};
|
|
943
|
+
static locale(locale) {
|
|
944
|
+
this.#locale = locale;
|
|
945
|
+
}
|
|
946
|
+
static setMessages(locale, messages) {
|
|
947
|
+
this.#messages[locale] = flattenObject(messages);
|
|
948
|
+
}
|
|
949
|
+
static get(path) {
|
|
950
|
+
if (this.#messages[this.#locale] && this.#messages[this.#locale][path]) {
|
|
951
|
+
return this.#messages[this.#locale][path];
|
|
2291
952
|
}
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
return this.replaceRequiredArrayKeys(message, attribute, rule, parameters);
|
|
2303
|
-
}
|
|
2304
|
-
}, {
|
|
2305
|
-
key: "replaceEndsWith",
|
|
2306
|
-
value: function replaceEndsWith(message, attribute, rule, parameters) {
|
|
2307
|
-
return this.replaceRequiredArrayKeys(message, attribute, rule, parameters);
|
|
2308
|
-
}
|
|
2309
|
-
}, {
|
|
2310
|
-
key: "replaceDoesntEndWith",
|
|
2311
|
-
value: function replaceDoesntEndWith(message, attribute, rule, parameters) {
|
|
2312
|
-
return this.replaceRequiredArrayKeys(message, attribute, rule, parameters);
|
|
953
|
+
return;
|
|
954
|
+
}
|
|
955
|
+
static has(path) {
|
|
956
|
+
return typeof this.get(path) === 'undefined' ? false : true;
|
|
957
|
+
}
|
|
958
|
+
static set(path, value) {
|
|
959
|
+
if (isPlainObject(value)) {
|
|
960
|
+
Object.assign(this.#messages[this.#locale], flattenObject(value, path));
|
|
961
|
+
} else if (typeof value === 'string') {
|
|
962
|
+
this.#messages[this.#locale][path] = value;
|
|
2313
963
|
}
|
|
964
|
+
}
|
|
965
|
+
}
|
|
2314
966
|
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
}
|
|
2327
|
-
key: "replaceGt",
|
|
2328
|
-
value: function replaceGt(message, attribute, rule, parameters) {
|
|
2329
|
-
var value = this.validator.getValue(parameters[0]);
|
|
2330
|
-
return this.replace(message, {
|
|
2331
|
-
value: value ? this.validator.getSize(parameters[0], value) : this.validator.getDisplayableAttribute(parameters[0])
|
|
2332
|
-
});
|
|
2333
|
-
}
|
|
2334
|
-
}, {
|
|
2335
|
-
key: "replaceGte",
|
|
2336
|
-
value: function replaceGte(message, attribute, rule, parameters) {
|
|
2337
|
-
return this.replaceGt(message, attribute, rule, parameters);
|
|
2338
|
-
}
|
|
2339
|
-
}, {
|
|
2340
|
-
key: "replaceLt",
|
|
2341
|
-
value: function replaceLt(message, attribute, rule, parameters) {
|
|
2342
|
-
return this.replaceGt(message, attribute, rule, parameters);
|
|
2343
|
-
}
|
|
2344
|
-
}, {
|
|
2345
|
-
key: "replaceLte",
|
|
2346
|
-
value: function replaceLte(message, attribute, rule, parameters) {
|
|
2347
|
-
return this.replaceGt(message, attribute, rule, parameters);
|
|
2348
|
-
}
|
|
967
|
+
class Replacers {
|
|
968
|
+
validator;
|
|
969
|
+
constructor(validator) {
|
|
970
|
+
this.validator = validator;
|
|
971
|
+
}
|
|
972
|
+
replace(message, data) {
|
|
973
|
+
Object.entries(data).forEach(_ref => {
|
|
974
|
+
let [key, value] = _ref;
|
|
975
|
+
return message = message.replaceAll(':' + key, value);
|
|
976
|
+
});
|
|
977
|
+
return message;
|
|
978
|
+
}
|
|
2349
979
|
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
value: function replaceAfterOrEqual(message, attribute, rule, parameters) {
|
|
2362
|
-
return this.replaceAfter(message, attribute, rule, parameters);
|
|
2363
|
-
}
|
|
2364
|
-
}, {
|
|
2365
|
-
key: "replaceBefore",
|
|
2366
|
-
value: function replaceBefore(message, attribute, rule, parameters) {
|
|
2367
|
-
return this.replaceAfter(message, attribute, rule, parameters);
|
|
2368
|
-
}
|
|
2369
|
-
}, {
|
|
2370
|
-
key: "replaceBeforeOrEqual",
|
|
2371
|
-
value: function replaceBeforeOrEqual(message, attribute, rule, parameters) {
|
|
2372
|
-
return this.replaceAfter(message, attribute, rule, parameters);
|
|
2373
|
-
}
|
|
2374
|
-
}, {
|
|
2375
|
-
key: "replaceDateEquals",
|
|
2376
|
-
value: function replaceDateEquals(message, attribute, rule, parameters) {
|
|
2377
|
-
return this.replaceAfter(message, attribute, rule, parameters);
|
|
2378
|
-
}
|
|
2379
|
-
}, {
|
|
2380
|
-
key: "replaceDateFormat",
|
|
2381
|
-
value: function replaceDateFormat(message, attribute, rule, parameters) {
|
|
2382
|
-
return this.replace(message, {
|
|
2383
|
-
format: parameters[0]
|
|
2384
|
-
});
|
|
2385
|
-
}
|
|
980
|
+
// Numeric
|
|
981
|
+
replaceDecimal(message, attribute, rule, parameters) {
|
|
982
|
+
return this.replace(message, {
|
|
983
|
+
decimal: parameters.join('-')
|
|
984
|
+
});
|
|
985
|
+
}
|
|
986
|
+
replaceMultipleOf(message, attribute, rule, parameters) {
|
|
987
|
+
return this.replace(message, {
|
|
988
|
+
value: parameters[0]
|
|
989
|
+
});
|
|
990
|
+
}
|
|
2386
991
|
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
}
|
|
2393
|
-
}
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
}
|
|
2398
|
-
}, {
|
|
2399
|
-
key: "replaceNotIn",
|
|
2400
|
-
value: function replaceNotIn(message, attribute, rule, parameters) {
|
|
2401
|
-
return this.replaceRequiredArrayKeys(message, attribute, rule, parameters);
|
|
2402
|
-
}
|
|
992
|
+
// Agreement
|
|
993
|
+
replaceAcceptedIf(message, attribute, rule, parameters) {
|
|
994
|
+
return this.replace(message, {
|
|
995
|
+
other: this.validator.getDisplayableAttribute(parameters[0]),
|
|
996
|
+
value: this.validator.getDisplayableValue(parameters[0], this.validator.getValue(parameters[0]))
|
|
997
|
+
});
|
|
998
|
+
}
|
|
999
|
+
replaceDeclinedIf(message, attribute, rule, parameters) {
|
|
1000
|
+
return this.replaceAcceptedIf(message, attribute, rule, parameters);
|
|
1001
|
+
}
|
|
2403
1002
|
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
}
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
1003
|
+
// Existence
|
|
1004
|
+
replaceRequiredArrayKeys(message, attribute, rule, parameters) {
|
|
1005
|
+
return this.replace(message, {
|
|
1006
|
+
values: parameters.map(value => this.validator.getDisplayableValue(attribute, value)).join(', ')
|
|
1007
|
+
});
|
|
1008
|
+
}
|
|
1009
|
+
replaceRequiredIf(message, attribute, rule, parameters) {
|
|
1010
|
+
return this.replaceAcceptedIf(message, attribute, rule, parameters);
|
|
1011
|
+
}
|
|
1012
|
+
replaceRequiredIfAccepted(message, attribute, rule, parameters) {
|
|
1013
|
+
return this.replaceAcceptedIf(message, attribute, rule, parameters);
|
|
1014
|
+
}
|
|
1015
|
+
replaceRequiredUnless(message, attribute, rule, parameters) {
|
|
1016
|
+
return this.replace(message, {
|
|
1017
|
+
other: this.validator.getDisplayableAttribute(parameters[0]),
|
|
1018
|
+
values: parameters.slice(1).map(value => this.validator.getDisplayableValue(parameters[0], value)).join(', ')
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
replaceRequiredWith(message, attribute, rule, parameters) {
|
|
1022
|
+
return this.replace(message, {
|
|
1023
|
+
values: parameters.map(value => this.validator.getDisplayableAttribute(value)).join(' / ')
|
|
1024
|
+
});
|
|
1025
|
+
}
|
|
1026
|
+
replaceRequiredWithAll(message, attribute, rule, parameters) {
|
|
1027
|
+
return this.replaceRequiredWith(message, attribute, rule, parameters);
|
|
1028
|
+
}
|
|
1029
|
+
replaceRequiredWithout(message, attribute, rule, parameters) {
|
|
1030
|
+
return this.replaceRequiredWith(message, attribute, rule, parameters);
|
|
1031
|
+
}
|
|
1032
|
+
replaceRequiredWithoutAll(message, attribute, rule, parameters) {
|
|
1033
|
+
return this.replaceRequiredWith(message, attribute, rule, parameters);
|
|
1034
|
+
}
|
|
2420
1035
|
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
var _errors = /*#__PURE__*/new WeakMap();
|
|
2429
|
-
var _implicitAttributes = /*#__PURE__*/new WeakMap();
|
|
2430
|
-
var _stopOnFirstFailure = /*#__PURE__*/new WeakMap();
|
|
2431
|
-
var _alwaysBail = /*#__PURE__*/new WeakMap();
|
|
2432
|
-
var Validator = /*#__PURE__*/function () {
|
|
2433
|
-
function Validator() {
|
|
2434
|
-
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2435
|
-
var rules = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2436
|
-
var messages = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
2437
|
-
var attributes = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
2438
|
-
var values = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
2439
|
-
_classCallCheck(this, Validator);
|
|
2440
|
-
_classPrivateFieldInitSpec(this, _data, {
|
|
2441
|
-
writable: true,
|
|
2442
|
-
value: void 0
|
|
1036
|
+
// Missing
|
|
1037
|
+
replaceMissingIf(message, attribute, rule, parameters) {
|
|
1038
|
+
return this.replaceAcceptedIf(message, attribute, rule, parameters);
|
|
1039
|
+
}
|
|
1040
|
+
replaceMissingUnless(message, attribute, rule, parameters) {
|
|
1041
|
+
return this.replace(this.replaceRequiredUnless(message, attribute, rule, parameters), {
|
|
1042
|
+
value: this.validator.getDisplayableValue(parameters[0], parameters[1])
|
|
2443
1043
|
});
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
1044
|
+
}
|
|
1045
|
+
replaceMissingWith(message, attribute, rule, parameters) {
|
|
1046
|
+
return this.replaceRequiredWith(message, attribute, rule, parameters);
|
|
1047
|
+
}
|
|
1048
|
+
replaceMissingWithAll(message, attribute, rule, parameters) {
|
|
1049
|
+
return this.replaceRequiredWith(message, attribute, rule, parameters);
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
// Prohibition
|
|
1053
|
+
replaceProhibitedIf(message, attribute, rule, parameters) {
|
|
1054
|
+
return this.replaceAcceptedIf(message, attribute, rule, parameters);
|
|
1055
|
+
}
|
|
1056
|
+
replaceProhibitedUnless(message, attribute, rule, parameters) {
|
|
1057
|
+
return this.replaceRequiredUnless(message, attribute, rule, parameters);
|
|
1058
|
+
}
|
|
1059
|
+
replaceProhibits(message, attribute, rule, parameters) {
|
|
1060
|
+
return this.replace(message, {
|
|
1061
|
+
other: parameters.map(value => this.validator.getDisplayableAttribute(value)).join(' / ')
|
|
2447
1062
|
});
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
// Size
|
|
1066
|
+
replaceSize(message, attribute, rule, parameters) {
|
|
1067
|
+
return this.replace(message, {
|
|
1068
|
+
size: parameters[0]
|
|
2451
1069
|
});
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
1070
|
+
}
|
|
1071
|
+
replaceMin(message, attribute, rule, parameters) {
|
|
1072
|
+
return this.replace(message, {
|
|
1073
|
+
min: parameters[0]
|
|
2455
1074
|
});
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
1075
|
+
}
|
|
1076
|
+
replaceMax(message, attribute, rule, parameters) {
|
|
1077
|
+
return this.replace(message, {
|
|
1078
|
+
max: parameters[0]
|
|
2459
1079
|
});
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
1080
|
+
}
|
|
1081
|
+
replaceBetween(message, attribute, rule, parameters) {
|
|
1082
|
+
return this.replace(message, {
|
|
1083
|
+
min: parameters[0],
|
|
1084
|
+
max: parameters[1]
|
|
2463
1085
|
});
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
// Digits
|
|
1089
|
+
replaceDigits(message, attribute, rule, parameters) {
|
|
1090
|
+
return this.replace(message, {
|
|
1091
|
+
digits: parameters[0]
|
|
2467
1092
|
});
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
1093
|
+
}
|
|
1094
|
+
replaceMinDigits(message, attribute, rule, parameters) {
|
|
1095
|
+
return this.replaceMin(message, attribute, rule, parameters);
|
|
1096
|
+
}
|
|
1097
|
+
replaceMaxDigits(message, attribute, rule, parameters) {
|
|
1098
|
+
return this.replaceMax(message, attribute, rule, parameters);
|
|
1099
|
+
}
|
|
1100
|
+
replaceDigitsBetween(message, attribute, rule, parameters) {
|
|
1101
|
+
return this.replaceBetween(message, attribute, rule, parameters);
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
// String
|
|
1105
|
+
replaceStartsWith(message, attribute, rule, parameters) {
|
|
1106
|
+
return this.replaceRequiredArrayKeys(message, attribute, rule, parameters);
|
|
1107
|
+
}
|
|
1108
|
+
replaceDoesntStartWith(message, attribute, rule, parameters) {
|
|
1109
|
+
return this.replaceRequiredArrayKeys(message, attribute, rule, parameters);
|
|
1110
|
+
}
|
|
1111
|
+
replaceEndsWith(message, attribute, rule, parameters) {
|
|
1112
|
+
return this.replaceRequiredArrayKeys(message, attribute, rule, parameters);
|
|
1113
|
+
}
|
|
1114
|
+
replaceDoesntEndWith(message, attribute, rule, parameters) {
|
|
1115
|
+
return this.replaceRequiredArrayKeys(message, attribute, rule, parameters);
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
// Compare values
|
|
1119
|
+
replaceSame(message, attribute, rule, parameters) {
|
|
1120
|
+
return this.replaceAcceptedIf(message, attribute, rule, parameters);
|
|
1121
|
+
}
|
|
1122
|
+
replaceDifferent(message, attribute, rule, parameters) {
|
|
1123
|
+
return this.replaceAcceptedIf(message, attribute, rule, parameters);
|
|
1124
|
+
}
|
|
1125
|
+
replaceGt(message, attribute, rule, parameters) {
|
|
1126
|
+
const value = this.validator.getValue(parameters[0]);
|
|
1127
|
+
return this.replace(message, {
|
|
1128
|
+
value: value ? this.validator.getSize(parameters[0], value) : this.validator.getDisplayableAttribute(parameters[0])
|
|
2471
1129
|
});
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
1130
|
+
}
|
|
1131
|
+
replaceGte(message, attribute, rule, parameters) {
|
|
1132
|
+
return this.replaceGt(message, attribute, rule, parameters);
|
|
1133
|
+
}
|
|
1134
|
+
replaceLt(message, attribute, rule, parameters) {
|
|
1135
|
+
return this.replaceGt(message, attribute, rule, parameters);
|
|
1136
|
+
}
|
|
1137
|
+
replaceLte(message, attribute, rule, parameters) {
|
|
1138
|
+
return this.replaceGt(message, attribute, rule, parameters);
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
// Dates
|
|
1142
|
+
replaceAfter(message, attribute, rule, parameters) {
|
|
1143
|
+
const other = parameters[0];
|
|
1144
|
+
return this.replace(message, {
|
|
1145
|
+
date: this.validator.hasAttribute(other) ? this.validator.getDisplayableAttribute(other) : other
|
|
2475
1146
|
});
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
1147
|
+
}
|
|
1148
|
+
replaceAfterOrEqual(message, attribute, rule, parameters) {
|
|
1149
|
+
return this.replaceAfter(message, attribute, rule, parameters);
|
|
1150
|
+
}
|
|
1151
|
+
replaceBefore(message, attribute, rule, parameters) {
|
|
1152
|
+
return this.replaceAfter(message, attribute, rule, parameters);
|
|
1153
|
+
}
|
|
1154
|
+
replaceBeforeOrEqual(message, attribute, rule, parameters) {
|
|
1155
|
+
return this.replaceAfter(message, attribute, rule, parameters);
|
|
1156
|
+
}
|
|
1157
|
+
replaceDateEquals(message, attribute, rule, parameters) {
|
|
1158
|
+
return this.replaceAfter(message, attribute, rule, parameters);
|
|
1159
|
+
}
|
|
1160
|
+
replaceDateFormat(message, attribute, rule, parameters) {
|
|
1161
|
+
return this.replace(message, {
|
|
1162
|
+
format: parameters[0]
|
|
2479
1163
|
});
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
// Array
|
|
1167
|
+
replaceInArray(message, attribute, rule, parameters) {
|
|
1168
|
+
return this.replaceAcceptedIf(message, attribute, rule, parameters);
|
|
1169
|
+
}
|
|
1170
|
+
replaceIn(message, attribute, rule, parameters) {
|
|
1171
|
+
return this.replaceRequiredArrayKeys(message, attribute, rule, parameters);
|
|
1172
|
+
}
|
|
1173
|
+
replaceNotIn(message, attribute, rule, parameters) {
|
|
1174
|
+
return this.replaceRequiredArrayKeys(message, attribute, rule, parameters);
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
// File
|
|
1178
|
+
replaceMimetypes(message, attribute, rule, parameters) {
|
|
1179
|
+
return this.replace(message, {
|
|
1180
|
+
values: parameters.join(', ')
|
|
2483
1181
|
});
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
1182
|
+
}
|
|
1183
|
+
replaceMimes(message, attribute, rule, parameters) {
|
|
1184
|
+
return this.replaceMimetypes(message, attribute, rule, parameters);
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
class Validator {
|
|
1189
|
+
static #customCheckers = {};
|
|
1190
|
+
static #customReplacers = {};
|
|
1191
|
+
static #dummyRules = ['active_url', 'bail', 'current_password', 'enum', 'exclude', 'exclude_if', 'exclude_unless', 'exclude_with', 'exclude_without', 'exists', 'nullable', 'sometimes', 'unique'];
|
|
1192
|
+
static #implicitRules = ['accepted', 'accepted_if', 'declined', 'declined_if', 'filled', 'missing', 'missing_if', 'missing_unless', 'missing_with', 'missing_with_all', 'present', 'required', 'required_if', 'required_if_accepted', 'required_unless', 'required_with', 'required_with_all', 'required_without', 'required_without_all'];
|
|
1193
|
+
#data;
|
|
1194
|
+
#rules;
|
|
1195
|
+
#customMessages;
|
|
1196
|
+
#customAttributes;
|
|
1197
|
+
#customValues;
|
|
1198
|
+
#checkers;
|
|
1199
|
+
#replacers;
|
|
1200
|
+
#errors;
|
|
1201
|
+
#implicitAttributes = {};
|
|
1202
|
+
#stopOnFirstFailure = false;
|
|
1203
|
+
#alwaysBail = false;
|
|
1204
|
+
fileRules = ['file', 'image', 'mimetypes', 'mimes'];
|
|
1205
|
+
numericRules = ['decimal', 'numeric', 'integer'];
|
|
1206
|
+
sizeRules = ['size', 'between', 'min', 'max', 'gt', 'lt', 'gte', 'lte'];
|
|
1207
|
+
static setLocale(locale) {
|
|
1208
|
+
Lang.locale(locale);
|
|
1209
|
+
}
|
|
1210
|
+
static setMessages(locale, messages) {
|
|
1211
|
+
Lang.setMessages(locale, messages);
|
|
1212
|
+
}
|
|
1213
|
+
static addChecker(rule, method, message) {
|
|
1214
|
+
Validator.#customCheckers[rule] = method;
|
|
1215
|
+
if (message) {
|
|
1216
|
+
Lang.set(rule, message);
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
static addImplicitChecker(rule, method, message) {
|
|
1220
|
+
Validator.addChecker(rule, method, message);
|
|
1221
|
+
Validator.#implicitRules.push(rule);
|
|
1222
|
+
}
|
|
1223
|
+
static addReplacer(rule, method) {
|
|
1224
|
+
Validator.#customReplacers[rule] = method;
|
|
1225
|
+
}
|
|
1226
|
+
static addDummyRule(rule) {
|
|
1227
|
+
Validator.#dummyRules.push(rule);
|
|
1228
|
+
}
|
|
1229
|
+
constructor() {
|
|
1230
|
+
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1231
|
+
let rules = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1232
|
+
let messages = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1233
|
+
let attributes = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1234
|
+
let values = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
2487
1235
|
this.setProperties(data, rules, messages, attributes, values);
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
for (
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
}
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
}
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
}
|
|
2555
|
-
}, {
|
|
2556
|
-
key: "stopOnFirstFailure",
|
|
2557
|
-
value: function stopOnFirstFailure() {
|
|
2558
|
-
var flag = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
2559
|
-
_classPrivateFieldSet(this, _stopOnFirstFailure, flag);
|
|
2560
|
-
return this;
|
|
2561
|
-
}
|
|
2562
|
-
}, {
|
|
2563
|
-
key: "alwaysBail",
|
|
2564
|
-
value: function alwaysBail() {
|
|
2565
|
-
var flag = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
2566
|
-
_classPrivateFieldSet(this, _alwaysBail, flag);
|
|
2567
|
-
return this;
|
|
2568
|
-
}
|
|
2569
|
-
}, {
|
|
2570
|
-
key: "parseRules",
|
|
2571
|
-
value: function parseRules(rules) {
|
|
2572
|
-
var parsedRules = {};
|
|
2573
|
-
var parseAttributeRules = function parseAttributeRules(rules) {
|
|
2574
|
-
if (Array.isArray(rules)) {
|
|
2575
|
-
return rules;
|
|
2576
|
-
} else {
|
|
2577
|
-
return String(rules).split('|');
|
|
2578
|
-
}
|
|
2579
|
-
};
|
|
2580
|
-
for (var _i3 = 0, _Object$entries3 = Object.entries(rules); _i3 < _Object$entries3.length; _i3++) {
|
|
2581
|
-
var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2),
|
|
2582
|
-
attribute = _Object$entries3$_i[0],
|
|
2583
|
-
attributeRules = _Object$entries3$_i[1];
|
|
2584
|
-
var attributes = attribute.includes('*') ? this.parseWildcardAttribute(attribute) : [attribute];
|
|
2585
|
-
var _iterator = _createForOfIteratorHelper(attributes),
|
|
2586
|
-
_step;
|
|
2587
|
-
try {
|
|
2588
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
2589
|
-
var _attribute = _step.value;
|
|
2590
|
-
var parsedAttributeRules = {};
|
|
2591
|
-
var _iterator2 = _createForOfIteratorHelper(parseAttributeRules(attributeRules)),
|
|
2592
|
-
_step2;
|
|
2593
|
-
try {
|
|
2594
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
2595
|
-
var attributeRule = _step2.value;
|
|
2596
|
-
var parts = attributeRule.split(':');
|
|
2597
|
-
var rule = parts[0];
|
|
2598
|
-
var parameters = parts.slice(1).join(':').split(',').filter(function (part) {
|
|
2599
|
-
return part !== '';
|
|
2600
|
-
});
|
|
2601
|
-
parsedAttributeRules[rule] = parameters;
|
|
2602
|
-
}
|
|
2603
|
-
} catch (err) {
|
|
2604
|
-
_iterator2.e(err);
|
|
2605
|
-
} finally {
|
|
2606
|
-
_iterator2.f();
|
|
2607
|
-
}
|
|
2608
|
-
parsedRules[_attribute] = parsedAttributeRules;
|
|
2609
|
-
}
|
|
2610
|
-
} catch (err) {
|
|
2611
|
-
_iterator.e(err);
|
|
2612
|
-
} finally {
|
|
2613
|
-
_iterator.f();
|
|
1236
|
+
this.#checkers = new Checkers(this);
|
|
1237
|
+
this.#replacers = new Replacers(this);
|
|
1238
|
+
for (const [rule, checker] of Object.entries(Validator.#customCheckers)) {
|
|
1239
|
+
this.#checkers[toCamelCase('check_' + rule)] = checker;
|
|
1240
|
+
}
|
|
1241
|
+
for (const [rule, replacer] of Object.entries(Validator.#customReplacers)) {
|
|
1242
|
+
this.#replacers[toCamelCase('replace_' + rule)] = replacer;
|
|
1243
|
+
}
|
|
1244
|
+
this.#errors = new ErrorBag();
|
|
1245
|
+
}
|
|
1246
|
+
setProperties() {
|
|
1247
|
+
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1248
|
+
let rules = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1249
|
+
let messages = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1250
|
+
let attributes = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1251
|
+
let values = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
1252
|
+
this.#data = data;
|
|
1253
|
+
this.#rules = this.parseRules(rules);
|
|
1254
|
+
this.#customMessages = messages;
|
|
1255
|
+
this.#customAttributes = attributes;
|
|
1256
|
+
this.#customValues = flattenObject(values);
|
|
1257
|
+
return this;
|
|
1258
|
+
}
|
|
1259
|
+
setData(data) {
|
|
1260
|
+
this.#data = data;
|
|
1261
|
+
return this;
|
|
1262
|
+
}
|
|
1263
|
+
setRules(rules) {
|
|
1264
|
+
this.#rules = this.parseRules(rules);
|
|
1265
|
+
return this;
|
|
1266
|
+
}
|
|
1267
|
+
setCustomMessages(messages) {
|
|
1268
|
+
this.#customMessages = messages;
|
|
1269
|
+
return this;
|
|
1270
|
+
}
|
|
1271
|
+
setCustomAttributes(attributes) {
|
|
1272
|
+
this.#customAttributes = attributes;
|
|
1273
|
+
return this;
|
|
1274
|
+
}
|
|
1275
|
+
setCustomValues(values) {
|
|
1276
|
+
this.#customValues = flattenObject(values);
|
|
1277
|
+
return this;
|
|
1278
|
+
}
|
|
1279
|
+
addImplicitAttribute(implicitAttribute, attribute) {
|
|
1280
|
+
this.#implicitAttributes[implicitAttribute] = attribute;
|
|
1281
|
+
return this;
|
|
1282
|
+
}
|
|
1283
|
+
stopOnFirstFailure() {
|
|
1284
|
+
let flag = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
1285
|
+
this.#stopOnFirstFailure = flag;
|
|
1286
|
+
return this;
|
|
1287
|
+
}
|
|
1288
|
+
alwaysBail() {
|
|
1289
|
+
let flag = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
1290
|
+
this.#alwaysBail = flag;
|
|
1291
|
+
return this;
|
|
1292
|
+
}
|
|
1293
|
+
parseRules(rules) {
|
|
1294
|
+
const parsedRules = {};
|
|
1295
|
+
for (const [attribute, attributeRules] of Object.entries(rules)) {
|
|
1296
|
+
const attributes = attribute.includes('*') ? this.parseWildcardAttribute(attribute) : [attribute];
|
|
1297
|
+
for (const attribute of attributes) {
|
|
1298
|
+
const parsedAttributeRules = {};
|
|
1299
|
+
for (const attributeRule of this.parseAttributeRules(attributeRules)) {
|
|
1300
|
+
const [rule, parameters] = this.parseAttributeRule(attributeRule);
|
|
1301
|
+
parsedAttributeRules[rule] = parameters;
|
|
2614
1302
|
}
|
|
1303
|
+
parsedRules[attribute] = parsedAttributeRules;
|
|
2615
1304
|
}
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
}
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
return
|
|
2642
|
-
}
|
|
2643
|
-
}
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
hasError = false;
|
|
2670
|
-
_i5 = 0, _Object$entries5 = Object.entries(rules);
|
|
2671
|
-
case 12:
|
|
2672
|
-
if (!(_i5 < _Object$entries5.length)) {
|
|
2673
|
-
_context.next = 42;
|
|
2674
|
-
break;
|
|
2675
|
-
}
|
|
2676
|
-
_Object$entries5$_i = _slicedToArray(_Object$entries5[_i5], 2), rule = _Object$entries5$_i[0], parameters = _Object$entries5$_i[1];
|
|
2677
|
-
if (!(rule === '')) {
|
|
2678
|
-
_context.next = 16;
|
|
2679
|
-
break;
|
|
2680
|
-
}
|
|
2681
|
-
return _context.abrupt("continue", 39);
|
|
2682
|
-
case 16:
|
|
2683
|
-
if (!(!_classStaticPrivateFieldSpecGet(Validator, Validator, _implicitRules).includes(rule) && (typeof value === 'undefined' || typeof value === 'string' && value.trim() === '' || isNullable && value === null))) {
|
|
2684
|
-
_context.next = 18;
|
|
2685
|
-
break;
|
|
2686
|
-
}
|
|
2687
|
-
return _context.abrupt("continue", 39);
|
|
2688
|
-
case 18:
|
|
2689
|
-
result = void 0, status = void 0, message = void 0;
|
|
2690
|
-
camelRule = toCamelCase('check_' + rule);
|
|
2691
|
-
if (!(typeof _classPrivateFieldGet(this, _checkers)[camelRule] === 'function')) {
|
|
2692
|
-
_context.next = 26;
|
|
2693
|
-
break;
|
|
2694
|
-
}
|
|
2695
|
-
_context.next = 23;
|
|
2696
|
-
return _classPrivateFieldGet(this, _checkers)[camelRule](attribute, value, parameters);
|
|
2697
|
-
case 23:
|
|
2698
|
-
result = _context.sent;
|
|
2699
|
-
_context.next = 31;
|
|
2700
|
-
break;
|
|
2701
|
-
case 26:
|
|
2702
|
-
if (!_classStaticPrivateFieldSpecGet(Validator, Validator, _dummyRules).includes(rule)) {
|
|
2703
|
-
_context.next = 30;
|
|
2704
|
-
break;
|
|
2705
|
-
}
|
|
2706
|
-
result = true;
|
|
2707
|
-
_context.next = 31;
|
|
2708
|
-
break;
|
|
2709
|
-
case 30:
|
|
2710
|
-
throw new Error("Invalid validation rule: ".concat(rule));
|
|
2711
|
-
case 31:
|
|
2712
|
-
if (typeof result === 'boolean') {
|
|
2713
|
-
status = result;
|
|
2714
|
-
} else {
|
|
2715
|
-
_result = result;
|
|
2716
|
-
status = _result.status;
|
|
2717
|
-
message = _result.message;
|
|
2718
|
-
}
|
|
2719
|
-
if (status) {
|
|
2720
|
-
_context.next = 39;
|
|
2721
|
-
break;
|
|
2722
|
-
}
|
|
2723
|
-
hasError = true;
|
|
2724
|
-
message = isEmpty(message) ? this.getMessage(attribute, rule) : message;
|
|
2725
|
-
message = this.makeReplacements(message, attribute, rule, parameters);
|
|
2726
|
-
_classPrivateFieldGet(this, _errors).add(attribute, message);
|
|
2727
|
-
if (!(doBail || _classStaticPrivateFieldSpecGet(Validator, Validator, _implicitRules).includes(rule))) {
|
|
2728
|
-
_context.next = 39;
|
|
2729
|
-
break;
|
|
2730
|
-
}
|
|
2731
|
-
return _context.abrupt("break", 42);
|
|
2732
|
-
case 39:
|
|
2733
|
-
_i5++;
|
|
2734
|
-
_context.next = 12;
|
|
2735
|
-
break;
|
|
2736
|
-
case 42:
|
|
2737
|
-
if (!(_classPrivateFieldGet(this, _stopOnFirstFailure) && hasError)) {
|
|
2738
|
-
_context.next = 44;
|
|
2739
|
-
break;
|
|
2740
|
-
}
|
|
2741
|
-
return _context.abrupt("break", 47);
|
|
2742
|
-
case 44:
|
|
2743
|
-
_i4++;
|
|
2744
|
-
_context.next = 3;
|
|
2745
|
-
break;
|
|
2746
|
-
case 47:
|
|
2747
|
-
if (!_classPrivateFieldGet(this, _errors).isNotEmpty()) {
|
|
2748
|
-
_context.next = 49;
|
|
2749
|
-
break;
|
|
2750
|
-
}
|
|
2751
|
-
throw _classPrivateFieldGet(this, _errors);
|
|
2752
|
-
case 49:
|
|
2753
|
-
case "end":
|
|
2754
|
-
return _context.stop();
|
|
2755
|
-
}
|
|
2756
|
-
}, _callee, this);
|
|
2757
|
-
}));
|
|
2758
|
-
function validate() {
|
|
2759
|
-
return _validate.apply(this, arguments);
|
|
2760
|
-
}
|
|
2761
|
-
return validate;
|
|
2762
|
-
}()
|
|
2763
|
-
}, {
|
|
2764
|
-
key: "passes",
|
|
2765
|
-
value: function () {
|
|
2766
|
-
var _passes = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
2767
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
2768
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
2769
|
-
case 0:
|
|
2770
|
-
_context2.prev = 0;
|
|
2771
|
-
_context2.next = 3;
|
|
2772
|
-
return this.validate();
|
|
2773
|
-
case 3:
|
|
2774
|
-
_context2.next = 10;
|
|
2775
|
-
break;
|
|
2776
|
-
case 5:
|
|
2777
|
-
_context2.prev = 5;
|
|
2778
|
-
_context2.t0 = _context2["catch"](0);
|
|
2779
|
-
if (!(_context2.t0 instanceof Error)) {
|
|
2780
|
-
_context2.next = 9;
|
|
2781
|
-
break;
|
|
2782
|
-
}
|
|
2783
|
-
throw _context2.t0;
|
|
2784
|
-
case 9:
|
|
2785
|
-
return _context2.abrupt("return", false);
|
|
2786
|
-
case 10:
|
|
2787
|
-
return _context2.abrupt("return", true);
|
|
2788
|
-
case 11:
|
|
2789
|
-
case "end":
|
|
2790
|
-
return _context2.stop();
|
|
2791
|
-
}
|
|
2792
|
-
}, _callee2, this, [[0, 5]]);
|
|
2793
|
-
}));
|
|
2794
|
-
function passes() {
|
|
2795
|
-
return _passes.apply(this, arguments);
|
|
2796
|
-
}
|
|
2797
|
-
return passes;
|
|
2798
|
-
}()
|
|
2799
|
-
}, {
|
|
2800
|
-
key: "fails",
|
|
2801
|
-
value: function () {
|
|
2802
|
-
var _fails = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
2803
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
2804
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
2805
|
-
case 0:
|
|
2806
|
-
_context3.next = 2;
|
|
2807
|
-
return this.passes();
|
|
2808
|
-
case 2:
|
|
2809
|
-
return _context3.abrupt("return", !_context3.sent);
|
|
2810
|
-
case 3:
|
|
2811
|
-
case "end":
|
|
2812
|
-
return _context3.stop();
|
|
2813
|
-
}
|
|
2814
|
-
}, _callee3, this);
|
|
2815
|
-
}));
|
|
2816
|
-
function fails() {
|
|
2817
|
-
return _fails.apply(this, arguments);
|
|
2818
|
-
}
|
|
2819
|
-
return fails;
|
|
2820
|
-
}()
|
|
2821
|
-
}, {
|
|
2822
|
-
key: "getMessage",
|
|
2823
|
-
value: function getMessage(attribute, rule) {
|
|
2824
|
-
var _message;
|
|
2825
|
-
var value = this.getValue(attribute);
|
|
2826
|
-
attribute = this.getPrimaryAttribute(attribute);
|
|
2827
|
-
var message;
|
|
2828
|
-
for (var _i6 = 0, _arr = ["".concat(attribute, ".").concat(rule), rule]; _i6 < _arr.length; _i6++) {
|
|
2829
|
-
var key = _arr[_i6];
|
|
2830
|
-
if (_classPrivateFieldGet(this, _customMessages).hasOwnProperty(key)) {
|
|
2831
|
-
message = _classPrivateFieldGet(this, _customMessages)[key];
|
|
2832
|
-
break;
|
|
1305
|
+
}
|
|
1306
|
+
return parsedRules;
|
|
1307
|
+
}
|
|
1308
|
+
parseWildcardAttribute(attribute) {
|
|
1309
|
+
const attributes = [];
|
|
1310
|
+
const index = attribute.indexOf('*');
|
|
1311
|
+
const parentPath = attribute.substring(0, index - 1);
|
|
1312
|
+
const childPath = attribute.substring(index + 2);
|
|
1313
|
+
const data = this.getValue(parentPath);
|
|
1314
|
+
if (!(Array.isArray(data) || isPlainObject(data))) {
|
|
1315
|
+
return [attribute];
|
|
1316
|
+
}
|
|
1317
|
+
Object.entries(data).forEach(_ref => {
|
|
1318
|
+
let [key, value] = _ref;
|
|
1319
|
+
const implicitAttribute = `${parentPath}.${key}.${childPath}`.replace(/\.$/, '');
|
|
1320
|
+
const implicitAttributes = implicitAttribute.includes('*') ? this.parseWildcardAttribute(implicitAttribute) : [implicitAttribute];
|
|
1321
|
+
attributes.push(...implicitAttributes);
|
|
1322
|
+
implicitAttributes.forEach(value => this.#implicitAttributes[value] = attribute);
|
|
1323
|
+
});
|
|
1324
|
+
return attributes;
|
|
1325
|
+
}
|
|
1326
|
+
parseAttributeRules(rules) {
|
|
1327
|
+
if (Array.isArray(rules)) {
|
|
1328
|
+
return rules;
|
|
1329
|
+
} else {
|
|
1330
|
+
return String(rules).split('|');
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
parseAttributeRule(rule) {
|
|
1334
|
+
if (Array.isArray(rule)) {
|
|
1335
|
+
return [rule.shift() ?? '', rule];
|
|
1336
|
+
}
|
|
1337
|
+
const index = rule.indexOf(':');
|
|
1338
|
+
if (index === -1) {
|
|
1339
|
+
return [rule, []];
|
|
1340
|
+
} else {
|
|
1341
|
+
return [rule.substring(0, index), parseCsvString(rule.substring(index + 1))];
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
async validate() {
|
|
1345
|
+
this.#checkers.clearCaches();
|
|
1346
|
+
this.#errors = new ErrorBag();
|
|
1347
|
+
for (const [attribute, rules] of Object.entries(this.#rules)) {
|
|
1348
|
+
let value = this.getValue(attribute);
|
|
1349
|
+
if (rules.hasOwnProperty('sometimes') && typeof value === 'undefined') {
|
|
1350
|
+
continue;
|
|
1351
|
+
}
|
|
1352
|
+
const doBail = this.#alwaysBail || rules.hasOwnProperty('bail');
|
|
1353
|
+
const isNullable = rules.hasOwnProperty('nullable');
|
|
1354
|
+
let hasError = false;
|
|
1355
|
+
for (const [rule, parameters] of Object.entries(rules)) {
|
|
1356
|
+
if (rule === '') {
|
|
1357
|
+
continue;
|
|
2833
1358
|
}
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
1359
|
+
if (!Validator.#implicitRules.includes(rule) && (typeof value === 'undefined' || typeof value === 'string' && value.trim() === '' || isNullable && value === null)) {
|
|
1360
|
+
continue;
|
|
1361
|
+
}
|
|
1362
|
+
let result, status, message;
|
|
1363
|
+
const camelRule = toCamelCase('check_' + rule);
|
|
1364
|
+
if (typeof this.#checkers[camelRule] === 'function') {
|
|
1365
|
+
result = await this.#checkers[camelRule](attribute, value, parameters);
|
|
1366
|
+
} else if (Validator.#dummyRules.includes(rule)) {
|
|
1367
|
+
result = true;
|
|
1368
|
+
} else {
|
|
1369
|
+
throw new Error(`Invalid validation rule: ${rule}`);
|
|
1370
|
+
}
|
|
1371
|
+
if (typeof result === 'boolean') {
|
|
1372
|
+
status = result;
|
|
1373
|
+
} else {
|
|
1374
|
+
({
|
|
1375
|
+
status,
|
|
1376
|
+
message
|
|
1377
|
+
} = result);
|
|
1378
|
+
}
|
|
1379
|
+
if (!status) {
|
|
1380
|
+
hasError = true;
|
|
1381
|
+
message = isEmpty(message) ? this.getMessage(attribute, rule) : message;
|
|
1382
|
+
message = this.makeReplacements(message, attribute, rule, parameters);
|
|
1383
|
+
this.#errors.add(attribute, message);
|
|
1384
|
+
if (doBail || Validator.#implicitRules.includes(rule)) {
|
|
1385
|
+
break;
|
|
2846
1386
|
}
|
|
2847
1387
|
}
|
|
2848
|
-
message = Lang.get(_key);
|
|
2849
1388
|
}
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
}, {
|
|
2853
|
-
key: "makeReplacements",
|
|
2854
|
-
value: function makeReplacements(message, attribute, rule, parameters) {
|
|
2855
|
-
var attributeName = this.getDisplayableAttribute(attribute);
|
|
2856
|
-
var value = this.getValue(attribute);
|
|
2857
|
-
var data = {
|
|
2858
|
-
attribute: attributeName,
|
|
2859
|
-
ATTRIBUTE: attributeName.toLocaleUpperCase(),
|
|
2860
|
-
Attribute: attributeName.charAt(0).toLocaleUpperCase() + attributeName.substring(1),
|
|
2861
|
-
input: this.getDisplayableValue(attribute, value)
|
|
2862
|
-
};
|
|
2863
|
-
for (var _i7 = 0, _Object$entries6 = Object.entries(data); _i7 < _Object$entries6.length; _i7++) {
|
|
2864
|
-
var _Object$entries6$_i = _slicedToArray(_Object$entries6[_i7], 2),
|
|
2865
|
-
key = _Object$entries6$_i[0],
|
|
2866
|
-
_value = _Object$entries6$_i[1];
|
|
2867
|
-
message = message.replaceAll(':' + key, _value);
|
|
1389
|
+
if (this.#stopOnFirstFailure && hasError) {
|
|
1390
|
+
break;
|
|
2868
1391
|
}
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
1392
|
+
}
|
|
1393
|
+
if (this.#errors.isNotEmpty()) {
|
|
1394
|
+
throw this.#errors;
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
async passes() {
|
|
1398
|
+
try {
|
|
1399
|
+
await this.validate();
|
|
1400
|
+
} catch (error) {
|
|
1401
|
+
if (error instanceof Error) {
|
|
1402
|
+
throw error;
|
|
2877
1403
|
}
|
|
2878
|
-
return
|
|
2879
|
-
}
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
1404
|
+
return false;
|
|
1405
|
+
}
|
|
1406
|
+
return true;
|
|
1407
|
+
}
|
|
1408
|
+
async fails() {
|
|
1409
|
+
return !(await this.passes());
|
|
1410
|
+
}
|
|
1411
|
+
getMessage(attribute, rule) {
|
|
1412
|
+
const value = this.getValue(attribute);
|
|
1413
|
+
attribute = this.getPrimaryAttribute(attribute);
|
|
1414
|
+
let message;
|
|
1415
|
+
for (const key of [`${attribute}.${rule}`, rule]) {
|
|
1416
|
+
if (this.#customMessages.hasOwnProperty(key)) {
|
|
1417
|
+
message = this.#customMessages[key];
|
|
1418
|
+
break;
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
if (!message) {
|
|
1422
|
+
let key = rule;
|
|
1423
|
+
if (this.sizeRules.includes(key)) {
|
|
1424
|
+
if (Array.isArray(value) || isPlainObject(value) || this.hasRule(attribute, 'array')) {
|
|
1425
|
+
key += '.array';
|
|
1426
|
+
} else if (value instanceof File || this.hasRule(attribute, this.fileRules)) {
|
|
1427
|
+
key += '.file';
|
|
1428
|
+
} else if (typeof value === 'number' || this.hasRule(attribute, this.numericRules)) {
|
|
1429
|
+
key += '.numeric';
|
|
1430
|
+
} else {
|
|
1431
|
+
key += '.string';
|
|
2890
1432
|
}
|
|
2891
1433
|
}
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
attribute
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
}
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
return
|
|
2924
|
-
} else if (
|
|
2925
|
-
return
|
|
2926
|
-
}
|
|
2927
|
-
return value;
|
|
2928
|
-
}
|
|
2929
|
-
}, {
|
|
2930
|
-
key: "getRule",
|
|
2931
|
-
value: function getRule(attribute) {
|
|
2932
|
-
var _classPrivateFieldGet2;
|
|
2933
|
-
attribute = this.getPrimaryAttribute(attribute);
|
|
2934
|
-
return (_classPrivateFieldGet2 = _classPrivateFieldGet(this, _rules)[attribute]) !== null && _classPrivateFieldGet2 !== void 0 ? _classPrivateFieldGet2 : {};
|
|
2935
|
-
}
|
|
2936
|
-
}, {
|
|
2937
|
-
key: "hasRule",
|
|
2938
|
-
value: function hasRule(attribute, rules) {
|
|
2939
|
-
attribute = this.getPrimaryAttribute(attribute);
|
|
2940
|
-
rules = typeof rules === 'string' ? [rules] : rules;
|
|
2941
|
-
if (!_classPrivateFieldGet(this, _rules).hasOwnProperty(attribute)) {
|
|
2942
|
-
return false;
|
|
2943
|
-
}
|
|
2944
|
-
var _iterator3 = _createForOfIteratorHelper(rules),
|
|
2945
|
-
_step3;
|
|
2946
|
-
try {
|
|
2947
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
2948
|
-
var rule = _step3.value;
|
|
2949
|
-
if (_classPrivateFieldGet(this, _rules)[attribute].hasOwnProperty(rule)) {
|
|
2950
|
-
return true;
|
|
2951
|
-
}
|
|
2952
|
-
}
|
|
2953
|
-
} catch (err) {
|
|
2954
|
-
_iterator3.e(err);
|
|
2955
|
-
} finally {
|
|
2956
|
-
_iterator3.f();
|
|
1434
|
+
message = Lang.get(key);
|
|
1435
|
+
}
|
|
1436
|
+
return message ?? `validation.${rule}`;
|
|
1437
|
+
}
|
|
1438
|
+
makeReplacements(message, attribute, rule, parameters) {
|
|
1439
|
+
const attributeName = this.getDisplayableAttribute(attribute);
|
|
1440
|
+
const value = this.getValue(attribute);
|
|
1441
|
+
const data = {
|
|
1442
|
+
attribute: attributeName,
|
|
1443
|
+
ATTRIBUTE: attributeName.toLocaleUpperCase(),
|
|
1444
|
+
Attribute: attributeName.charAt(0).toLocaleUpperCase() + attributeName.substring(1),
|
|
1445
|
+
input: this.getDisplayableValue(attribute, value)
|
|
1446
|
+
};
|
|
1447
|
+
for (const [key, value] of Object.entries(data)) {
|
|
1448
|
+
message = message.replaceAll(':' + key, value);
|
|
1449
|
+
}
|
|
1450
|
+
const match = attribute.match(/\.(\d+)\.?/);
|
|
1451
|
+
const index = match === null ? -1 : parseInt(match[1], 10);
|
|
1452
|
+
if (index !== -1) {
|
|
1453
|
+
message = message.replaceAll(':index', index).replaceAll(':position', index + 1);
|
|
1454
|
+
}
|
|
1455
|
+
const camelRule = toCamelCase('replace_' + rule);
|
|
1456
|
+
if (typeof this.#replacers[camelRule] === 'function') {
|
|
1457
|
+
message = this.#replacers[camelRule](message, attribute, rule, parameters);
|
|
1458
|
+
}
|
|
1459
|
+
return message;
|
|
1460
|
+
}
|
|
1461
|
+
getDisplayableAttribute(attribute) {
|
|
1462
|
+
const unparsed = this.getPrimaryAttribute(attribute);
|
|
1463
|
+
for (const name of [attribute, unparsed]) {
|
|
1464
|
+
if (this.#customAttributes.hasOwnProperty(name)) {
|
|
1465
|
+
return this.#customAttributes[name];
|
|
1466
|
+
} else if (Lang.has(`attributes.${name}`)) {
|
|
1467
|
+
return Lang.get(`attributes.${name}`);
|
|
2957
1468
|
}
|
|
1469
|
+
}
|
|
1470
|
+
if (this.#implicitAttributes.hasOwnProperty(attribute)) {
|
|
1471
|
+
return attribute;
|
|
1472
|
+
}
|
|
1473
|
+
return toSnakeCase(attribute).replaceAll('_', ' ');
|
|
1474
|
+
}
|
|
1475
|
+
getDisplayableValue(attribute, value) {
|
|
1476
|
+
attribute = this.getPrimaryAttribute(attribute);
|
|
1477
|
+
const path = `${attribute}.${value}`;
|
|
1478
|
+
if (isEmpty(value)) {
|
|
1479
|
+
return 'empty';
|
|
1480
|
+
} else if (typeof value === 'boolean' || this.hasRule(attribute, 'boolean')) {
|
|
1481
|
+
return Number(value) ? 'true' : 'false';
|
|
1482
|
+
} else if (this.#customValues.hasOwnProperty(path)) {
|
|
1483
|
+
return this.#customValues[path];
|
|
1484
|
+
} else if (Lang.has(`values.${path}`)) {
|
|
1485
|
+
return Lang.get(`values.${path}`);
|
|
1486
|
+
}
|
|
1487
|
+
return value;
|
|
1488
|
+
}
|
|
1489
|
+
getSize(attribute, value) {
|
|
1490
|
+
if (isEmpty(value)) {
|
|
1491
|
+
return 0;
|
|
1492
|
+
} else if (isNumeric(value) && this.hasRule(attribute, this.numericRules)) {
|
|
1493
|
+
return parseFloat(typeof value === 'string' ? value.trim() : value, 10);
|
|
1494
|
+
} else if (value instanceof File) {
|
|
1495
|
+
return value.size / 1024;
|
|
1496
|
+
} else if (isPlainObject(value)) {
|
|
1497
|
+
return Object.keys(value).length;
|
|
1498
|
+
} else if (value.hasOwnProperty('length')) {
|
|
1499
|
+
return value.length;
|
|
1500
|
+
}
|
|
1501
|
+
return value;
|
|
1502
|
+
}
|
|
1503
|
+
getRule(attribute) {
|
|
1504
|
+
attribute = this.getPrimaryAttribute(attribute);
|
|
1505
|
+
return this.#rules[attribute] ?? {};
|
|
1506
|
+
}
|
|
1507
|
+
hasRule(attribute, rules) {
|
|
1508
|
+
attribute = this.getPrimaryAttribute(attribute);
|
|
1509
|
+
rules = typeof rules === 'string' ? [rules] : rules;
|
|
1510
|
+
if (!this.#rules.hasOwnProperty(attribute)) {
|
|
2958
1511
|
return false;
|
|
2959
1512
|
}
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
return _classPrivateFieldGet(this, _implicitAttributes).hasOwnProperty(attribute) ? _classPrivateFieldGet(this, _implicitAttributes)[attribute] : attribute;
|
|
2964
|
-
}
|
|
2965
|
-
}, {
|
|
2966
|
-
key: "hasAttribute",
|
|
2967
|
-
value: function hasAttribute(attribute) {
|
|
2968
|
-
return typeof this.getValue(attribute) !== 'undefined';
|
|
2969
|
-
}
|
|
2970
|
-
}, {
|
|
2971
|
-
key: "getValue",
|
|
2972
|
-
value: function getValue(attribute) {
|
|
2973
|
-
return getByPath(_classPrivateFieldGet(this, _data), attribute);
|
|
2974
|
-
}
|
|
2975
|
-
}, {
|
|
2976
|
-
key: "errors",
|
|
2977
|
-
value: function errors() {
|
|
2978
|
-
return _classPrivateFieldGet(this, _errors);
|
|
2979
|
-
}
|
|
2980
|
-
}], [{
|
|
2981
|
-
key: "setLocale",
|
|
2982
|
-
value: function setLocale(locale) {
|
|
2983
|
-
Lang.locale(locale);
|
|
2984
|
-
}
|
|
2985
|
-
}, {
|
|
2986
|
-
key: "setMessages",
|
|
2987
|
-
value: function setMessages(locale, messages) {
|
|
2988
|
-
Lang.setMessages(locale, messages);
|
|
2989
|
-
}
|
|
2990
|
-
}, {
|
|
2991
|
-
key: "addChecker",
|
|
2992
|
-
value: function addChecker(rule, method, message) {
|
|
2993
|
-
_classStaticPrivateFieldSpecGet(Validator, Validator, _customCheckers)[rule] = method;
|
|
2994
|
-
if (message) {
|
|
2995
|
-
Lang.set(rule, message);
|
|
1513
|
+
for (const rule of rules) {
|
|
1514
|
+
if (this.#rules[attribute].hasOwnProperty(rule)) {
|
|
1515
|
+
return true;
|
|
2996
1516
|
}
|
|
2997
1517
|
}
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
}
|
|
3014
|
-
}]);
|
|
3015
|
-
return Validator;
|
|
3016
|
-
}();
|
|
3017
|
-
var _customCheckers = {
|
|
3018
|
-
writable: true,
|
|
3019
|
-
value: {}
|
|
3020
|
-
};
|
|
3021
|
-
var _customReplacers = {
|
|
3022
|
-
writable: true,
|
|
3023
|
-
value: {}
|
|
3024
|
-
};
|
|
3025
|
-
var _dummyRules = {
|
|
3026
|
-
writable: true,
|
|
3027
|
-
value: ['active_url', 'bail', 'current_password', 'enum', 'exclude', 'exclude_if', 'exclude_unless', 'exclude_with', 'exclude_without', 'exists', 'nullable', 'sometimes', 'unique']
|
|
3028
|
-
};
|
|
3029
|
-
var _implicitRules = {
|
|
3030
|
-
writable: true,
|
|
3031
|
-
value: ['accepted', 'accepted_if', 'declined', 'declined_if', 'filled', 'missing', 'missing_if', 'missing_unless', 'missing_with', 'missing_with_all', 'present', 'required', 'required_if', 'required_if_accepted', 'required_unless', 'required_with', 'required_with_all', 'required_without', 'required_without_all']
|
|
3032
|
-
};
|
|
1518
|
+
return false;
|
|
1519
|
+
}
|
|
1520
|
+
getPrimaryAttribute(attribute) {
|
|
1521
|
+
return this.#implicitAttributes.hasOwnProperty(attribute) ? this.#implicitAttributes[attribute] : attribute;
|
|
1522
|
+
}
|
|
1523
|
+
hasAttribute(attribute) {
|
|
1524
|
+
return typeof this.getValue(attribute) !== 'undefined';
|
|
1525
|
+
}
|
|
1526
|
+
getValue(attribute) {
|
|
1527
|
+
return getByPath(this.#data, attribute);
|
|
1528
|
+
}
|
|
1529
|
+
errors() {
|
|
1530
|
+
return this.#errors;
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
3033
1533
|
|
|
3034
1534
|
exports.Checkers = Checkers;
|
|
3035
1535
|
exports.ErrorBag = ErrorBag;
|