vest 4.4.2 → 4.5.0

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.
Files changed (51) hide show
  1. package/dist/cjs/classnames.development.js +16 -90
  2. package/dist/cjs/classnames.production.js +1 -1
  3. package/dist/cjs/enforce/compose.development.js +5 -58
  4. package/dist/cjs/enforce/compose.production.js +1 -1
  5. package/dist/cjs/enforce/compounds.development.js +8 -51
  6. package/dist/cjs/enforce/compounds.production.js +1 -1
  7. package/dist/cjs/enforce/schema.development.js +5 -57
  8. package/dist/cjs/enforce/schema.production.js +1 -1
  9. package/dist/cjs/parser.development.js +15 -89
  10. package/dist/cjs/parser.production.js +1 -1
  11. package/dist/cjs/promisify.development.js +2 -26
  12. package/dist/cjs/promisify.production.js +1 -1
  13. package/dist/cjs/vest.development.js +197 -452
  14. package/dist/cjs/vest.production.js +1 -1
  15. package/dist/es/classnames.development.js +14 -88
  16. package/dist/es/classnames.production.js +1 -1
  17. package/dist/es/enforce/compose.development.js +1 -54
  18. package/dist/es/enforce/compose.production.js +1 -1
  19. package/dist/es/enforce/compounds.development.js +2 -45
  20. package/dist/es/enforce/compounds.production.js +1 -1
  21. package/dist/es/enforce/schema.development.js +1 -53
  22. package/dist/es/enforce/schema.production.js +1 -1
  23. package/dist/es/parser.development.js +14 -88
  24. package/dist/es/parser.production.js +1 -1
  25. package/dist/es/promisify.development.js +1 -25
  26. package/dist/es/promisify.production.js +1 -1
  27. package/dist/es/vest.development.js +131 -387
  28. package/dist/es/vest.production.js +1 -1
  29. package/dist/umd/classnames.development.js +27 -56
  30. package/dist/umd/classnames.production.js +1 -1
  31. package/dist/umd/enforce/compose.development.js +111 -94
  32. package/dist/umd/enforce/compose.production.js +1 -1
  33. package/dist/umd/enforce/compounds.development.js +185 -168
  34. package/dist/umd/enforce/compounds.production.js +1 -1
  35. package/dist/umd/enforce/schema.development.js +134 -117
  36. package/dist/umd/enforce/schema.production.js +1 -1
  37. package/dist/umd/parser.development.js +27 -56
  38. package/dist/umd/parser.production.js +1 -1
  39. package/dist/umd/vest.development.js +398 -386
  40. package/dist/umd/vest.production.js +1 -1
  41. package/package.json +4 -3
  42. package/testUtils/__tests__/partition.test.ts +21 -0
  43. package/testUtils/mockThrowError.ts +2 -1
  44. package/testUtils/partition.ts +13 -0
  45. package/testUtils/suiteDummy.ts +1 -1
  46. package/types/enforce/compose.d.ts +17 -32
  47. package/types/enforce/compounds.d.ts +17 -32
  48. package/types/enforce/schema.d.ts +17 -32
  49. package/types/parser.d.ts +8 -7
  50. package/types/promisify.d.ts +20 -35
  51. package/types/vest.d.ts +45 -60
