vest 4.0.1 → 4.0.2-dev-6e9534

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.
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('n4s')) :
3
- typeof define === 'function' && define.amd ? define(['n4s'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.compose = factory(global.n4s));
5
- }(this, (function (n4s) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
+ typeof define === 'function' && define.amd ? define(factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.compose = factory());
5
+ }(this, (function () { 'use strict';
6
6
 
7
7
  function mapFirst(array, callback) {
8
8
  var broke = false;
@@ -43,6 +43,16 @@
43
43
  throw new Error(devMessage );
44
44
  }
45
45
 
46
+ function bindNot(fn) {
47
+ return function () {
48
+ var args = [];
49
+ for (var _i = 0; _i < arguments.length; _i++) {
50
+ args[_i] = arguments[_i];
51
+ }
52
+ return !fn.apply(void 0, args);
53
+ };
54
+ }
55
+
46
56
  /**
47
57
  * A safe hasOwnProperty access
48
58
  */
@@ -53,10 +63,12 @@
53
63
  function isNumber(value) {
54
64
  return Boolean(typeof value === 'number');
55
65
  }
66
+ var isNotNumber = bindNot(isNumber);
56
67
 
57
68
  function lengthEquals(value, arg1) {
58
69
  return value.length === Number(arg1);
59
70
  }
71
+ var lengthNotEquals = bindNot(lengthEquals);
60
72
 
61
73
  function isEmpty(value) {
62
74
  if (!value) {
@@ -73,6 +85,378 @@
73
85
  }
74
86
  return true;
75
87
  }
88
+ var isNotEmpty = bindNot(isEmpty);
89
+
90
+ var assign = Object.assign;
91
+
92
+ function isNull(value) {
93
+ return value === null;
94
+ }
95
+ var isNotNull = bindNot(isNull);
96
+
97
+ function isUndefined(value) {
98
+ return value === undefined;
99
+ }
100
+ var isNotUndefined = bindNot(isUndefined);
101
+
102
+ function isNullish(value) {
103
+ return isNull(value) || isUndefined(value);
104
+ }
105
+ var isNotNullish = bindNot(isNullish);
106
+
107
+ function isStringValue(v) {
108
+ return String(v) === v;
109
+ }
110
+
111
+ function endsWith(value, arg1) {
112
+ return isStringValue(value) && isStringValue(arg1) && value.endsWith(arg1);
113
+ }
114
+ var doesNotEndWith = bindNot(endsWith);
115
+
116
+ function equals(value, arg1) {
117
+ return value === arg1;
118
+ }
119
+ var notEquals = bindNot(equals);
120
+
121
+ function isNumeric(value) {
122
+ var str = String(value);
123
+ var num = Number(value);
124
+ var result = !isNaN(parseFloat(str)) && !isNaN(Number(value)) && isFinite(num);
125
+ return Boolean(result);
126
+ }
127
+ var isNotNumeric = bindNot(isNumeric);
128
+
129
+ function greaterThan(value, gt) {
130
+ return isNumeric(value) && isNumeric(gt) && Number(value) > Number(gt);
131
+ }
132
+
133
+ function greaterThanOrEquals(value, gte) {
134
+ return isNumeric(value) && isNumeric(gte) && Number(value) >= Number(gte);
135
+ }
136
+
137
+ // The module is named "isArrayValue" since it
138
+ // is conflicting with a nested npm dependency.
139
+ // We may need to revisit this in the future.
140
+ function isArray(value) {
141
+ return Boolean(Array.isArray(value));
142
+ }
143
+ var isNotArray = bindNot(isArray);
144
+
145
+ function inside(value, arg1) {
146
+ if (isArray(arg1)) {
147
+ return arg1.indexOf(value) !== -1;
148
+ }
149
+ // both value and arg1 are strings
150
+ if (isStringValue(arg1) && isStringValue(value)) {
151
+ return arg1.indexOf(value) !== -1;
152
+ }
153
+ return false;
154
+ }
155
+ var notInside = bindNot(inside);
156
+
157
+ function lessThanOrEquals(value, lte) {
158
+ return isNumeric(value) && isNumeric(lte) && Number(value) <= Number(lte);
159
+ }
160
+
161
+ function isBetween(value, min, max) {
162
+ return greaterThanOrEquals(value, min) && lessThanOrEquals(value, max);
163
+ }
164
+ var isNotBetween = bindNot(isBetween);
165
+
166
+ function isBlank(value) {
167
+ return isNullish(value) || (isStringValue(value) && !value.trim());
168
+ }
169
+ var isNotBlank = bindNot(isBlank);
170
+
171
+ function isBoolean(value) {
172
+ return !!value === value;
173
+ }
174
+
175
+ var isNotBoolean = bindNot(isBoolean);
176
+
177
+ /**
178
+ * Validates that a given value is an even number
179
+ */
180
+ var isEven = function (value) {
181
+ if (isNumeric(value)) {
182
+ return value % 2 === 0;
183
+ }
184
+ return false;
185
+ };
186
+
187
+ function isNaN$1(value) {
188
+ return Number.isNaN(value);
189
+ }
190
+ var isNotNaN = bindNot(isNaN$1);
191
+
192
+ function isNegative(value) {
193
+ if (isNumeric(value)) {
194
+ return Number(value) < 0;
195
+ }
196
+ return false;
197
+ }
198
+ var isPositive = bindNot(isNegative);
199
+
200
+ /**
201
+ * Validates that a given value is an odd number
202
+ */
203
+ var isOdd = function (value) {
204
+ if (isNumeric(value)) {
205
+ return value % 2 !== 0;
206
+ }
207
+ return false;
208
+ };
209
+
210
+ var isNotString = bindNot(isStringValue);
211
+
212
+ function isTruthy(value) {
213
+ return !!value;
214
+ }
215
+ var isFalsy = bindNot(isTruthy);
216
+
217
+ function lessThan(value, lt) {
218
+ return isNumeric(value) && isNumeric(lt) && Number(value) < Number(lt);
219
+ }
220
+
221
+ function longerThan(value, arg1) {
222
+ return value.length > Number(arg1);
223
+ }
224
+
225
+ function longerThanOrEquals(value, arg1) {
226
+ return value.length >= Number(arg1);
227
+ }
228
+
229
+ function matches(value, regex) {
230
+ if (regex instanceof RegExp) {
231
+ return regex.test(value);
232
+ }
233
+ else if (isStringValue(regex)) {
234
+ return new RegExp(regex).test(value);
235
+ }
236
+ else {
237
+ return false;
238
+ }
239
+ }
240
+ var notMatches = bindNot(matches);
241
+
242
+ function numberEquals(value, eq) {
243
+ return isNumeric(value) && isNumeric(eq) && Number(value) === Number(eq);
244
+ }
245
+ var numberNotEquals = bindNot(numberEquals);
246
+
247
+ function condition(value, callback) {
248
+ try {
249
+ return callback(value);
250
+ }
251
+ catch (_a) {
252
+ return false;
253
+ }
254
+ }
255
+
256
+ function shorterThan(value, arg1) {
257
+ return value.length < Number(arg1);
258
+ }
259
+
260
+ function shorterThanOrEquals(value, arg1) {
261
+ return value.length <= Number(arg1);
262
+ }
263
+
264
+ function startsWith(value, arg1) {
265
+ return isStringValue(value) && isStringValue(arg1) && value.startsWith(arg1);
266
+ }
267
+ var doesNotStartWith = bindNot(startsWith);
268
+
269
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, max-lines-per-function
270
+ function rules() {
271
+ return {
272
+ condition: condition,
273
+ doesNotEndWith: doesNotEndWith,
274
+ doesNotStartWith: doesNotStartWith,
275
+ endsWith: endsWith,
276
+ equals: equals,
277
+ greaterThan: greaterThan,
278
+ greaterThanOrEquals: greaterThanOrEquals,
279
+ gt: greaterThan,
280
+ gte: greaterThanOrEquals,
281
+ inside: inside,
282
+ isArray: isArray,
283
+ isBetween: isBetween,
284
+ isBlank: isBlank,
285
+ isBoolean: isBoolean,
286
+ isEmpty: isEmpty,
287
+ isEven: isEven,
288
+ isFalsy: isFalsy,
289
+ isNaN: isNaN$1,
290
+ isNegative: isNegative,
291
+ isNotArray: isNotArray,
292
+ isNotBetween: isNotBetween,
293
+ isNotBlank: isNotBlank,
294
+ isNotBoolean: isNotBoolean,
295
+ isNotEmpty: isNotEmpty,
296
+ isNotNaN: isNotNaN,
297
+ isNotNull: isNotNull,
298
+ isNotNullish: isNotNullish,
299
+ isNotNumber: isNotNumber,
300
+ isNotNumeric: isNotNumeric,
301
+ isNotString: isNotString,
302
+ isNotUndefined: isNotUndefined,
303
+ isNull: isNull,
304
+ isNullish: isNullish,
305
+ isNumber: isNumber,
306
+ isNumeric: isNumeric,
307
+ isOdd: isOdd,
308
+ isPositive: isPositive,
309
+ isString: isStringValue,
310
+ isTruthy: isTruthy,
311
+ isUndefined: isUndefined,
312
+ lengthEquals: lengthEquals,
313
+ lengthNotEquals: lengthNotEquals,
314
+ lessThan: lessThan,
315
+ lessThanOrEquals: lessThanOrEquals,
316
+ longerThan: longerThan,
317
+ longerThanOrEquals: longerThanOrEquals,
318
+ lt: lessThan,
319
+ lte: lessThanOrEquals,
320
+ matches: matches,
321
+ notEquals: notEquals,
322
+ notInside: notInside,
323
+ notMatches: notMatches,
324
+ numberEquals: numberEquals,
325
+ numberNotEquals: numberNotEquals,
326
+ shorterThan: shorterThan,
327
+ shorterThanOrEquals: shorterThanOrEquals,
328
+ startsWith: startsWith
329
+ };
330
+ }
331
+
332
+ var baseRules = rules();
333
+ function getRule(ruleName) {
334
+ return baseRules[ruleName];
335
+ }
336
+
337
+ function eachEnforceRule(action) {
338
+ for (var ruleName in baseRules) {
339
+ var ruleFn = getRule(ruleName);
340
+ if (isFunction(ruleFn)) {
341
+ action(ruleName, ruleFn);
342
+ }
343
+ }
344
+ }
345
+
346
+ // eslint-disable-next-line max-lines-per-function
347
+ function createContext(init) {
348
+ var storage = { ancestry: [] };
349
+ return {
350
+ bind: bind,
351
+ run: run,
352
+ use: use,
353
+ useX: useX
354
+ };
355
+ function useX(errorMessage) {
356
+ var _a;
357
+ return ((_a = storage.ctx) !== null && _a !== void 0 ? _a : throwError(defaultTo(errorMessage, 'Context was used after it was closed')));
358
+ }
359
+ function run(ctxRef, fn) {
360
+ var _a;
361
+ var parentContext = use();
362
+ var out = assign({}, parentContext ? parentContext : {}, (_a = optionalFunctionValue(init, ctxRef, parentContext)) !== null && _a !== void 0 ? _a : ctxRef);
363
+ var ctx = set(Object.freeze(out));
364
+ storage.ancestry.unshift(ctx);
365
+ var res = fn(ctx);
366
+ clear();
367
+ return res;
368
+ }
369
+ function bind(ctxRef, fn) {
370
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
371
+ // @ts-ignore - this one's pretty hard to get right
372
+ var returnedFn = function () {
373
+ var runTimeArgs = [];
374
+ for (var _i = 0; _i < arguments.length; _i++) {
375
+ runTimeArgs[_i] = arguments[_i];
376
+ }
377
+ return run(ctxRef, function () {
378
+ return fn.apply(void 0, runTimeArgs);
379
+ });
380
+ };
381
+ return returnedFn;
382
+ }
383
+ function use() {
384
+ return storage.ctx;
385
+ }
386
+ function set(value) {
387
+ return (storage.ctx = value);
388
+ }
389
+ function clear() {
390
+ var _a;
391
+ storage.ancestry.shift();
392
+ set((_a = storage.ancestry[0]) !== null && _a !== void 0 ? _a : null);
393
+ }
394
+ }
395
+
396
+ var ctx = createContext(function (ctxRef, parentContext) {
397
+ var base = {
398
+ value: ctxRef.value,
399
+ meta: ctxRef.meta || {}
400
+ };
401
+ if (!parentContext) {
402
+ return assign(base, {
403
+ parent: emptyParent
404
+ });
405
+ }
406
+ else if (ctxRef.set) {
407
+ return assign(base, {
408
+ parent: function () { return stripContext(parentContext); }
409
+ });
410
+ }
411
+ return parentContext;
412
+ });
413
+ function stripContext(ctx) {
414
+ if (!ctx) {
415
+ return ctx;
416
+ }
417
+ return {
418
+ value: ctx.value,
419
+ meta: ctx.meta,
420
+ parent: ctx.parent
421
+ };
422
+ }
423
+ function emptyParent() {
424
+ return null;
425
+ }
426
+
427
+ /*! *****************************************************************************
428
+ Copyright (c) Microsoft Corporation.
429
+
430
+ Permission to use, copy, modify, and/or distribute this software for any
431
+ purpose with or without fee is hereby granted.
432
+
433
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
434
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
435
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
436
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
437
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
438
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
439
+ PERFORMANCE OF THIS SOFTWARE.
440
+ ***************************************************************************** */
441
+
442
+ function __spreadArray(to, from, pack) {
443
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
444
+ if (ar || !(i in from)) {
445
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
446
+ ar[i] = from[i];
447
+ }
448
+ }
449
+ return to.concat(ar || Array.prototype.slice.call(from));
450
+ }
451
+
452
+ function isProxySupported() {
453
+ try {
454
+ return isFunction(Proxy);
455
+ }
456
+ catch (_a) {
457
+ return false;
458
+ }
459
+ }
76
460
 
77
461
  function ruleReturn(pass, message) {
78
462
  var output = { pass: pass };
@@ -91,6 +475,182 @@
91
475
  return defaultTo(callback, passing());
92
476
  }
93
477
 
478
+ /**
479
+ * Transform the result of a rule into a standard format
480
+ */
481
+ function transformResult(result, ruleName, value) {
482
+ var args = [];
483
+ for (var _i = 3; _i < arguments.length; _i++) {
484
+ args[_i - 3] = arguments[_i];
485
+ }
486
+ validateResult(result);
487
+ // if result is boolean
488
+ if (isBoolean(result)) {
489
+ return ruleReturn(result);
490
+ }
491
+ else {
492
+ return ruleReturn(result.pass, optionalFunctionValue.apply(void 0, __spreadArray([result.message, ruleName, value], args)));
493
+ }
494
+ }
495
+ function validateResult(result) {
496
+ // if result is boolean, or if result.pass is boolean
497
+ if (isBoolean(result) || (result && isBoolean(result.pass))) {
498
+ return;
499
+ }
500
+ throwError('Incorrect return value for rule: ' + JSON.stringify(result));
501
+ }
502
+
503
+ function enforceEager(value) {
504
+ var target = {};
505
+ if (!isProxySupported()) {
506
+ eachEnforceRule(function (ruleName, ruleFn) {
507
+ target[ruleName] = genRuleCall(target, ruleFn, ruleName);
508
+ });
509
+ return target;
510
+ }
511
+ var proxy = new Proxy(target, {
512
+ get: function (_, ruleName) {
513
+ var rule = getRule(ruleName);
514
+ if (rule) {
515
+ return genRuleCall(proxy, rule, ruleName);
516
+ }
517
+ }
518
+ });
519
+ return proxy;
520
+ function genRuleCall(target, rule, ruleName) {
521
+ return function ruleCall() {
522
+ var args = [];
523
+ for (var _i = 0; _i < arguments.length; _i++) {
524
+ args[_i] = arguments[_i];
525
+ }
526
+ var transformedResult = transformResult.apply(void 0, __spreadArray([ctx.run({ value: value }, function () { return rule.apply(void 0, __spreadArray([value], args)); }),
527
+ ruleName,
528
+ value], args));
529
+ if (!transformedResult.pass) {
530
+ if (isEmpty(transformedResult.message)) {
531
+ throwError("enforce/" + ruleName + " failed with " + JSON.stringify(value));
532
+ }
533
+ else {
534
+ // Explicitly throw a string so that vest.test can pick it up as the validation error message
535
+ throw transformedResult.message;
536
+ }
537
+ }
538
+ return target;
539
+ };
540
+ }
541
+ }
542
+
543
+ // eslint-disable-next-line max-lines-per-function
544
+ function genEnforceLazy(key) {
545
+ var registeredRules = [];
546
+ var lazyMessage;
547
+ return addLazyRule(key);
548
+ // eslint-disable-next-line max-lines-per-function
549
+ function addLazyRule(ruleName) {
550
+ // eslint-disable-next-line max-lines-per-function
551
+ return function () {
552
+ var args = [];
553
+ for (var _i = 0; _i < arguments.length; _i++) {
554
+ args[_i] = arguments[_i];
555
+ }
556
+ var rule = getRule(ruleName);
557
+ registeredRules.push(function (value) {
558
+ return transformResult.apply(void 0, __spreadArray([rule.apply(void 0, __spreadArray([value], args)), ruleName, value], args));
559
+ });
560
+ var proxy = {
561
+ run: function (value) {
562
+ return defaultToPassing(mapFirst(registeredRules, function (rule, breakout) {
563
+ var _a;
564
+ var res = ctx.run({ value: value }, function () { return rule(value); });
565
+ if (!res.pass) {
566
+ breakout(ruleReturn(!!res.pass, (_a = optionalFunctionValue(lazyMessage, value, res.message)) !== null && _a !== void 0 ? _a : res.message));
567
+ }
568
+ }));
569
+ },
570
+ test: function (value) { return proxy.run(value).pass; },
571
+ message: function (message) {
572
+ if (message) {
573
+ lazyMessage = message;
574
+ }
575
+ return proxy;
576
+ }
577
+ };
578
+ if (!isProxySupported()) {
579
+ eachEnforceRule(function (ruleName) {
580
+ proxy[ruleName] = addLazyRule(ruleName);
581
+ });
582
+ return proxy;
583
+ }
584
+ // reassigning the proxy here is not pretty
585
+ // but it's a cleaner way of getting `run` and `test` for free
586
+ proxy = new Proxy(proxy, {
587
+ get: function (target, key) {
588
+ if (getRule(key)) {
589
+ return addLazyRule(key);
590
+ }
591
+ return target[key]; // already has `run` and `test` on it
592
+ }
593
+ });
594
+ return proxy;
595
+ };
596
+ }
597
+ }
598
+
599
+ /**
600
+ * Enforce is quite complicated, I want to explain it in detail.
601
+ * It is dynamic in nature, so a lot of proxy objects are involved.
602
+ *
603
+ * Enforce has two main interfaces
604
+ * 1. eager
605
+ * 2. lazy
606
+ *
607
+ * The eager interface is the most commonly used, and the easier to understand.
608
+ * It throws an error when a rule is not satisfied.
609
+ * The eager interface is declared in enforceEager.ts and it is quite simple to understand.
610
+ * enforce is called with a value, and the return value is a proxy object that points back to all the rules.
611
+ * When a rule is called, the value is mapped as its first argument, and if the rule passes, the same
612
+ * proxy object is returned. Otherwise, an error is thrown.
613
+ *
614
+ * The lazy interface works quite differently. It is declared in genEnforceLazy.ts.
615
+ * Rather than calling enforce directly, the lazy interface has all the rules as "methods" (only by proxy).
616
+ * Calling the first function in the chain will initialize an array of calls. It stores the different rule calls
617
+ * and the parameters passed to them. None of the rules are called yet.
618
+ * The rules are only invoked in sequence once either of these chained functions are called:
619
+ * 1. test(value)
620
+ * 2. run(value)
621
+ *
622
+ * Calling run or test will call all the rules in sequence, with the difference that test will only return a boolean value,
623
+ * while run will return an object with the validation result and an optional message created by the rule.
624
+ */
625
+ function genEnforce() {
626
+ var target = {
627
+ context: function () { return ctx.useX(); },
628
+ extend: function (customRules) {
629
+ assign(baseRules, customRules);
630
+ }
631
+ };
632
+ if (!isProxySupported()) {
633
+ eachEnforceRule(function (ruleName) {
634
+ // Only on the first rule access - start the chain of calls
635
+ target[ruleName] = genEnforceLazy(ruleName);
636
+ });
637
+ return target;
638
+ }
639
+ return new Proxy(assign(enforceEager, target), {
640
+ get: function (target, key) {
641
+ if (key in target) {
642
+ return target[key];
643
+ }
644
+ if (!getRule(key)) {
645
+ return;
646
+ }
647
+ // Only on the first rule access - start the chain of calls
648
+ return genEnforceLazy(key);
649
+ }
650
+ });
651
+ }
652
+ genEnforce();
653
+
94
654
  function runLazyRule(lazyRule, currentValue) {
95
655
  try {
96
656
  return lazyRule.run(currentValue);
@@ -122,7 +682,7 @@
122
682
  test: function (value) { return run(value).pass; }
123
683
  });
124
684
  function run(value) {
125
- return n4s.ctx.run({ value: value }, function () {
685
+ return ctx.run({ value: value }, function () {
126
686
  return defaultToPassing(mapFirst(composites, function (composite, breakout) {
127
687
  /* HACK: Just a small white lie. ~~HELP WANTED~~.
128
688
  The ideal is that instead of `TLazyRuleRunners` We would simply use `TLazy` to begin with.
@@ -1 +1 @@
1
- "use strict";!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("n4s")):"function"==typeof define&&define.amd?define(["n4s"],e):(n="undefined"!=typeof globalThis?globalThis:n||self).compose=e(n.n4s)}(this,(function(n){function e(n,e){function t(n){r=!0,o=n}for(var r=!1,o=null,u=0;u<n.length;u++)if(e(n[u],t,u),r)return o}function t(n,e){var t;return null!==(t=function(n){for(var e=[],t=1;t<arguments.length;t++)e[t-1]=arguments[t];return"function"==typeof n?n.apply(void 0,e):n}(n))&&void 0!==t?t:e}function r(n){if(n){if("number"==typeof n)return 0===n;if(Object.prototype.hasOwnProperty.call(n,"length"))return n.length===Number(0);if("object"==typeof n)return Object.keys(n).length===Number(0)}return!0}function o(n,e){return n={pass:n},e&&(n.message=e),n}return function(){function u(r){return n.ctx.run({value:r},(function(){return t(e(f,(function(n,e){try{var t=n.run(r)}catch(n){t=o(!1)}t.pass||e(t)})),o(!0))}))}for(var f=[],i=0;i<arguments.length;i++)f[i]=arguments[i];return Object.assign((function(n){if(!(n=u(n)).pass){if(r(n.message))throw Error(t(void 0,void 0));throw n.message}}),{run:u,test:function(n){return u(n).pass}})}}));
1
+ "use strict";!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(n="undefined"!=typeof globalThis?globalThis:n||self).compose=t()}(this,(function(){function n(n,t){function r(n){e=!0,u=n}for(var e=!1,u=null,i=0;i<n.length;i++)if(t(n[i],r,i),e)return u}function t(n){return"function"==typeof n}function r(n){for(var r=[],e=1;e<arguments.length;e++)r[e-1]=arguments[e];return t(n)?n.apply(void 0,r):n}function e(n,t){var e;return null!==(e=r(n))&&void 0!==e?e:t}function u(n,t){throw Error(e(t,n))}function i(n){return function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return!n.apply(void 0,t)}}function o(n){return"number"==typeof n}function s(n,t){return n.length===Number(t)}function a(n){if(n){if(o(n))return 0===n;if(Object.prototype.hasOwnProperty.call(n,"length"))return s(n,0);if("object"==typeof n)return s(Object.keys(n),0)}return!0}function f(n){return null===n}function c(n){return void 0===n}function l(n){return null===n||c(n)}function N(n){return String(n)===n}function h(n,t){return N(n)&&N(t)&&n.endsWith(t)}function p(n,t){return n===t}function v(n){var t=Number(n);return!(isNaN(parseFloat(String(n)))||isNaN(Number(n))||!isFinite(t))}function g(n,t){return v(n)&&v(t)&&Number(n)>Number(t)}function m(n,t){return v(n)&&v(t)&&Number(n)>=Number(t)}function d(n){return!!Array.isArray(n)}function y(n,t){return!!(d(t)||N(t)&&N(n))&&-1!==t.indexOf(n)}function b(n,t){return v(n)&&v(t)&&Number(n)<=Number(t)}function x(n,t,r){return m(n,t)&&b(n,r)}function E(n){return l(n)||N(n)&&!n.trim()}function O(n){return!!n===n}function w(n){return Number.isNaN(n)}function T(n){return!!v(n)&&0>Number(n)}function q(n){return!!n}function j(n,t){return v(n)&&v(t)&&Number(n)<Number(t)}function S(n,t){return t instanceof RegExp?t.test(n):!!N(t)&&new RegExp(t).test(n)}function A(n,t){return v(n)&&v(t)&&Number(n)===Number(t)}function B(n,t){return N(n)&&N(t)&&n.startsWith(t)}function P(n){for(var r in an){var e=an[r];t(e)&&n(r,e)}}function W(){return null}function k(n,t,r){if(r||2===arguments.length)for(var e,u=0,i=t.length;u<i;u++)!e&&u in t||(e||(e=Array.prototype.slice.call(t,0,u)),e[u]=t[u]);return n.concat(e||Array.prototype.slice.call(t))}function F(){try{return t(Proxy)}catch(n){return!1}}function I(n,t){return n={pass:n},t&&(n.message=t),n}function J(n,t,e){for(var i=[],o=3;o<arguments.length;o++)i[o-3]=arguments[o];return O(n)||n&&O(n.pass)||u("Incorrect return value for rule: "+JSON.stringify(n)),O(n)?I(n):I(n.pass,r.apply(void 0,k([n.message,t,e],i)))}function R(n){function t(t,r,e){return function(){for(var i=[],o=0;o<arguments.length;o++)i[o]=arguments[o];if(!(o=J.apply(void 0,k([fn.run({value:n},(function(){return r.apply(void 0,k([n],i))})),e,n],i))).pass){if(!a(o.message))throw o.message;u("enforce/"+e+" failed with "+JSON.stringify(n))}return t}}var r={};if(!F())return P((function(n,e){r[n]=t(r,e,n)})),r;var e=new Proxy(r,{get:function(n,r){if(n=an[r])return t(e,n,r)}});return e}function U(t){var u,i=[];return function t(o){return function(){for(var s=[],a=0;a<arguments.length;a++)s[a]=arguments[a];var f=an[o];i.push((function(n){return J.apply(void 0,k([f.apply(void 0,k([n],s)),o,n],s))}));var c={run:function(t){return e(n(i,(function(n,e){var i,o=fn.run({value:t},(function(){return n(t)}));o.pass||e(I(!!o.pass,null!==(i=r(u,t,o.message))&&void 0!==i?i:o.message))})),I(!0))},test:function(n){return c.run(n).pass},message:function(n){return n&&(u=n),c}};return F()?c=new Proxy(c,{get:function(n,r){return an[r]?t(r):n[r]}}):(P((function(n){c[n]=t(n)})),c)}}(t)}var X,z=i(o),C=i(s),M=i(a),D=Object.assign,G=i(f),H=i(c),K=i(l),L=i(h),Q=i(p),V=i(v),Y=i(d),Z=i(y),$=i(x),_=i(E),nn=i(O),tn=i(w),rn=i(T),en=i(N),un=i(q),on=i(S),sn=i(A),an={condition:function(n,t){try{return t(n)}catch(n){return!1}},doesNotEndWith:L,doesNotStartWith:i(B),endsWith:h,equals:p,greaterThan:g,greaterThanOrEquals:m,gt:g,gte:m,inside:y,isArray:d,isBetween:x,isBlank:E,isBoolean:O,isEmpty:a,isEven:function(n){return!!v(n)&&0==n%2},isFalsy:un,isNaN:w,isNegative:T,isNotArray:Y,isNotBetween:$,isNotBlank:_,isNotBoolean:nn,isNotEmpty:M,isNotNaN:tn,isNotNull:G,isNotNullish:K,isNotNumber:z,isNotNumeric:V,isNotString:en,isNotUndefined:H,isNull:f,isNullish:l,isNumber:o,isNumeric:v,isOdd:function(n){return!!v(n)&&0!=n%2},isPositive:rn,isString:N,isTruthy:q,isUndefined:c,lengthEquals:s,lengthNotEquals:C,lessThan:j,lessThanOrEquals:b,longerThan:function(n,t){return n.length>Number(t)},longerThanOrEquals:function(n,t){return n.length>=Number(t)},lt:j,lte:b,matches:S,notEquals:Q,notInside:Z,notMatches:on,numberEquals:A,numberNotEquals:sn,shorterThan:function(n,t){return n.length<Number(t)},shorterThanOrEquals:function(n,t){return n.length<=Number(t)},startsWith:B},fn=function(n){function t(t,e){var u,s,a=i();return t=D({},a||{},null!==(u=r(n,t,a))&&void 0!==u?u:t),u=o.ctx=Object.freeze(t),o.ancestry.unshift(u),e=e(u),o.ancestry.shift(),o.ctx=null!==(s=o.ancestry[0])&&void 0!==s?s:null,e}function i(){return o.ctx}var o={ancestry:[]};return{bind:function(n,r){return function(){for(var e=[],u=0;u<arguments.length;u++)e[u]=arguments[u];return t(n,(function(){return r.apply(void 0,e)}))}},run:t,use:i,useX:function(n){var t;return null!==(t=o.ctx)&&void 0!==t?t:u(e(n,"Context was used after it was closed"))}}}((function(n,t){var r={value:n.value,meta:n.meta||{}};return t?n.set?D(r,{parent:function(){return t?{value:t.value,meta:t.meta,parent:t.parent}:t}}):t:D(r,{parent:W})}));return X={context:function(){return fn.useX()},extend:function(n){D(an,n)}},F()?new Proxy(D(R,X),{get:function(n,t){return t in n?n[t]:an[t]?U(t):void 0}}):P((function(n){X[n]=U(n)})),function(){function t(t){return fn.run({value:t},(function(){return e(n(r,(function(n,r){try{var e=n.run(t)}catch(n){e=I(!1)}e.pass||r(e)})),I(!0))}))}for(var r=[],i=0;i<arguments.length;i++)r[i]=arguments[i];return Object.assign((function(n){if(!(n=t(n)).pass){if(!a(n.message))throw n.message;u()}}),{run:t,test:function(n){return t(n).pass}})}}));