vest 4.0.0 → 4.0.2-dev-72921c

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,20 +1,326 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('n4s'), require('context')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'n4s', 'context'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.vest = {}, global.n4s, global.context));
5
- }(this, (function (exports, n4s, context$1) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.vest = {}));
5
+ }(this, (function (exports) { 'use strict';
6
6
 
7
7
  var assign = Object.assign;
8
8
 
9
+ function isFunction(value) {
10
+ return typeof value === 'function';
11
+ }
12
+
13
+ function bindNot(fn) {
14
+ return function () {
15
+ var args = [];
16
+ for (var _i = 0; _i < arguments.length; _i++) {
17
+ args[_i] = arguments[_i];
18
+ }
19
+ return !fn.apply(void 0, args);
20
+ };
21
+ }
22
+
23
+ function isNull(value) {
24
+ return value === null;
25
+ }
26
+ var isNotNull = bindNot(isNull);
27
+
28
+ function isUndefined(value) {
29
+ return value === undefined;
30
+ }
31
+ var isNotUndefined = bindNot(isUndefined);
32
+
33
+ function isNullish(value) {
34
+ return isNull(value) || isUndefined(value);
35
+ }
36
+ var isNotNullish = bindNot(isNullish);
37
+
38
+ function isStringValue(v) {
39
+ return String(v) === v;
40
+ }
41
+
42
+ function endsWith(value, arg1) {
43
+ return isStringValue(value) && isStringValue(arg1) && value.endsWith(arg1);
44
+ }
45
+ var doesNotEndWith = bindNot(endsWith);
46
+
47
+ function equals(value, arg1) {
48
+ return value === arg1;
49
+ }
50
+ var notEquals = bindNot(equals);
51
+
52
+ function isNumeric(value) {
53
+ var str = String(value);
54
+ var num = Number(value);
55
+ var result = !isNaN(parseFloat(str)) && !isNaN(Number(value)) && isFinite(num);
56
+ return Boolean(result);
57
+ }
58
+ var isNotNumeric = bindNot(isNumeric);
59
+
60
+ function greaterThan(value, gt) {
61
+ return isNumeric(value) && isNumeric(gt) && Number(value) > Number(gt);
62
+ }
63
+
64
+ function greaterThanOrEquals(value, gte) {
65
+ return isNumeric(value) && isNumeric(gte) && Number(value) >= Number(gte);
66
+ }
67
+
68
+ // The module is named "isArrayValue" since it
69
+ // is conflicting with a nested npm dependency.
70
+ // We may need to revisit this in the future.
71
+ function isArray(value) {
72
+ return Boolean(Array.isArray(value));
73
+ }
74
+ var isNotArray = bindNot(isArray);
75
+
76
+ function inside(value, arg1) {
77
+ if (isArray(arg1)) {
78
+ return arg1.indexOf(value) !== -1;
79
+ }
80
+ // both value and arg1 are strings
81
+ if (isStringValue(arg1) && isStringValue(value)) {
82
+ return arg1.indexOf(value) !== -1;
83
+ }
84
+ return false;
85
+ }
86
+ var notInside = bindNot(inside);
87
+
88
+ function lessThanOrEquals(value, lte) {
89
+ return isNumeric(value) && isNumeric(lte) && Number(value) <= Number(lte);
90
+ }
91
+
92
+ function isBetween(value, min, max) {
93
+ return greaterThanOrEquals(value, min) && lessThanOrEquals(value, max);
94
+ }
95
+ var isNotBetween = bindNot(isBetween);
96
+
97
+ function isBlank(value) {
98
+ return isNullish(value) || (isStringValue(value) && !value.trim());
99
+ }
100
+ var isNotBlank = bindNot(isBlank);
101
+
102
+ function isBoolean(value) {
103
+ return !!value === value;
104
+ }
105
+
106
+ var isNotBoolean = bindNot(isBoolean);
107
+
9
108
  /**
10
- * @returns a unique numeric id.
109
+ * A safe hasOwnProperty access
11
110
  */
12
- var genId = (function (n) { return function () {
13
- return "" + n++;
14
- }; })(0);
111
+ function hasOwnProperty(obj, key) {
112
+ return Object.prototype.hasOwnProperty.call(obj, key);
113
+ }
15
114
 
16
- function isFunction(value) {
17
- return typeof value === 'function';
115
+ function isNumber(value) {
116
+ return Boolean(typeof value === 'number');
117
+ }
118
+ var isNotNumber = bindNot(isNumber);
119
+
120
+ function lengthEquals(value, arg1) {
121
+ return value.length === Number(arg1);
122
+ }
123
+ var lengthNotEquals = bindNot(lengthEquals);
124
+
125
+ function isEmpty(value) {
126
+ if (!value) {
127
+ return true;
128
+ }
129
+ else if (isNumber(value)) {
130
+ return value === 0;
131
+ }
132
+ else if (hasOwnProperty(value, 'length')) {
133
+ return lengthEquals(value, 0);
134
+ }
135
+ else if (typeof value === 'object') {
136
+ return lengthEquals(Object.keys(value), 0);
137
+ }
138
+ return true;
139
+ }
140
+ var isNotEmpty = bindNot(isEmpty);
141
+
142
+ /**
143
+ * Validates that a given value is an even number
144
+ */
145
+ var isEven = function (value) {
146
+ if (isNumeric(value)) {
147
+ return value % 2 === 0;
148
+ }
149
+ return false;
150
+ };
151
+
152
+ function isNaN$1(value) {
153
+ return Number.isNaN(value);
154
+ }
155
+ var isNotNaN = bindNot(isNaN$1);
156
+
157
+ function isNegative(value) {
158
+ if (isNumeric(value)) {
159
+ return Number(value) < 0;
160
+ }
161
+ return false;
162
+ }
163
+ var isPositive = bindNot(isNegative);
164
+
165
+ /**
166
+ * Validates that a given value is an odd number
167
+ */
168
+ var isOdd = function (value) {
169
+ if (isNumeric(value)) {
170
+ return value % 2 !== 0;
171
+ }
172
+ return false;
173
+ };
174
+
175
+ var isNotString = bindNot(isStringValue);
176
+
177
+ function isTruthy(value) {
178
+ return !!value;
179
+ }
180
+ var isFalsy = bindNot(isTruthy);
181
+
182
+ function isValueOf(value, objectToCheck) {
183
+ if (isNullish(objectToCheck)) {
184
+ return false;
185
+ }
186
+ for (var key in objectToCheck) {
187
+ if (objectToCheck[key] === value) {
188
+ return true;
189
+ }
190
+ }
191
+ return false;
192
+ }
193
+ var isNotValueOf = bindNot(isValueOf);
194
+
195
+ function lessThan(value, lt) {
196
+ return isNumeric(value) && isNumeric(lt) && Number(value) < Number(lt);
197
+ }
198
+
199
+ function longerThan(value, arg1) {
200
+ return value.length > Number(arg1);
201
+ }
202
+
203
+ function longerThanOrEquals(value, arg1) {
204
+ return value.length >= Number(arg1);
205
+ }
206
+
207
+ function matches(value, regex) {
208
+ if (regex instanceof RegExp) {
209
+ return regex.test(value);
210
+ }
211
+ else if (isStringValue(regex)) {
212
+ return new RegExp(regex).test(value);
213
+ }
214
+ else {
215
+ return false;
216
+ }
217
+ }
218
+ var notMatches = bindNot(matches);
219
+
220
+ function numberEquals(value, eq) {
221
+ return isNumeric(value) && isNumeric(eq) && Number(value) === Number(eq);
222
+ }
223
+ var numberNotEquals = bindNot(numberEquals);
224
+
225
+ function condition(value, callback) {
226
+ try {
227
+ return callback(value);
228
+ }
229
+ catch (_a) {
230
+ return false;
231
+ }
232
+ }
233
+
234
+ function shorterThan(value, arg1) {
235
+ return value.length < Number(arg1);
236
+ }
237
+
238
+ function shorterThanOrEquals(value, arg1) {
239
+ return value.length <= Number(arg1);
240
+ }
241
+
242
+ function startsWith(value, arg1) {
243
+ return isStringValue(value) && isStringValue(arg1) && value.startsWith(arg1);
244
+ }
245
+ var doesNotStartWith = bindNot(startsWith);
246
+
247
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, max-lines-per-function
248
+ function rules() {
249
+ return {
250
+ condition: condition,
251
+ doesNotEndWith: doesNotEndWith,
252
+ doesNotStartWith: doesNotStartWith,
253
+ endsWith: endsWith,
254
+ equals: equals,
255
+ greaterThan: greaterThan,
256
+ greaterThanOrEquals: greaterThanOrEquals,
257
+ gt: greaterThan,
258
+ gte: greaterThanOrEquals,
259
+ inside: inside,
260
+ isArray: isArray,
261
+ isBetween: isBetween,
262
+ isBlank: isBlank,
263
+ isBoolean: isBoolean,
264
+ isEmpty: isEmpty,
265
+ isEven: isEven,
266
+ isFalsy: isFalsy,
267
+ isNaN: isNaN$1,
268
+ isNegative: isNegative,
269
+ isNotArray: isNotArray,
270
+ isNotBetween: isNotBetween,
271
+ isNotBlank: isNotBlank,
272
+ isNotBoolean: isNotBoolean,
273
+ isNotEmpty: isNotEmpty,
274
+ isNotNaN: isNotNaN,
275
+ isNotNull: isNotNull,
276
+ isNotNullish: isNotNullish,
277
+ isNotNumber: isNotNumber,
278
+ isNotNumeric: isNotNumeric,
279
+ isNotString: isNotString,
280
+ isNotUndefined: isNotUndefined,
281
+ isNotValueOf: isNotValueOf,
282
+ isNull: isNull,
283
+ isNullish: isNullish,
284
+ isNumber: isNumber,
285
+ isNumeric: isNumeric,
286
+ isOdd: isOdd,
287
+ isPositive: isPositive,
288
+ isString: isStringValue,
289
+ isTruthy: isTruthy,
290
+ isUndefined: isUndefined,
291
+ isValueOf: isValueOf,
292
+ lengthEquals: lengthEquals,
293
+ lengthNotEquals: lengthNotEquals,
294
+ lessThan: lessThan,
295
+ lessThanOrEquals: lessThanOrEquals,
296
+ longerThan: longerThan,
297
+ longerThanOrEquals: longerThanOrEquals,
298
+ lt: lessThan,
299
+ lte: lessThanOrEquals,
300
+ matches: matches,
301
+ notEquals: notEquals,
302
+ notInside: notInside,
303
+ notMatches: notMatches,
304
+ numberEquals: numberEquals,
305
+ numberNotEquals: numberNotEquals,
306
+ shorterThan: shorterThan,
307
+ shorterThanOrEquals: shorterThanOrEquals,
308
+ startsWith: startsWith
309
+ };
310
+ }
311
+
312
+ var baseRules = rules();
313
+ function getRule(ruleName) {
314
+ return baseRules[ruleName];
315
+ }
316
+
317
+ function eachEnforceRule(action) {
318
+ for (var ruleName in baseRules) {
319
+ var ruleFn = getRule(ruleName);
320
+ if (isFunction(ruleFn)) {
321
+ action(ruleName, ruleFn);
322
+ }
323
+ }
18
324
  }
19
325
 
20
326
  function optionalFunctionValue(value) {
@@ -42,6 +348,344 @@
42
348
  }, 0);
43
349
  }
44
350
 
351
+ // eslint-disable-next-line max-lines-per-function
352
+ function createContext(init) {
353
+ var storage = { ancestry: [] };
354
+ return {
355
+ bind: bind,
356
+ run: run,
357
+ use: use,
358
+ useX: useX
359
+ };
360
+ function useX(errorMessage) {
361
+ var _a;
362
+ return ((_a = storage.ctx) !== null && _a !== void 0 ? _a : throwError(defaultTo(errorMessage, 'Context was used after it was closed')));
363
+ }
364
+ function run(ctxRef, fn) {
365
+ var _a;
366
+ var parentContext = use();
367
+ var out = assign({}, parentContext ? parentContext : {}, (_a = optionalFunctionValue(init, ctxRef, parentContext)) !== null && _a !== void 0 ? _a : ctxRef);
368
+ var ctx = set(Object.freeze(out));
369
+ storage.ancestry.unshift(ctx);
370
+ var res = fn(ctx);
371
+ clear();
372
+ return res;
373
+ }
374
+ function bind(ctxRef, fn) {
375
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
376
+ // @ts-ignore - this one's pretty hard to get right
377
+ var returnedFn = function () {
378
+ var runTimeArgs = [];
379
+ for (var _i = 0; _i < arguments.length; _i++) {
380
+ runTimeArgs[_i] = arguments[_i];
381
+ }
382
+ return run(ctxRef, function () {
383
+ return fn.apply(void 0, runTimeArgs);
384
+ });
385
+ };
386
+ return returnedFn;
387
+ }
388
+ function use() {
389
+ return storage.ctx;
390
+ }
391
+ function set(value) {
392
+ return (storage.ctx = value);
393
+ }
394
+ function clear() {
395
+ var _a;
396
+ storage.ancestry.shift();
397
+ set((_a = storage.ancestry[0]) !== null && _a !== void 0 ? _a : null);
398
+ }
399
+ }
400
+
401
+ var ctx = createContext(function (ctxRef, parentContext) {
402
+ var base = {
403
+ value: ctxRef.value,
404
+ meta: ctxRef.meta || {}
405
+ };
406
+ if (!parentContext) {
407
+ return assign(base, {
408
+ parent: emptyParent
409
+ });
410
+ }
411
+ else if (ctxRef.set) {
412
+ return assign(base, {
413
+ parent: function () { return stripContext(parentContext); }
414
+ });
415
+ }
416
+ return parentContext;
417
+ });
418
+ function stripContext(ctx) {
419
+ if (!ctx) {
420
+ return ctx;
421
+ }
422
+ return {
423
+ value: ctx.value,
424
+ meta: ctx.meta,
425
+ parent: ctx.parent
426
+ };
427
+ }
428
+ function emptyParent() {
429
+ return null;
430
+ }
431
+
432
+ /*! *****************************************************************************
433
+ Copyright (c) Microsoft Corporation.
434
+
435
+ Permission to use, copy, modify, and/or distribute this software for any
436
+ purpose with or without fee is hereby granted.
437
+
438
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
439
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
440
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
441
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
442
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
443
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
444
+ PERFORMANCE OF THIS SOFTWARE.
445
+ ***************************************************************************** */
446
+
447
+ var __assign = function() {
448
+ __assign = Object.assign || function __assign(t) {
449
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
450
+ s = arguments[i];
451
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
452
+ }
453
+ return t;
454
+ };
455
+ return __assign.apply(this, arguments);
456
+ };
457
+
458
+ function __spreadArray(to, from, pack) {
459
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
460
+ if (ar || !(i in from)) {
461
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
462
+ ar[i] = from[i];
463
+ }
464
+ }
465
+ return to.concat(ar || Array.prototype.slice.call(from));
466
+ }
467
+
468
+ function isProxySupported() {
469
+ try {
470
+ return isFunction(Proxy);
471
+ }
472
+ catch (_a) {
473
+ return false;
474
+ }
475
+ }
476
+
477
+ function ruleReturn(pass, message) {
478
+ var output = { pass: pass };
479
+ if (message) {
480
+ output.message = message;
481
+ }
482
+ return output;
483
+ }
484
+ function passing() {
485
+ return ruleReturn(true);
486
+ }
487
+ function defaultToPassing(callback) {
488
+ return defaultTo(callback, passing());
489
+ }
490
+
491
+ /**
492
+ * Transform the result of a rule into a standard format
493
+ */
494
+ function transformResult(result, ruleName, value) {
495
+ var args = [];
496
+ for (var _i = 3; _i < arguments.length; _i++) {
497
+ args[_i - 3] = arguments[_i];
498
+ }
499
+ validateResult(result);
500
+ // if result is boolean
501
+ if (isBoolean(result)) {
502
+ return ruleReturn(result);
503
+ }
504
+ else {
505
+ return ruleReturn(result.pass, optionalFunctionValue.apply(void 0, __spreadArray([result.message, ruleName, value], args)));
506
+ }
507
+ }
508
+ function validateResult(result) {
509
+ // if result is boolean, or if result.pass is boolean
510
+ if (isBoolean(result) || (result && isBoolean(result.pass))) {
511
+ return;
512
+ }
513
+ throwError('Incorrect return value for rule: ' + JSON.stringify(result));
514
+ }
515
+
516
+ function enforceEager(value) {
517
+ var target = {};
518
+ if (!isProxySupported()) {
519
+ eachEnforceRule(function (ruleName, ruleFn) {
520
+ target[ruleName] = genRuleCall(target, ruleFn, ruleName);
521
+ });
522
+ return target;
523
+ }
524
+ var proxy = new Proxy(target, {
525
+ get: function (_, ruleName) {
526
+ var rule = getRule(ruleName);
527
+ if (rule) {
528
+ return genRuleCall(proxy, rule, ruleName);
529
+ }
530
+ }
531
+ });
532
+ return proxy;
533
+ function genRuleCall(target, rule, ruleName) {
534
+ return function ruleCall() {
535
+ var args = [];
536
+ for (var _i = 0; _i < arguments.length; _i++) {
537
+ args[_i] = arguments[_i];
538
+ }
539
+ var transformedResult = transformResult.apply(void 0, __spreadArray([ctx.run({ value: value }, function () { return rule.apply(void 0, __spreadArray([value], args)); }),
540
+ ruleName,
541
+ value], args));
542
+ if (!transformedResult.pass) {
543
+ if (isEmpty(transformedResult.message)) {
544
+ throwError("enforce/" + ruleName + " failed with " + JSON.stringify(value));
545
+ }
546
+ else {
547
+ // Explicitly throw a string so that vest.test can pick it up as the validation error message
548
+ throw transformedResult.message;
549
+ }
550
+ }
551
+ return target;
552
+ };
553
+ }
554
+ }
555
+
556
+ function mapFirst(array, callback) {
557
+ var broke = false;
558
+ var breakoutValue = null;
559
+ for (var i = 0; i < array.length; i++) {
560
+ callback(array[i], breakout, i);
561
+ if (broke) {
562
+ return breakoutValue;
563
+ }
564
+ }
565
+ function breakout(value) {
566
+ broke = true;
567
+ breakoutValue = value;
568
+ }
569
+ }
570
+
571
+ // eslint-disable-next-line max-lines-per-function
572
+ function genEnforceLazy(key) {
573
+ var registeredRules = [];
574
+ var lazyMessage;
575
+ return addLazyRule(key);
576
+ // eslint-disable-next-line max-lines-per-function
577
+ function addLazyRule(ruleName) {
578
+ // eslint-disable-next-line max-lines-per-function
579
+ return function () {
580
+ var args = [];
581
+ for (var _i = 0; _i < arguments.length; _i++) {
582
+ args[_i] = arguments[_i];
583
+ }
584
+ var rule = getRule(ruleName);
585
+ registeredRules.push(function (value) {
586
+ return transformResult.apply(void 0, __spreadArray([rule.apply(void 0, __spreadArray([value], args)), ruleName, value], args));
587
+ });
588
+ var proxy = {
589
+ run: function (value) {
590
+ return defaultToPassing(mapFirst(registeredRules, function (rule, breakout) {
591
+ var _a;
592
+ var res = ctx.run({ value: value }, function () { return rule(value); });
593
+ if (!res.pass) {
594
+ breakout(ruleReturn(!!res.pass, (_a = optionalFunctionValue(lazyMessage, value, res.message)) !== null && _a !== void 0 ? _a : res.message));
595
+ }
596
+ }));
597
+ },
598
+ test: function (value) { return proxy.run(value).pass; },
599
+ message: function (message) {
600
+ if (message) {
601
+ lazyMessage = message;
602
+ }
603
+ return proxy;
604
+ }
605
+ };
606
+ if (!isProxySupported()) {
607
+ eachEnforceRule(function (ruleName) {
608
+ proxy[ruleName] = addLazyRule(ruleName);
609
+ });
610
+ return proxy;
611
+ }
612
+ // reassigning the proxy here is not pretty
613
+ // but it's a cleaner way of getting `run` and `test` for free
614
+ proxy = new Proxy(proxy, {
615
+ get: function (target, key) {
616
+ if (getRule(key)) {
617
+ return addLazyRule(key);
618
+ }
619
+ return target[key]; // already has `run` and `test` on it
620
+ }
621
+ });
622
+ return proxy;
623
+ };
624
+ }
625
+ }
626
+
627
+ /**
628
+ * Enforce is quite complicated, I want to explain it in detail.
629
+ * It is dynamic in nature, so a lot of proxy objects are involved.
630
+ *
631
+ * Enforce has two main interfaces
632
+ * 1. eager
633
+ * 2. lazy
634
+ *
635
+ * The eager interface is the most commonly used, and the easier to understand.
636
+ * It throws an error when a rule is not satisfied.
637
+ * The eager interface is declared in enforceEager.ts and it is quite simple to understand.
638
+ * enforce is called with a value, and the return value is a proxy object that points back to all the rules.
639
+ * When a rule is called, the value is mapped as its first argument, and if the rule passes, the same
640
+ * proxy object is returned. Otherwise, an error is thrown.
641
+ *
642
+ * The lazy interface works quite differently. It is declared in genEnforceLazy.ts.
643
+ * Rather than calling enforce directly, the lazy interface has all the rules as "methods" (only by proxy).
644
+ * Calling the first function in the chain will initialize an array of calls. It stores the different rule calls
645
+ * and the parameters passed to them. None of the rules are called yet.
646
+ * The rules are only invoked in sequence once either of these chained functions are called:
647
+ * 1. test(value)
648
+ * 2. run(value)
649
+ *
650
+ * Calling run or test will call all the rules in sequence, with the difference that test will only return a boolean value,
651
+ * while run will return an object with the validation result and an optional message created by the rule.
652
+ */
653
+ function genEnforce() {
654
+ var target = {
655
+ context: function () { return ctx.useX(); },
656
+ extend: function (customRules) {
657
+ assign(baseRules, customRules);
658
+ }
659
+ };
660
+ if (!isProxySupported()) {
661
+ eachEnforceRule(function (ruleName) {
662
+ // Only on the first rule access - start the chain of calls
663
+ target[ruleName] = genEnforceLazy(ruleName);
664
+ });
665
+ return assign(enforceEager, target);
666
+ }
667
+ return new Proxy(assign(enforceEager, target), {
668
+ get: function (target, key) {
669
+ if (key in target) {
670
+ return target[key];
671
+ }
672
+ if (!getRule(key)) {
673
+ return;
674
+ }
675
+ // Only on the first rule access - start the chain of calls
676
+ return genEnforceLazy(key);
677
+ }
678
+ });
679
+ }
680
+ var enforce = genEnforce();
681
+
682
+ /**
683
+ * @returns a unique numeric id.
684
+ */
685
+ var genId = (function (n) { return function () {
686
+ return "" + n++;
687
+ }; })(0);
688
+
45
689
  // eslint-disable-next-line max-lines-per-function