@@ -4,12 +4,6 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.schema = {}));
5
5
  }(this, (function (exports) { 'use strict';
6
6
 
7
- var assign = Object.assign;
8
-
9
- function isFunction(value) {
10
- return typeof value === 'function';
11
- }
12
-
13
7
  function bindNot(fn) {
14
8
  return function () {
15
9
  var args = [];
@@ -20,6 +14,32 @@
20
14
  };
21
15
  }
22
16
 
17
+ function isNumeric(value) {
18
+ var str = String(value);
19
+ var num = Number(value);
20
+ var result = !isNaN(parseFloat(str)) && !isNaN(Number(value)) && isFinite(num);
21
+ return Boolean(result);
22
+ }
23
+ var isNotNumeric = bindNot(isNumeric);
24
+
25
+ function numberEquals(value, eq) {
26
+ return isNumeric(value) && isNumeric(eq) && Number(value) === Number(eq);
27
+ }
28
+ var numberNotEquals = bindNot(numberEquals);
29
+
30
+ function lengthEquals(value, arg1) {
31
+ return numberEquals(value.length, arg1);
32
+ }
33
+ var lengthNotEquals = bindNot(lengthEquals);
34
+
35
+ function greaterThan(value, gt) {
36
+ return isNumeric(value) && isNumeric(gt) && Number(value) > Number(gt);
37
+ }
38
+
39
+ function longerThan(value, arg1) {
40
+ return greaterThan(value.length, arg1);
41
+ }
42
+
23
43
  function isNull(value) {
24
44
  return value === null;
25
45
  }
@@ -35,49 +55,115 @@
35
55
  }
36
56
  var isNotNullish = bindNot(isNullish);
37
57
 
58
+ function isFunction(value) {
59
+ return typeof value === 'function';
60
+ }
61
+
62
+ function optionalFunctionValue(value) {
63
+ var args = [];
64
+ for (var _i = 1; _i < arguments.length; _i++) {
65
+ args[_i - 1] = arguments[_i];
66
+ }
67
+ return isFunction(value) ? value.apply(void 0, args) : value;
68
+ }
69
+
70
+ function defaultTo(value, defaultValue) {
71
+ var _a;
72
+ return (_a = optionalFunctionValue(value)) !== null && _a !== void 0 ? _a : optionalFunctionValue(defaultValue);
73
+ }
74
+
75
+ // The module is named "isArrayValue" since it
76
+ // is conflicting with a nested npm dependency.
77
+ // We may need to revisit this in the future.
78
+ function isArray(value) {
79
+ return Boolean(Array.isArray(value));
80
+ }
81
+ var isNotArray = bindNot(isArray);
82
+
83
+ /**
84
+ * A safe hasOwnProperty access
85
+ */
86
+ function hasOwnProperty(obj, key) {
87
+ return Object.prototype.hasOwnProperty.call(obj, key);
88
+ }
89
+
90
+ var assign = Object.assign;
91
+
92
+ function invariant(condition,
93
+ // eslint-disable-next-line @typescript-eslint/ban-types
94
+ message) {
95
+ if (condition) {
96
+ return;
97
+ }
98
+ // If message is a string object (rather than string literal)
99
+ // Throw the value directly as a string
100
+ // Alternatively, throw an error with the message
101
+ throw message instanceof String
102
+ ? message.valueOf()
103
+ : new Error(message ? optionalFunctionValue(message) : message);
104
+ }
105
+ // eslint-disable-next-line @typescript-eslint/ban-types
106
+ function StringObject(value) {
107
+ return new String(optionalFunctionValue(value));
108
+ }
109
+
38
110
  function isStringValue(v) {
39
111
  return String(v) === v;
40
112
  }
41
113
 
42
- function endsWith(value, arg1) {
43
- return isStringValue(value) && isStringValue(arg1) && value.endsWith(arg1);
114
+ function isBoolean(value) {
115
+ return !!value === value;
44
116
  }
45
- var doesNotEndWith = bindNot(endsWith);
46
117
 
47
- function equals(value, arg1) {
48
- return value === arg1;
118
+ function mapFirst(array, callback) {
119
+ var broke = false;
120
+ var breakoutValue = null;
121
+ for (var i = 0; i < array.length; i++) {
122
+ callback(array[i], breakout, i);
123
+ if (broke) {
124
+ return breakoutValue;
125
+ }
126
+ }
127
+ function breakout(conditional, value) {
128
+ if (conditional) {
129
+ broke = true;
130
+ breakoutValue = value;
131
+ }
132
+ }
49
133
  }
50
- var notEquals = bindNot(equals);
51
134
 
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);
135
+ function isEmpty(value) {
136
+ if (!value) {
137
+ return true;
138
+ }
139
+ else if (hasOwnProperty(value, 'length')) {
140
+ return lengthEquals(value, 0);
141
+ }
142
+ else if (typeof value === 'object') {
143
+ return lengthEquals(Object.keys(value), 0);
144
+ }
145
+ return false;
57
146
  }
58
- var isNotNumeric = bindNot(isNumeric);
147
+ var isNotEmpty = bindNot(isEmpty);
59
148
 
60
- function greaterThan(value, gt) {
61
- return isNumeric(value) && isNumeric(gt) && Number(value) > Number(gt);
149
+ function isPositive(value) {
150
+ return greaterThan(value, 0);
62
151
  }
63
152
 
64
- function numberEquals(value, eq) {
65
- return isNumeric(value) && isNumeric(eq) && Number(value) === Number(eq);
153
+ function endsWith(value, arg1) {
154
+ return isStringValue(value) && isStringValue(arg1) && value.endsWith(arg1);
66
155
  }
67
- var numberNotEquals = bindNot(numberEquals);
156
+ var doesNotEndWith = bindNot(endsWith);
157
+
158
+ function equals(value, arg1) {
159
+ return value === arg1;
160
+ }
161
+ var notEquals = bindNot(equals);
68
162
 
69
163
  function greaterThanOrEquals(value, gte) {
70
164
  return numberEquals(value, gte) || greaterThan(value, gte);
71
165
  }
72
166
 
73
- // The module is named "isArrayValue" since it
74
- // is conflicting with a nested npm dependency.
75
- // We may need to revisit this in the future.
76
- function isArray(value) {
77
- return Boolean(Array.isArray(value));
78
- }
79
- var isNotArray = bindNot(isArray);
80
-
81
167
  function inside(value, arg1) {
82
168
  if (isArray(arg1)) {
83
169
  return arg1.indexOf(value) !== -1;
@@ -108,38 +194,8 @@
108
194
  }
109
195
  var isNotBlank = bindNot(isBlank);
110
196
 
111
- function isBoolean(value) {
112
- return !!value === value;
113
- }
114
-
115
197
  var isNotBoolean = bindNot(isBoolean);
116
198
 
117
- /**
118
- * A safe hasOwnProperty access
119
- */
120
- function hasOwnProperty(obj, key) {
121
- return Object.prototype.hasOwnProperty.call(obj, key);
122
- }
123
-
124
- function lengthEquals(value, arg1) {
125
- return numberEquals(value.length, arg1);
126
- }
127
- var lengthNotEquals = bindNot(lengthEquals);
128
-
129
- function isEmpty(value) {
130
- if (!value) {
131
- return true;
132
- }
133
- else if (hasOwnProperty(value, 'length')) {
134
- return lengthEquals(value, 0);
135
- }
136
- else if (typeof value === 'object') {
137
- return lengthEquals(Object.keys(value), 0);
138
- }
139
- return false;
140
- }
141
- var isNotEmpty = bindNot(isEmpty);
142
-
143
199
  /**
144
200
  * Validates that a given value is an even number
145
201
  */
@@ -179,10 +235,6 @@
179
235
  return false;
180
236
  };
181
237
 
182
- function isPositive(value) {
183
- return greaterThan(value, 0);
184
- }
185
-
186
238
  var isNotString = bindNot(isStringValue);
187
239
 
188
240
  function isTruthy(value) {
@@ -203,10 +255,6 @@
203
255
  }
204
256
  var isNotValueOf = bindNot(isValueOf);
205
257
 
206
- function longerThan(value, arg1) {
207
- return greaterThan(value.length, arg1);
208
- }
209
-
210
258
  function longerThanOrEquals(value, arg1) {
211
259
  return greaterThanOrEquals(value.length, arg1);
212
260
  }
@@ -327,37 +375,6 @@
327
375
  }
328
376
  }
329
377
 
330
- function optionalFunctionValue(value) {
331
- var args = [];
332
- for (var _i = 1; _i < arguments.length; _i++) {
333
- args[_i - 1] = arguments[_i];
334
- }
335
- return isFunction(value) ? value.apply(void 0, args) : value;
336
- }
337
-
338
- function defaultTo(value, defaultValue) {
339
- var _a;
340
- return (_a = optionalFunctionValue(value)) !== null && _a !== void 0 ? _a : optionalFunctionValue(defaultValue);
341
- }
342
-
343
- function invariant(condition,
344
- // eslint-disable-next-line @typescript-eslint/ban-types
345
- message) {
346
- if (condition) {
347
- return;
348
- }
349
- // If message is a string object (rather than string literal)
350
- // Throw the value directly as a string
351
- // Alternatively, throw an error with the message
352
- throw message instanceof String
353
- ? message.valueOf()
354
- : new Error(message ? optionalFunctionValue(message) : message);
355
- }
356
- // eslint-disable-next-line @typescript-eslint/ban-types
357
- function StringObject(value) {
358
- return new String(optionalFunctionValue(value));
359
- }
360
-
361
378
  // eslint-disable-next-line max-lines-per-function
362
379
  function createContext(init) {
363
380
  var storage = { ancestry: [] };
@@ -515,30 +532,47 @@
515
532
 
516
533
  function enforceEager(value) {
517
534
  var target = {};
535
+ // This condition is for when we don't have proxy support (ES5).
536
+ // In this case, we need to manually assign the rules to the target object on runtime.
537
+ // The follow up proxy block is used in case we do have proxy support, and we can assign each rule upon invocation.
518
538
  if (!isProxySupported()) {
539
+ // We iterate over each of the rules, and add them to the target object being return by enforce
519
540
  eachEnforceRule(function (ruleName, ruleFn) {
541
+ // We then wrap the rule with `genRuleCall` that adds the base enforce behavior
520
542
  target[ruleName] = genRuleCall(target, ruleFn, ruleName);
521
543
  });
522
544
  return target;
523
545
  }
546
+ // We create a proxy intercepting access to the target object (which is empty).
524
547
  var proxy = new Proxy(target, {
525
548
  get: function (_, ruleName) {
549
+ // On property access, we identify if it is a rule or not.
526
550
  var rule = getRule(ruleName);
551
+ // If it is a rule, we wrap it with `genRuleCall` that adds the base enforce behavior
527
552
  if (rule) {
528
553
  return genRuleCall(proxy, rule, ruleName);
529
554
  }
530
555
  }
531
556
  });
532
557
  return proxy;
558
+ // This function is used to wrap a rule with the base enforce behavior
559
+ // It takes the target object, the rule function, and the rule name
560
+ // It then returns the rule, in a manner that can be used by enforce
533
561
  function genRuleCall(target, rule, ruleName) {
534
562
  return function ruleCall() {
535
563
  var args = [];
536
564
  for (var _i = 0; _i < arguments.length; _i++) {
537
565
  args[_i] = arguments[_i];
538
566
  }
567
+ // Order of operation:
568
+ // 1. Create a context with the value being enforced
569
+ // 2. Call the rule within the context, and pass over the arguments passed to it
570
+ // 3. Transform the result to the correct output format
539
571
  var transformedResult = ctx.run({ value: value }, function () {
540
572
  return transformResult.apply(void 0, __spreadArray([rule.apply(void 0, __spreadArray([value], args, false)), ruleName, value], args, false));
541
573
  });
574
+ // On rule failure (the result is false), we either throw an error
575
+ // or throw a string value if the rule has a message defined in it.
542
576
  invariant(transformedResult.pass, isNullish(transformedResult.message)
543
577
  ? "enforce/".concat(ruleName, " failed with ").concat(JSON.stringify(value))
544
578
  : StringObject(transformedResult.message));
@@ -547,23 +581,6 @@
547
581
  }
548
582
  }
549
583
 
550
- function mapFirst(array, callback) {
551
- var broke = false;
552
- var breakoutValue = null;
553
- for (var i = 0; i < array.length; i++) {
554
- callback(array[i], breakout, i);
555
- if (broke) {
556
- return breakoutValue;
557
- }
558
- }
559
- function breakout(conditional, value) {
560
- if (conditional) {
561
- broke = true;
562
- breakoutValue = value;
563
- }
564
- }
565
- }
566
-
567
584
  // eslint-disable-next-line max-lines-per-function
568
585
  function genEnforceLazy(key) {
569
586
  var registeredRules = [];
@@ -1 +1 @@
1
- "use strict";!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).schema={})}(this,(function(n){function t(n){return"function"==typeof n}function r(n){return function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return!n.apply(void 0,t)}}function e(n){return null===n}function u(n){return void 0===n}function i(n){return null===n||u(n)}function o(n){return String(n)===n}function a(n,t){return o(n)&&o(t)&&n.endsWith(t)}function f(n,t){return n===t}function s(n){var t=Number(n);return!(isNaN(parseFloat(String(n)))||isNaN(Number(n))||!isFinite(t))}function c(n,t){return s(n)&&s(t)&&Number(n)>Number(t)}function l(n,t){return s(n)&&s(t)&&Number(n)===Number(t)}function p(n,t){return l(n,t)||c(n,t)}function v(n){return!!Array.isArray(n)}function h(n,t){return!!(v(t)||o(t)&&o(n))&&-1!==t.indexOf(n)}function y(n,t){return s(n)&&s(t)&&Number(n)<Number(t)}function N(n,t){return l(n,t)||y(n,t)}function d(n,t,r){return p(n,t)&&N(n,r)}function g(n){return i(n)||o(n)&&!n.trim()}function m(n){return!!n===n}function b(n,t){return l(n.length,t)}function O(n){return!n||(Object.prototype.hasOwnProperty.call(n,"length")?b(n,0):"object"==typeof n&&b(Object.keys(n),0))}function x(n,t){return n in t}function E(n){return Number.isNaN(n)}function w(n){return"number"==typeof n}function T(n){return!!n}function q(n,t){if(i(t))return!1;for(var r in t)if(t[r]===n)return!0;return!1}function j(n,t){return t instanceof RegExp?t.test(n):!!o(t)&&new RegExp(t).test(n)}function S(n,t){return o(n)&&o(t)&&n.startsWith(t)}function P(n){for(var r in pn){var e=pn[r];t(e)&&n(r,e)}}function A(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 B(n,t){var r;return null!==(r=A(n))&&void 0!==r?r:A(t)}function W(n,t){if(!n)throw t instanceof String?t.valueOf():Error(t?A(t):t)}function k(){return null}function F(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 I(){try{return t(Proxy)}catch(n){return!1}}function J(n,t){return n={pass:n},t&&(n.message=t),n}function K(n,t,r){for(var e=[],u=3;u<arguments.length;u++)e[u-3]=arguments[u];return W(m(n)||n&&m(n.pass),"Incorrect return value for rule: "+JSON.stringify(n)),m(n)?J(n):J(n.pass,A.apply(void 0,F([n.message,t,r],e,!1)))}function M(n){function t(t,r,e){return function(){for(var u=[],o=0;o<arguments.length;o++)u[o]=arguments[o];return W((o=vn.run({value:n},(function(){return K.apply(void 0,F([r.apply(void 0,F([n],u,!1)),e,n],u,!1))}))).pass,i(o.message)?"enforce/".concat(e," failed with ").concat(JSON.stringify(n)):new String(A(o.message))),t}}var r={};if(!I())return P((function(n,e){r[n]=t(r,e,n)})),r;var e=new Proxy(r,{get:function(n,r){if(n=pn[r])return t(e,n,r)}});return e}function R(n,t){function r(n,t){n&&(e=!0,u=t)}for(var e=!1,u=null,i=0;i<n.length;i++)if(t(n[i],r,i),e)return u}function U(n){var t,r=[];return function n(e){return function(){for(var u=[],i=0;i<arguments.length;i++)u[i]=arguments[i];var o=pn[e];r.push((function(n){return K.apply(void 0,F([o.apply(void 0,F([n],u,!1)),e,n],u,!1))}));var a={run:function(n){return B(R(r,(function(r,e){var u,i=vn.run({value:n},(function(){return r(n)}));e(!i.pass,J(!!i.pass,null!==(u=A(t,n,i.message))&&void 0!==u?u:i.message))})),J(!0))},test:function(n){return a.run(n).pass},message:function(n){return n&&(t=n),a}};return I()?a=new Proxy(a,{get:function(t,r){return pn[r]?n(r):t[r]}}):(P((function(t){a[t]=n(t)})),a)}}(n)}function V(n,t){try{return n.run(t)}catch(n){return J(!1)}}function X(n,t){var r,e=function(r){var e=n[r],u=t[r];if(!(r=vn.run({value:e,set:!0,meta:{key:r}},(function(){return V(u,e)}))).pass)return{value:r}};for(r in t){var u=e(r);if("object"==typeof u)return u.value}return J(!0)}var _=Object.assign,z=r(e),C=r(u),D=r(i),G=r(a),H=r(f),L=r(s),Q=r(l),Y=r(v),Z=r(h),$=r(d),nn=r(g),tn=r(m),rn=r(b),en=r(O),un=r(x),on=r(E),an=r(w),fn=r(o),sn=r(T),cn=r(q),ln=r(j),pn={condition:function(n,t){try{return t(n)}catch(n){return!1}},doesNotEndWith:G,doesNotStartWith:r(S),endsWith:a,equals:f,greaterThan:c,greaterThanOrEquals:p,gt:c,gte:p,inside:h,isArray:v,isBetween:d,isBlank:g,isBoolean:m,isEmpty:O,isEven:function(n){return!!s(n)&&0==n%2},isFalsy:sn,isKeyOf:x,isNaN:E,isNegative:function(n){return y(n,0)},isNotArray:Y,isNotBetween:$,isNotBlank:nn,isNotBoolean:tn,isNotEmpty:en,isNotKeyOf:un,isNotNaN:on,isNotNull:z,isNotNullish:D,isNotNumber:an,isNotNumeric:L,isNotString:fn,isNotUndefined:C,isNotValueOf:cn,isNull:e,isNullish:i,isNumber:w,isNumeric:s,isOdd:function(n){return!!s(n)&&0!=n%2},isPositive:function(n){return c(n,0)},isString:o,isTruthy:T,isUndefined:u,isValueOf:q,lengthEquals:b,lengthNotEquals:rn,lessThan:y,lessThanOrEquals:N,longerThan:function(n,t){return c(n.length,t)},longerThanOrEquals:function(n,t){return p(n.length,t)},lt:y,lte:N,matches:j,notEquals:H,notInside:Z,notMatches:ln,numberEquals:l,numberNotEquals:Q,shorterThan:function(n,t){return y(n.length,t)},shorterThanOrEquals:function(n,t){return N(n.length,t)},startsWith:S},vn=function(n){function t(t,u){var i,o,a=r();return t=_({},a||{},null!==(i=A(n,t,a))&&void 0!==i?i:t),i=e.ctx=Object.freeze(t),e.ancestry.unshift(i),u=u(i),e.ancestry.shift(),e.ctx=null!==(o=e.ancestry[0])&&void 0!==o?o:null,u}function r(){return e.ctx}var e={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:r,useX:function(n){var t=r();return W(t,B(n,"Context was used after it was closed")),t}}}((function(n,t){var r={value:n.value,meta:n.meta||{}};return t?n.set?_(r,{parent:function(){return t?{value:t.value,meta:t.meta,parent:t.parent}:t}}):t:_(r,{parent:k})})),hn=function(){function n(){if(!I())return P((function(n){t[n]=U(n)})),_(M,t)}var t={context:function(){return vn.useX()},extend:function(t){_(pn,t),n()}};return n(),new Proxy(_(M,t),{get:function(n,t){return t in n?n[t]:pn[t]?U(t):void 0}})}();hn.extend({isArrayOf:function(n,t){return B(R(n,(function(n,r,e){r(!(e=vn.run({value:n,set:!0,meta:{index:e}},(function(){return V(t,n)}))).pass,e)})),J(!0))},loose:X,optional:function(n,t){return i(n)?J(!0):V(t,n)},shape:function(n,t){var r=X(n,t);if(!r.pass)return r;for(var e in n)if(!Object.prototype.hasOwnProperty.call(t,e))return J(!1);return J(!0)}}),n.partial=function(n){var t,r={};for(t in n)r[t]=hn.optional(n[t]);return r},Object.defineProperty(n,"__esModule",{value:!0})}));
1
+ "use strict";!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).schema={})}(this,(function(n){function t(n){return function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return!n.apply(void 0,t)}}function r(n){var t=Number(n);return!(isNaN(parseFloat(String(n)))||isNaN(Number(n))||!isFinite(t))}function e(n,t){return r(n)&&r(t)&&Number(n)===Number(t)}function u(n,t){return e(n.length,t)}function i(n,t){return r(n)&&r(t)&&Number(n)>Number(t)}function o(n){return null===n}function a(n){return void 0===n}function f(n){return null===n||a(n)}function s(n){return"function"==typeof n}function c(n){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];return s(n)?n.apply(void 0,t):n}function l(n,t){var r;return null!==(r=c(n))&&void 0!==r?r:c(t)}function p(n){return!!Array.isArray(n)}function v(n,t){if(!n)throw t instanceof String?t.valueOf():Error(t?c(t):t)}function h(n){return String(n)===n}function y(n){return!!n===n}function N(n,t){function r(n,t){n&&(e=!0,u=t)}for(var e=!1,u=null,i=0;i<n.length;i++)if(t(n[i],r,i),e)return u}function d(n){return!n||(Object.prototype.hasOwnProperty.call(n,"length")?u(n,0):"object"==typeof n&&u(Object.keys(n),0))}function g(n,t){return h(n)&&h(t)&&n.endsWith(t)}function m(n,t){return n===t}function b(n,t){return e(n,t)||i(n,t)}function O(n,t){return!!(p(t)||h(t)&&h(n))&&-1!==t.indexOf(n)}function x(n,t){return r(n)&&r(t)&&Number(n)<Number(t)}function E(n,t){return e(n,t)||x(n,t)}function w(n,t,r){return b(n,t)&&E(n,r)}function T(n){return f(n)||h(n)&&!n.trim()}function q(n,t){return n in t}function j(n){return Number.isNaN(n)}function S(n){return"number"==typeof n}function P(n){return!!n}function A(n,t){if(f(t))return!1;for(var r in t)if(t[r]===n)return!0;return!1}function B(n,t){return t instanceof RegExp?t.test(n):!!h(t)&&new RegExp(t).test(n)}function W(n,t){return h(n)&&h(t)&&n.startsWith(t)}function k(n){for(var t in pn){var r=pn[t];s(r)&&n(t,r)}}function F(){return null}function I(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 J(){try{return s(Proxy)}catch(n){return!1}}function K(n,t){return n={pass:n},t&&(n.message=t),n}function M(n,t,r){for(var e=[],u=3;u<arguments.length;u++)e[u-3]=arguments[u];return v(y(n)||n&&y(n.pass),"Incorrect return value for rule: "+JSON.stringify(n)),y(n)?K(n):K(n.pass,c.apply(void 0,I([n.message,t,r],e,!1)))}function R(n){function t(t,r,e){return function(){for(var u=[],i=0;i<arguments.length;i++)u[i]=arguments[i];return v((i=vn.run({value:n},(function(){return M.apply(void 0,I([r.apply(void 0,I([n],u,!1)),e,n],u,!1))}))).pass,f(i.message)?"enforce/".concat(e," failed with ").concat(JSON.stringify(n)):new String(c(i.message))),t}}var r={};if(!J())return k((function(n,e){r[n]=t(r,e,n)})),r;var e=new Proxy(r,{get:function(n,r){if(n=pn[r])return t(e,n,r)}});return e}function U(n){var t,r=[];return function n(e){return function(){for(var u=[],i=0;i<arguments.length;i++)u[i]=arguments[i];var o=pn[e];r.push((function(n){return M.apply(void 0,I([o.apply(void 0,I([n],u,!1)),e,n],u,!1))}));var a={run:function(n){return l(N(r,(function(r,e){var u,i=vn.run({value:n},(function(){return r(n)}));e(!i.pass,K(!!i.pass,null!==(u=c(t,n,i.message))&&void 0!==u?u:i.message))})),K(!0))},test:function(n){return a.run(n).pass},message:function(n){return n&&(t=n),a}};return J()?a=new Proxy(a,{get:function(t,r){return pn[r]?n(r):t[r]}}):(k((function(t){a[t]=n(t)})),a)}}(n)}function V(n,t){try{return n.run(t)}catch(n){return K(!1)}}function X(n,t){var r,e=function(r){var e=n[r],u=t[r];if(!(r=vn.run({value:e,set:!0,meta:{key:r}},(function(){return V(u,e)}))).pass)return{value:r}};for(r in t){var u=e(r);if("object"==typeof u)return u.value}return K(!0)}var _=t(r),z=t(e),C=t(u),D=t(o),G=t(a),H=t(f),L=t(p),Q=Object.assign,Y=t(d),Z=t(g),$=t(m),nn=t(O),tn=t(w),rn=t(T),en=t(y),un=t(q),on=t(j),an=t(S),fn=t(h),sn=t(P),cn=t(A),ln=t(B),pn={condition:function(n,t){try{return t(n)}catch(n){return!1}},doesNotEndWith:Z,doesNotStartWith:t(W),endsWith:g,equals:m,greaterThan:i,greaterThanOrEquals:b,gt:i,gte:b,inside:O,isArray:p,isBetween:w,isBlank:T,isBoolean:y,isEmpty:d,isEven:function(n){return!!r(n)&&0==n%2},isFalsy:sn,isKeyOf:q,isNaN:j,isNegative:function(n){return x(n,0)},isNotArray:L,isNotBetween:tn,isNotBlank:rn,isNotBoolean:en,isNotEmpty:Y,isNotKeyOf:un,isNotNaN:on,isNotNull:D,isNotNullish:H,isNotNumber:an,isNotNumeric:_,isNotString:fn,isNotUndefined:G,isNotValueOf:cn,isNull:o,isNullish:f,isNumber:S,isNumeric:r,isOdd:function(n){return!!r(n)&&0!=n%2},isPositive:function(n){return i(n,0)},isString:h,isTruthy:P,isUndefined:a,isValueOf:A,lengthEquals:u,lengthNotEquals:C,lessThan:x,lessThanOrEquals:E,longerThan:function(n,t){return i(n.length,t)},longerThanOrEquals:function(n,t){return b(n.length,t)},lt:x,lte:E,matches:B,notEquals:$,notInside:nn,notMatches:ln,numberEquals:e,numberNotEquals:z,shorterThan:function(n,t){return x(n.length,t)},shorterThanOrEquals:function(n,t){return E(n.length,t)},startsWith:W},vn=function(n){function t(t,u){var i,o,a=r();return t=Q({},a||{},null!==(i=c(n,t,a))&&void 0!==i?i:t),i=e.ctx=Object.freeze(t),e.ancestry.unshift(i),u=u(i),e.ancestry.shift(),e.ctx=null!==(o=e.ancestry[0])&&void 0!==o?o:null,u}function r(){return e.ctx}var e={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:r,useX:function(n){var t=r();return v(t,l(n,"Context was used after it was closed")),t}}}((function(n,t){var r={value:n.value,meta:n.meta||{}};return t?n.set?Q(r,{parent:function(){return t?{value:t.value,meta:t.meta,parent:t.parent}:t}}):t:Q(r,{parent:F})})),hn=function(){function n(){if(!J())return k((function(n){t[n]=U(n)})),Q(R,t)}var t={context:function(){return vn.useX()},extend:function(t){Q(pn,t),n()}};return n(),new Proxy(Q(R,t),{get:function(n,t){return t in n?n[t]:pn[t]?U(t):void 0}})}();hn.extend({isArrayOf:function(n,t){return l(N(n,(function(n,r,e){r(!(e=vn.run({value:n,set:!0,meta:{index:e}},(function(){return V(t,n)}))).pass,e)})),K(!0))},loose:X,optional:function(n,t){return f(n)?K(!0):V(t,n)},shape:function(n,t){var r=X(n,t);if(!r.pass)return r;for(var e in n)if(!Object.prototype.hasOwnProperty.call(t,e))return K(!1);return K(!0)}}),n.partial=function(n){var t,r={};for(t in n)r[t]=hn.optional(n[t]);return r},Object.defineProperty(n,"__esModule",{value:!0})}));
@@ -1,8 +1,19 @@
1
1
  (function (global, factory) {
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.parser = {}));
5
- }(this, (function (exports) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vest')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'vest'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.parser = {}, global.vest));
5
+ }(this, (function (exports, vest) { 'use strict';
6
+
7
+ function isNumeric(value) {
8
+ var str = String(value);
9
+ var num = Number(value);
10
+ var result = !isNaN(parseFloat(str)) && !isNaN(Number(value)) && isFinite(num);
11
+ return Boolean(result);
12
+ }
13
+
14
+ function greaterThan(value, gt) {
15
+ return isNumeric(value) && isNumeric(gt) && Number(value) > Number(gt);
16
+ }
6
17
 
7
18
  function isFunction(value) {
8
19
  return typeof value === 'function';
@@ -16,11 +27,6 @@
16
27
  return isFunction(value) ? value.apply(void 0, args) : value;
17
28
  }
18
29
 
19
- function defaultTo(value, defaultValue) {
20
- var _a;
21
- return (_a = optionalFunctionValue(value)) !== null && _a !== void 0 ? _a : optionalFunctionValue(defaultValue);
22
- }
23
-
24
30
  /**
25
31
  * A safe hasOwnProperty access
26
32
  */
@@ -42,72 +48,37 @@
42
48
  : new Error(message ? optionalFunctionValue(message) : message);
43
49
  }
44
50
 
45
- function isNumeric(value) {
46
- var str = String(value);
47
- var num = Number(value);
48
- var result = !isNaN(parseFloat(str)) && !isNaN(Number(value)) && isFinite(num);
49
- return Boolean(result);
50
- }
51
-
52
- function greaterThan(value, gt) {
53
- return isNumeric(value) && isNumeric(gt) && Number(value) > Number(gt);
54
- }
55
-
56
51
  function isPositive(value) {
57
52
  return greaterThan(value, 0);
58
53
  }
59
54
 
60
- var Severity;
61
- (function (Severity) {
62
- Severity["WARNINGS"] = "warnings";
63
- Severity["ERRORS"] = "errors";
64
- })(Severity || (Severity = {}));
65
- var SeverityCount;
66
- (function (SeverityCount) {
67
- SeverityCount["ERROR_COUNT"] = "errorCount";
68
- SeverityCount["WARN_COUNT"] = "warnCount";
69
- })(SeverityCount || (SeverityCount = {}));
70
-
71
- // eslint-disable-next-line max-lines-per-function
72
- function parse(res) {
73
- invariant(res && hasOwnProperty(res, 'valid'), "Vest parser: expected argument at position 0 to be Vest's result object.");
55
+ // eslint-disable-next-line max-statements
56
+ function parse(summary) {
57
+ invariant(summary && hasOwnProperty(summary, 'valid'), "Vest parser: expected argument at position 0 to be Vest's result object.");
58
+ var sel = vest.suiteSelectors(summary);
74
59
  var testedStorage = {};
75
60
  var selectors = {
76
- invalid: hasErrors,
61
+ invalid: sel.hasErrors,
77
62
  tested: isTested,
78
63
  untested: isUntested,
79
- valid: isValid,
80
- warning: hasWarnings
64
+ valid: sel.isValid,
65
+ warning: sel.hasWarnings
81
66
  };
82
67
  return selectors;
68
+ // Booleans
83
69
  function isTested(fieldName) {
84
70
  if (!fieldName) {
85
- return isPositive(res.testCount);
71
+ return isPositive(summary.testCount);
86
72
  }
87
73
  if (hasOwnProperty(testedStorage, fieldName))
88
74
  return testedStorage[fieldName];
89
75
  testedStorage[fieldName] =
90
- hasOwnProperty(res.tests, fieldName) &&
91
- isPositive(res.tests[fieldName].testCount);
76
+ hasOwnProperty(summary.tests, fieldName) &&
77
+ isPositive(summary.tests[fieldName].testCount);
92
78
  return selectors.tested(fieldName);
93
79
  }
94
80
  function isUntested(fieldName) {
95
- return res.testCount === 0 || !selectors.tested(fieldName);
96
- }
97
- function isValid(fieldName) {
98
- var _a;
99
- return fieldName ? Boolean((_a = res.tests[fieldName]) === null || _a === void 0 ? void 0 : _a.valid) : res.valid;
100
- }
101
- function hasWarnings(fieldName) {
102
- return hasFailures(SeverityCount.WARN_COUNT, fieldName);
103
- }
104
- function hasErrors(fieldName) {
105
- return hasFailures(SeverityCount.ERROR_COUNT, fieldName);
106
- }
107
- function hasFailures(countKey, fieldName) {
108
- var _a;
109
- var failureCount = defaultTo(fieldName ? (_a = res.tests[fieldName]) === null || _a === void 0 ? void 0 : _a[countKey] : res[countKey], 0);
110
- return isPositive(failureCount);
81
+ return !(isPositive(summary.testCount) && selectors.tested(fieldName));
111
82
  }
112
83
  }
113
84
 
@@ -1 +1 @@
1
- "use strict";!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).parser={})}(this,(function(t){function e(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];return"function"==typeof t?t.apply(void 0,e):t}function n(t){var e=Number(t);return!(isNaN(parseFloat(String(t)))||isNaN(Number(t))||!isFinite(e))}function r(t,e){return n(t)&&n(e)&&Number(t)>Number(e)}var o,i,u;(i=o||(o={})).WARNINGS="warnings",i.ERRORS="errors",function(t){t.ERROR_COUNT="errorCount",t.WARN_COUNT="warnCount"}(u||(u={})),t.parse=function(t){function n(n,o){var i,u;return n=o?null===(i=t.tests[o])||void 0===i?void 0:i[n]:t[n],r(i=null!==(u=e(n))&&void 0!==u?u:e(0),0)}!function(t,n){if(!t)throw n instanceof String?n.valueOf():Error(n?e(n):n)}(t&&Object.prototype.hasOwnProperty.call(t,"valid"),"Vest parser: expected argument at position 0 to be Vest's result object.");var o={},i={invalid:function(t){return n(u.ERROR_COUNT,t)},tested:function(e){return e?Object.prototype.hasOwnProperty.call(o,e)?o[e]:(o[e]=Object.prototype.hasOwnProperty.call(t.tests,e)&&r(t.tests[e].testCount,0),i.tested(e)):r(t.testCount,0)},untested:function(e){return 0===t.testCount||!i.tested(e)},valid:function(e){var n;return e?!(null===(n=t.tests[e])||void 0===n||!n.valid):t.valid},warning:function(t){return n(u.WARN_COUNT,t)}};return i},Object.defineProperty(t,"__esModule",{value:!0})}));
1
+ "use strict";!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vest")):"function"==typeof define&&define.amd?define(["exports","vest"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).parser={},e.vest)}(this,(function(e,t){function r(e){var t=Number(e);return!(isNaN(parseFloat(String(e)))||isNaN(Number(e))||!isFinite(t))}function n(e,t){return r(e)&&r(t)&&Number(e)>Number(t)}e.parse=function(e){!function(e,t){if(!e)throw t instanceof String?t.valueOf():Error(t?function(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];return"function"==typeof e?e.apply(void 0,t):e}(t):t)}(e&&Object.prototype.hasOwnProperty.call(e,"valid"),"Vest parser: expected argument at position 0 to be Vest's result object.");var r=t.suiteSelectors(e),o={},s={invalid:r.hasErrors,tested:function(t){return t?Object.prototype.hasOwnProperty.call(o,t)?o[t]:(o[t]=Object.prototype.hasOwnProperty.call(e.tests,t)&&n(e.tests[t].testCount,0),s.tested(t)):n(e.testCount,0)},untested:function(t){return!(n(e.testCount,0)&&s.tested(t))},valid:r.isValid,warning:r.hasWarnings};return s},Object.defineProperty(e,"__esModule",{value:!0})}));