46
690
  function createState(onStateChange) {
47
691
  var state = {
@@ -178,7 +822,7 @@
178
822
  };
179
823
  }
180
824
 
181
- var context = context$1.createContext(function (ctxRef, parentContext) {
825
+ var context = createContext(function (ctxRef, parentContext) {
182
826
  return parentContext
183
827
  ? null
184
828
  : assign({}, {
@@ -186,6 +830,7 @@
186
830
  tests: {},
187
831
  groups: {}
188
832
  },
833
+ inclusion: {},
189
834
  isolate: {
190
835
  type: IsolateTypes.DEFAULT,
191
836
  keys: {
@@ -197,28 +842,6 @@
197
842
  }, ctxRef);
198
843
  });
199
844
 
200
- function bindNot(fn) {
201
- return function () {
202
- var args = [];
203
- for (var _i = 0; _i < arguments.length; _i++) {
204
- args[_i] = arguments[_i];
205
- }
206
- return !fn.apply(void 0, args);
207
- };
208
- }
209
-
210
- // The module is named "isArrayValue" since it
211
- // is conflicting with a nested npm dependency.
212
- // We may need to revisit this in the future.
213
- function isArray(value) {
214
- return Boolean(Array.isArray(value));
215
- }
216
-
217
- function isNull(value) {
218
- return value === null;
219
- }
220
- var isNotNull = bindNot(isNull);
221
-
222
845
  // This is sort of a map/filter in one function.
223
846
  // Normally, behaves like a nested-array map
224
847
  // Returning `null` will drop the element from the array
@@ -264,31 +887,11 @@
264
887
  return current;
265
888
  }
266
889
 
267
- function isUndefined(value) {
268
- return value === undefined;
269
- }
270
-
271
- function isNullish(value) {
272
- return isNull(value) || isUndefined(value);
273
- }
274
-
275
- function isStringValue(v) {
276
- return String(v) === v;
277
- }
278
-
279
890
  function shouldUseErrorAsMessage(message, error) {
280
891
  // kind of cheating with this safe guard, but it does the job
281
892
  return isUndefined(message) && isStringValue(error);
282
893
  }
283
894
 
284
- function lengthEquals(value, arg1) {
285
- return value.length === Number(arg1);
286
- }
287
-
288
- function longerThan(value, arg1) {
289
- return value.length > Number(arg1);
290
- }
291
-
292
895
  /**
293
896
  * Creates a cache function
294
897
  */
@@ -604,34 +1207,6 @@
604
1207
  return context.useX().isolate.type === IsolateTypes.EACH;
605
1208
  }
606
1209
 
607
- /**
608
- * A safe hasOwnProperty access
609
- */
610
- function hasOwnProperty(obj, key) {
611
- return Object.prototype.hasOwnProperty.call(obj, key);
612
- }
613
-
614
- function isNumber(value) {
615
- return Boolean(typeof value === 'number');
616
- }
617
-
618
- function isEmpty(value) {
619
- if (!value) {
620
- return true;
621
- }
622
- else if (isNumber(value)) {
623
- return value === 0;
624
- }
625
- else if (hasOwnProperty(value, 'length')) {
626
- return lengthEquals(value, 0);
627
- }
628
- else if (typeof value === 'object') {
629
- return lengthEquals(Object.keys(value), 0);
630
- }
631
- return true;
632
- }
633
- var isNotEmpty = bindNot(isEmpty);
634
-
635
1210
  function nonMatchingFieldName(testObject, fieldName) {
636
1211
  return !!fieldName && !matchingFieldName(testObject, fieldName);
637
1212
  }
@@ -719,42 +1294,6 @@
719
1294
  return testKey;
720
1295
  }
721
1296
 
722
- /*! *****************************************************************************
723
- Copyright (c) Microsoft Corporation.
724
-
725
- Permission to use, copy, modify, and/or distribute this software for any
726
- purpose with or without fee is hereby granted.
727
-
728
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
729
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
730
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
731
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
732
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
733
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
734
- PERFORMANCE OF THIS SOFTWARE.
735
- ***************************************************************************** */
736
-
737
- var __assign = function() {
738
- __assign = Object.assign || function __assign(t) {
739
- for (var s, i = 1, n = arguments.length; i < n; i++) {
740
- s = arguments[i];
741
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
742
- }
743
- return t;
744
- };
745
- return __assign.apply(this, arguments);
746
- };
747
-
748
- function __spreadArray(to, from, pack) {
749
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
750
- if (ar || !(i in from)) {
751
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
752
- ar[i] = from[i];
753
- }
754
- }
755
- return to.concat(ar || from);
756
- }
757
-
758
1297
  function either(a, b) {
759
1298
  return !!a !== !!b;
760
1299
  }
@@ -1263,13 +1802,14 @@
1263
1802
  return !!context.useX().skipped;
1264
1803
  }
1265
1804
  //Checks whether a certain test profile excluded by any of the exclusion groups.
1266
- // eslint-disable-next-line complexity, max-statements
1805
+ // eslint-disable-next-line complexity, max-statements, max-lines-per-function
1267
1806
  function isExcluded(testObject) {
1268
1807
  var fieldName = testObject.fieldName, groupName = testObject.groupName;
1269
1808
  if (isExcludedIndividually())
1270
1809
  return true;
1271
1810
  var context$1 = context.useX();
1272
1811
  var exclusion = context$1.exclusion;
1812
+ var inclusion = context$1.inclusion;
1273
1813
  var keyTests = exclusion.tests;
1274
1814
  var testValue = keyTests[fieldName];
1275
1815
  // if test is skipped
@@ -1299,8 +1839,12 @@
1299
1839
  if (isTestIncluded)
1300
1840
  return false;
1301
1841
  // If there is _ANY_ `only`ed test (and we already know this one isn't) return true
1302
- // Otherwise return false
1303
- return hasIncludedTests(keyTests);
1842
+ if (hasIncludedTests(keyTests)) {
1843
+ // Check if inclusion rules for this field (`include` hook)
1844
+ return !optionalFunctionValue(inclusion[fieldName]);
1845
+ }
1846
+ // We're done here. This field is not excluded
1847
+ return false;
1304
1848
  }
1305
1849
  // eslint-disable-next-line max-statements
1306
1850
  function isMissingFromIncludedGroup(groupName) {
@@ -1405,6 +1949,29 @@
1405
1949
  throwError("Wrong arguments passed to group. Group " + error + ".");
1406
1950
  }
1407
1951
 
1952
+ function include(fieldName) {
1953
+ var context$1 = context.useX();
1954
+ var inclusion = context$1.inclusion, exclusion = context$1.exclusion;
1955
+ if (!fieldName) {
1956
+ return { when: when };
1957
+ }
1958
+ inclusion[fieldName] = defaultTo(exclusion.tests[fieldName], true);
1959
+ return { when: when };
1960
+ function when(condition) {
1961
+ var context$1 = context.useX();
1962
+ var inclusion = context$1.inclusion, exclusion = context$1.exclusion;
1963
+ inclusion[fieldName] = function () {
1964
+ if (hasOwnProperty(exclusion.tests, fieldName)) {
1965
+ return defaultTo(exclusion.tests[fieldName], true);
1966
+ }
1967
+ if (isStringValue(condition)) {
1968
+ return Boolean(exclusion.tests[condition]);
1969
+ }
1970
+ return optionalFunctionValue(condition, optionalFunctionValue(produceDraft));
1971
+ };
1972
+ }
1973
+ }
1974
+
1408
1975
  /**
1409
1976
  * Conditionally omits tests from the suite.
1410
1977
  *
@@ -1472,8 +2039,6 @@
1472
2039
  });
1473
2040
  }
1474
2041
 
1475
- var isNotString = bindNot(isStringValue);
1476
-
1477
2042
  function isPromise(value) {
1478
2043
  return value && isFunction(value.then);
1479
2044
  }
@@ -1683,6 +2248,7 @@
1683
2248
  }
1684
2249
  }
1685
2250
 
2251
+ /* eslint-disable jest/valid-title */
1686
2252
  // eslint-disable-next-line max-lines-per-function
1687
2253
  function bindTestMemo(test) {
1688
2254
  var cache = createCache(100); // arbitrary cache size
@@ -1760,19 +2326,15 @@
1760
2326
  ctx.currentTest.warn();
1761
2327
  }
1762
2328
 
1763
- var VERSION = "3.3.0";
2329
+ var VERSION = "4.0.2-dev-72921c";
1764
2330
 
1765
- Object.defineProperty(exports, 'enforce', {
1766
- enumerable: true,
1767
- get: function () {
1768
- return n4s.enforce;
1769
- }
1770
- });
1771
2331
  exports.VERSION = VERSION;
1772
2332
  exports.context = context;
1773
2333
  exports.create = create;
1774
2334
  exports.each = each;
2335
+ exports.enforce = enforce;
1775
2336
  exports.group = group;
2337
+ exports.include = include;
1776
2338
  exports.omitWhen = omitWhen;
1777
2339
  exports.only = only;
1778
2340
  exports.optional = optional;