vest 4.2.2 → 4.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/cjs/classnames.development.js +76 -28
  2. package/dist/cjs/classnames.production.js +1 -1
  3. package/dist/cjs/enforce/compose.development.js +28 -60
  4. package/dist/cjs/enforce/compose.production.js +1 -1
  5. package/dist/cjs/enforce/compounds.development.js +17 -2
  6. package/dist/cjs/enforce/compounds.production.js +1 -1
  7. package/dist/cjs/enforce/schema.development.js +1 -1
  8. package/dist/cjs/parser.development.js +84 -22
  9. package/dist/cjs/parser.production.js +1 -1
  10. package/dist/cjs/promisify.development.js +21 -8
  11. package/dist/cjs/promisify.production.js +1 -1
  12. package/dist/cjs/vest.development.js +297 -294
  13. package/dist/cjs/vest.production.js +1 -1
  14. package/dist/es/classnames.development.js +76 -28
  15. package/dist/es/classnames.production.js +1 -1
  16. package/dist/es/enforce/compose.development.js +28 -60
  17. package/dist/es/enforce/compose.production.js +1 -1
  18. package/dist/es/enforce/compounds.development.js +17 -2
  19. package/dist/es/enforce/compounds.production.js +1 -1
  20. package/dist/es/enforce/schema.development.js +1 -1
  21. package/dist/es/parser.development.js +84 -22
  22. package/dist/es/parser.production.js +1 -1
  23. package/dist/es/promisify.development.js +21 -8
  24. package/dist/es/promisify.production.js +1 -1
  25. package/dist/es/vest.development.js +297 -294
  26. package/dist/es/vest.production.js +1 -1
  27. package/dist/umd/classnames.development.js +76 -28
  28. package/dist/umd/classnames.production.js +1 -1
  29. package/dist/umd/enforce/compose.development.js +94 -104
  30. package/dist/umd/enforce/compose.production.js +1 -1
  31. package/dist/umd/enforce/compounds.development.js +39 -41
  32. package/dist/umd/enforce/compounds.production.js +1 -1
  33. package/dist/umd/enforce/schema.development.js +40 -42
  34. package/dist/umd/enforce/schema.production.js +1 -1
  35. package/dist/umd/parser.development.js +84 -22
  36. package/dist/umd/parser.production.js +1 -1
  37. package/dist/umd/promisify.development.js +21 -8
  38. package/dist/umd/promisify.production.js +1 -1
  39. package/dist/umd/vest.development.js +264 -283
  40. package/dist/umd/vest.production.js +1 -1
  41. package/package.json +3 -3
  42. package/testUtils/mockThrowError.ts +3 -6
  43. package/testUtils/suiteDummy.ts +5 -1
  44. package/types/classnames.d.ts +13 -54
  45. package/types/enforce/compose.d.ts +22 -21
  46. package/types/enforce/compounds.d.ts +24 -23
  47. package/types/enforce/schema.d.ts +26 -25
  48. package/types/parser.d.ts +12 -53
  49. package/types/promisify.d.ts +19 -15
  50. package/types/vest.d.ts +66 -61
@@ -5,10 +5,32 @@ function isFunction(value) {
5
5
  }
6
6
 
7
7
  /**
8
- * Throws a timed out error.
8
+ * A safe hasOwnProperty access
9
9
  */
10
- function throwError(devMessage, productionMessage) {
11
- throw new Error(devMessage );
10
+ function hasOwnProperty(obj, key) {
11
+ return Object.prototype.hasOwnProperty.call(obj, key);
12
+ }
13
+
14
+ function optionalFunctionValue(value) {
15
+ var args = [];
16
+ for (var _i = 1; _i < arguments.length; _i++) {
17
+ args[_i - 1] = arguments[_i];
18
+ }
19
+ return isFunction(value) ? value.apply(void 0, args) : value;
20
+ }
21
+
22
+ function invariant(condition,
23
+ // eslint-disable-next-line @typescript-eslint/ban-types
24
+ message) {
25
+ if (condition) {
26
+ return;
27
+ }
28
+ // If message is a string object (rather than string literal)
29
+ // Throw the value directly as a string
30
+ // Alternatively, throw an error with the message
31
+ throw message instanceof String
32
+ ? message.valueOf()
33
+ : new Error(message ? optionalFunctionValue(message) : message);
12
34
  }
13
35
 
14
36
  function isNumeric(value) {
@@ -22,35 +44,64 @@ function greaterThan(value, gt) {
22
44
  return isNumeric(value) && isNumeric(gt) && Number(value) > Number(gt);
23
45
  }
24
46
 
25
- /**
26
- * A safe hasOwnProperty access
27
- */
28
- function hasOwnProperty(obj, key) {
29
- return Object.prototype.hasOwnProperty.call(obj, key);
47
+ function isPositive(value) {
48
+ return greaterThan(value, 0);
30
49
  }
31
50
 
51
+ var Severity;
52
+ (function (Severity) {
53
+ Severity["WARNINGS"] = "warnings";
54
+ Severity["ERRORS"] = "errors";
55
+ })(Severity || (Severity = {}));
56
+ var SeverityCount;
57
+ (function (SeverityCount) {
58
+ SeverityCount["ERROR_COUNT"] = "errorCount";
59
+ SeverityCount["WARN_COUNT"] = "warnCount";
60
+ })(SeverityCount || (SeverityCount = {}));
61
+
62
+ // eslint-disable-next-line max-lines-per-function
32
63
  function parse(res) {
64
+ invariant(res && hasOwnProperty(res, 'valid'), "Vest parser: expected argument at position 0 to be Vest's result object.");
33
65
  var testedStorage = {};
34
66
  var selectors = {
35
- invalid: res.hasErrors,
36
- tested: function (fieldName) {
37
- if (!fieldName) {
38
- return greaterThan(res.testCount, 0);
39
- }
40
- if (hasOwnProperty(testedStorage, fieldName))
41
- return testedStorage[fieldName];
42
- testedStorage[fieldName] =
43
- hasOwnProperty(res.tests, fieldName) &&
44
- greaterThan(res.tests[fieldName].testCount, 0);
45
- return selectors.tested(fieldName);
46
- },
47
- untested: function (fieldName) {
48
- return res.testCount === 0 || !selectors.tested(fieldName);
49
- },
50
- valid: res.isValid,
51
- warning: res.hasWarnings
67
+ invalid: hasErrors,
68
+ tested: isTested,
69
+ untested: isUntested,
70
+ valid: isValid,
71
+ warning: hasWarnings
52
72
  };
53
73
  return selectors;
74
+ function isTested(fieldName) {
75
+ if (!fieldName) {
76
+ return isPositive(res.testCount);
77
+ }
78
+ if (hasOwnProperty(testedStorage, fieldName))
79
+ return testedStorage[fieldName];
80
+ testedStorage[fieldName] =
81
+ hasOwnProperty(res.tests, fieldName) &&
82
+ isPositive(res.tests[fieldName].testCount);
83
+ return selectors.tested(fieldName);
84
+ }
85
+ function isUntested(fieldName) {
86
+ return res.testCount === 0 || !selectors.tested(fieldName);
87
+ }
88
+ function isValid(fieldName) {
89
+ var _a, _b;
90
+ return Boolean(fieldName ? (_b = (_a = res.tests) === null || _a === void 0 ? void 0 : _a[fieldName]) === null || _b === void 0 ? void 0 : _b.valid : res.valid);
91
+ }
92
+ function hasWarnings(fieldName) {
93
+ return hasFailures(res, SeverityCount.WARN_COUNT, fieldName);
94
+ }
95
+ function hasErrors(fieldName) {
96
+ return hasFailures(res, SeverityCount.ERROR_COUNT, fieldName);
97
+ }
98
+ }
99
+ function hasFailures(res, countKey, fieldName) {
100
+ var _a, _b, _c;
101
+ var failureCount = fieldName
102
+ ? (_b = (_a = res.tests) === null || _a === void 0 ? void 0 : _a[fieldName]) === null || _b === void 0 ? void 0 : _b[countKey]
103
+ : (_c = res[countKey]) !== null && _c !== void 0 ? _c : 0;
104
+ return isPositive(failureCount);
54
105
  }
55
106
 
56
107
  /**
@@ -58,9 +109,6 @@ function parse(res) {
58
109
  */
59
110
  function classnames(res, classes) {
60
111
  if (classes === void 0) { classes = {}; }
61
- if (!res || !isFunction(res.hasErrors)) {
62
- throwError("classnames: Expected first argument to be Vest's result object.");
63
- }
64
112
  var selectors = parse(res);
65
113
  return function (key) {
66
114
  var classesArray = [];
@@ -1 +1 @@
1
- "use strict";function t(t){return"function"==typeof t}function r(r,n){var e;return null!==(e=function(r){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];return t(r)?r.apply(void 0,n):r}(r))&&void 0!==e?e:n}function n(t){var r=Number(t);return!(isNaN(parseFloat(String(t)))||isNaN(Number(t))||!isFinite(r))}function e(t,r){return n(t)&&n(r)&&Number(t)>Number(r)}function u(t,r){return Object.prototype.hasOwnProperty.call(t,r)}module.exports=function(n,o){void 0===o&&(o={}),n&&t(n.hasErrors)||function(t,n){throw Error(r(n,t))}("classnames: Expected first argument to be Vest's result object.");var s=function(t){var r={},n={invalid:t.hasErrors,tested:function(o){return o?u(r,o)?r[o]:(r[o]=u(t.tests,o)&&e(t.tests[o].testCount,0),n.tested(o)):e(t.testCount,0)},untested:function(r){return 0===t.testCount||!n.tested(r)},valid:t.isValid,warning:t.hasWarnings};return n}(n);return function(r){var n,e=[];for(n in o){var u=n;t(s[u])&&s[u](r)&&e.push(o[u])}return e.join(" ")}};
1
+ "use strict";function t(t){return"function"==typeof t}function n(t,n){return Object.prototype.hasOwnProperty.call(t,n)}function r(n,r){if(!n)throw r instanceof String?r.valueOf():Error(r?function(n){for(var r=[],e=1;e<arguments.length;e++)r[e-1]=arguments[e];return t(n)?n.apply(void 0,r):n}(r):r)}function e(t){var n=Number(t);return!(isNaN(parseFloat(String(t)))||isNaN(Number(t))||!isFinite(n))}function u(t){return function(t,n){return e(t)&&e(n)&&Number(t)>Number(n)}(t,0)}var o,i,s;function a(t,n,r){var e,o,i;return u(t=r?null===(o=null===(e=t.tests)||void 0===e?void 0:e[r])||void 0===o?void 0:o[n]:null!==(i=t[n])&&void 0!==i?i:0)}(i=o||(o={})).WARNINGS="warnings",i.ERRORS="errors",function(t){t.ERROR_COUNT="errorCount",t.WARN_COUNT="warnCount"}(s||(s={})),module.exports=function(e,o){void 0===o&&(o={});var i=function(t){r(t&&n(t,"valid"),"Vest parser: expected argument at position 0 to be Vest's result object.");var e={},o={invalid:function(n){return a(t,s.ERROR_COUNT,n)},tested:function(r){return r?n(e,r)?e[r]:(e[r]=n(t.tests,r)&&u(t.tests[r].testCount),o.tested(r)):u(t.testCount)},untested:function(n){return 0===t.testCount||!o.tested(n)},valid:function(n){var r,e;return!!(n?null!==(e=null===(r=t.tests)||void 0===r?void 0:r[n])&&void 0!==e&&e.valid:t.valid)},warning:function(n){return a(t,s.WARN_COUNT,n)}};return o}(e);return function(n){var r,e=[];for(r in o){var u=r;t(i[u])&&i[u](n)&&e.push(o[u])}return e.join(" ")}};
@@ -2,6 +2,32 @@
2
2
 
3
3
  var n4s = require('n4s');
4
4
 
5
+ function isFunction(value) {
6
+ return typeof value === 'function';
7
+ }
8
+
9
+ function optionalFunctionValue(value) {
10
+ var args = [];
11
+ for (var _i = 1; _i < arguments.length; _i++) {
12
+ args[_i - 1] = arguments[_i];
13
+ }
14
+ return isFunction(value) ? value.apply(void 0, args) : value;
15
+ }
16
+
17
+ function invariant(condition,
18
+ // eslint-disable-next-line @typescript-eslint/ban-types
19
+ message) {
20
+ if (condition) {
21
+ return;
22
+ }
23
+ // If message is a string object (rather than string literal)
24
+ // Throw the value directly as a string
25
+ // Alternatively, throw an error with the message
26
+ throw message instanceof String
27
+ ? message.valueOf()
28
+ : new Error(message ? optionalFunctionValue(message) : message);
29
+ }
30
+
5
31
  function mapFirst(array, callback) {
6
32
  var broke = false;
7
33
  var breakoutValue = null;
@@ -17,61 +43,11 @@ function mapFirst(array, callback) {
17
43
  }
18
44
  }
19
45
 
20
- function isFunction(value) {
21
- return typeof value === 'function';
22
- }
23
-
24
- function optionalFunctionValue(value) {
25
- var args = [];
26
- for (var _i = 1; _i < arguments.length; _i++) {
27
- args[_i - 1] = arguments[_i];
28
- }
29
- return isFunction(value) ? value.apply(void 0, args) : value;
30
- }
31
-
32
46
  function defaultTo(callback, defaultValue) {
33
47
  var _a;
34
48
  return (_a = optionalFunctionValue(callback)) !== null && _a !== void 0 ? _a : defaultValue;
35
49
  }
36
50
 
37
- /**
38
- * Throws a timed out error.
39
- */
40
- function throwError(devMessage, productionMessage) {
41
- throw new Error(devMessage );
42
- }
43
-
44
- /**
45
- * A safe hasOwnProperty access
46
- */
47
- function hasOwnProperty(obj, key) {
48
- return Object.prototype.hasOwnProperty.call(obj, key);
49
- }
50
-
51
- function isNumber(value) {
52
- return Boolean(typeof value === 'number');
53
- }
54
-
55
- function lengthEquals(value, arg1) {
56
- return value.length === Number(arg1);
57
- }
58
-
59
- function isEmpty(value) {
60
- if (!value) {
61
- return true;
62
- }
63
- else if (isNumber(value)) {
64
- return value === 0;
65
- }
66
- else if (hasOwnProperty(value, 'length')) {
67
- return lengthEquals(value, 0);
68
- }
69
- else if (typeof value === 'object') {
70
- return lengthEquals(Object.keys(value), 0);
71
- }
72
- return true;
73
- }
74
-
75
51
  function ruleReturn(pass, message) {
76
52
  var output = { pass: pass };
77
53
  if (message) {
@@ -106,15 +82,7 @@ function compose() {
106
82
  }
107
83
  return Object.assign(function (value) {
108
84
  var res = run(value);
109
- if (!res.pass) {
110
- if (isEmpty(res.message)) {
111
- throwError();
112
- }
113
- else {
114
- // Explicitly throw a string so that vest.test can pick it up as the validation error message
115
- throw res.message;
116
- }
117
- }
85
+ invariant(res.pass, new String(res.message));
118
86
  }, {
119
87
  run: run,
120
88
  test: function (value) { return run(value).pass; }
@@ -123,7 +91,7 @@ function compose() {
123
91
  return n4s.ctx.run({ value: value }, function () {
124
92
  return defaultToPassing(mapFirst(composites, function (composite, breakout) {
125
93
  /* HACK: Just a small white lie. ~~HELP WANTED~~.
126
- The ideal is that instead of `TLazyRuleRunners` We would simply use `TLazy` to begin with.
94
+ The ideal is that instead of `LazyRuleRunners` We would simply use `Lazy` to begin with.
127
95
  The problem is that lazy rules can't really be passed to this function due to some generic hell
128
96
  so we're limiting it to a small set of functions.
129
97
  */
@@ -1 +1 @@
1
- "use strict";var n=require("n4s");function r(n,r){function t(n){u=!0,e=n}for(var u=!1,e=null,o=0;o<n.length;o++)if(r(n[o],t,o),u)return e}function t(n){return"function"==typeof n}function u(n,r){var u;return null!==(u=function(n){for(var r=[],u=1;u<arguments.length;u++)r[u-1]=arguments[u];return t(n)?n.apply(void 0,r):n}(n))&&void 0!==u?u:r}function e(n,r){throw Error(u(r,n))}function o(n,r){return n.length===Number(r)}function f(n){if(n){if(function(n){return"number"==typeof n}(n))return 0===n;if(function(n,r){return Object.prototype.hasOwnProperty.call(n,r)}(n,"length"))return o(n,0);if("object"==typeof n)return o(Object.keys(n),0)}return!0}function i(n,r){return n={pass:n},r&&(n.message=r),n}function c(n){return u(n,i(!0))}function s(n,r){try{return n.run(r)}catch(n){return i(!1)}}module.exports=function(){function t(t){return n.ctx.run({value:t},(function(){return c(r(u,(function(n,r){(n=s(n,t)).pass||r(n)})))}))}for(var u=[],o=0;o<arguments.length;o++)u[o]=arguments[o];return Object.assign((function(n){if(!(n=t(n)).pass){if(!f(n.message))throw n.message;e()}}),{run:t,test:function(n){return t(n).pass}})};
1
+ "use strict";var n=require("n4s");function r(n){return"function"==typeof n}function t(n){for(var t=[],u=1;u<arguments.length;u++)t[u-1]=arguments[u];return r(n)?n.apply(void 0,t):n}function u(n,r){if(!n)throw r instanceof String?r.valueOf():Error(r?t(r):r)}function e(n,r){function t(n){u=!0,e=n}for(var u=!1,e=null,o=0;o<n.length;o++)if(r(n[o],t,o),u)return e}function o(n,r){return n={pass:n},r&&(n.message=r),n}function i(n){return function(n,r){var u;return null!==(u=t(n))&&void 0!==u?u:r}(n,o(!0))}function f(n,r){try{return n.run(r)}catch(n){return o(!1)}}module.exports=function(){function r(r){return n.ctx.run({value:r},(function(){return i(e(t,(function(n,t){(n=f(n,r)).pass||t(n)})))}))}for(var t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];return Object.assign((function(n){u((n=r(n)).pass,new String(n.message))}),{run:r,test:function(n){return r(n).pass}})};
@@ -102,12 +102,27 @@ function noneOf(value) {
102
102
  }));
103
103
  }
104
104
 
105
+ function isNumeric(value) {
106
+ var str = String(value);
107
+ var num = Number(value);
108
+ var result = !isNaN(parseFloat(str)) && !isNaN(Number(value)) && isFinite(num);
109
+ return Boolean(result);
110
+ }
111
+
112
+ function numberEquals(value, eq) {
113
+ return isNumeric(value) && isNumeric(eq) && Number(value) === Number(eq);
114
+ }
115
+
105
116
  function lengthEquals(value, arg1) {
106
- return value.length === Number(arg1);
117
+ return numberEquals(value.length, arg1);
118
+ }
119
+
120
+ function greaterThan(value, gt) {
121
+ return isNumeric(value) && isNumeric(gt) && Number(value) > Number(gt);
107
122
  }
108
123
 
109
124
  function longerThan(value, arg1) {
110
- return value.length > Number(arg1);
125
+ return greaterThan(value.length, arg1);
111
126
  }
112
127
 
113
128
  var REQUIRED_COUNT = 1;
@@ -1 +1 @@
1
- "use strict";var n=require("n4s");function r(n,r){function t(n){u=!0,e=n}for(var u=!1,e=null,f=0;f<n.length;f++)if(r(n[f],t,f),u)return e}function t(n){return"function"==typeof n}function u(n,r){var u;return null!==(u=function(n){for(var r=[],u=1;u<arguments.length;u++)r[u-1]=arguments[u];return t(n)?n.apply(void 0,r):n}(n))&&void 0!==u?u:r}function e(n,r){return n={pass:n},r&&(n.message=r),n}function f(){return e(!1)}function o(n){return u(n,f())}function i(n){return u(n,e(!0))}function c(n,r){try{return n.run(r)}catch(n){return f()}}function a(n,r){return n.length===Number(r)}function s(n,r){return n.length>Number(r)}n.enforce.extend({allOf:function(n){for(var t=[],u=1;u<arguments.length;u++)t[u-1]=arguments[u];return i(r(t,(function(r,t){(r=c(r,n)).pass||t(r)})))},anyOf:function(n){for(var t=[],u=1;u<arguments.length;u++)t[u-1]=arguments[u];return o(r(t,(function(r,t){(r=c(r,n)).pass&&t(r)})))},noneOf:function(n){for(var t=[],u=1;u<arguments.length;u++)t[u-1]=arguments[u];return i(r(t,(function(r,t){c(r,n).pass&&t(f())})))},oneOf:function(n){for(var r=[],t=1;t<arguments.length;t++)r[t-1]=arguments[t];var u=[];return r.some((function(r){if(s(u,1))return!1;(r=c(r,n)).pass&&u.push(r)})),e(a(u,1))}});
1
+ "use strict";var n=require("n4s");function r(n,r){function t(n){u=!0,e=n}for(var u=!1,e=null,f=0;f<n.length;f++)if(r(n[f],t,f),u)return e}function t(n){return"function"==typeof n}function u(n,r){var u;return null!==(u=function(n){for(var r=[],u=1;u<arguments.length;u++)r[u-1]=arguments[u];return t(n)?n.apply(void 0,r):n}(n))&&void 0!==u?u:r}function e(n,r){return n={pass:n},r&&(n.message=r),n}function f(){return e(!1)}function o(n){return u(n,f())}function i(n){return u(n,e(!0))}function c(n,r){try{return n.run(r)}catch(n){return f()}}function a(n){var r=Number(n);return!(isNaN(parseFloat(String(n)))||isNaN(Number(n))||!isFinite(r))}function s(n,r){return function(n,r){return a(n)&&a(r)&&Number(n)===Number(r)}(n.length,r)}function l(n,r){return function(n,r){return a(n)&&a(r)&&Number(n)>Number(r)}(n.length,r)}n.enforce.extend({allOf:function(n){for(var t=[],u=1;u<arguments.length;u++)t[u-1]=arguments[u];return i(r(t,(function(r,t){(r=c(r,n)).pass||t(r)})))},anyOf:function(n){for(var t=[],u=1;u<arguments.length;u++)t[u-1]=arguments[u];return o(r(t,(function(r,t){(r=c(r,n)).pass&&t(r)})))},noneOf:function(n){for(var t=[],u=1;u<arguments.length;u++)t[u-1]=arguments[u];return i(r(t,(function(r,t){c(r,n).pass&&t(f())})))},oneOf:function(n){for(var r=[],t=1;t<arguments.length;t++)r[t-1]=arguments[t];var u=[];return r.some((function(r){if(l(u,1))return!1;(r=c(r,n)).pass&&u.push(r)})),e(s(u,1))}});
@@ -130,7 +130,7 @@ function shape(inputObject, shapeObject) {
130
130
  }
131
131
 
132
132
  // Help needed improving the typings of this file.
133
- // Ideally, we'd be able to extend IShapeObject, but that's not possible.
133
+ // Ideally, we'd be able to extend ShapeObject, but that's not possible.
134
134
  function partial(shapeObject) {
135
135
  var output = {};
136
136
  for (var key in shapeObject) {
@@ -2,6 +2,39 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ /**
6
+ * A safe hasOwnProperty access
7
+ */
8
+ function hasOwnProperty(obj, key) {
9
+ return Object.prototype.hasOwnProperty.call(obj, key);
10
+ }
11
+
12
+ function isFunction(value) {
13
+ return typeof value === 'function';
14
+ }
15
+
16
+ function optionalFunctionValue(value) {
17
+ var args = [];
18
+ for (var _i = 1; _i < arguments.length; _i++) {
19
+ args[_i - 1] = arguments[_i];
20
+ }
21
+ return isFunction(value) ? value.apply(void 0, args) : value;
22
+ }
23
+
24
+ function invariant(condition,
25
+ // eslint-disable-next-line @typescript-eslint/ban-types
26
+ message) {
27
+ if (condition) {
28
+ return;
29
+ }
30
+ // If message is a string object (rather than string literal)
31
+ // Throw the value directly as a string
32
+ // Alternatively, throw an error with the message
33
+ throw message instanceof String
34
+ ? message.valueOf()
35
+ : new Error(message ? optionalFunctionValue(message) : message);
36
+ }
37
+
5
38
  function isNumeric(value) {
6
39
  var str = String(value);
7
40
  var num = Number(value);
@@ -13,35 +46,64 @@ function greaterThan(value, gt) {
13
46
  return isNumeric(value) && isNumeric(gt) && Number(value) > Number(gt);
14
47
  }
15
48
 
16
- /**
17
- * A safe hasOwnProperty access
18
- */
19
- function hasOwnProperty(obj, key) {
20
- return Object.prototype.hasOwnProperty.call(obj, key);
49
+ function isPositive(value) {
50
+ return greaterThan(value, 0);
21
51
  }
22
52
 
53
+ var Severity;
54
+ (function (Severity) {
55
+ Severity["WARNINGS"] = "warnings";
56
+ Severity["ERRORS"] = "errors";
57
+ })(Severity || (Severity = {}));
58
+ var SeverityCount;
59
+ (function (SeverityCount) {
60
+ SeverityCount["ERROR_COUNT"] = "errorCount";
61
+ SeverityCount["WARN_COUNT"] = "warnCount";
62
+ })(SeverityCount || (SeverityCount = {}));
63
+
64
+ // eslint-disable-next-line max-lines-per-function
23
65
  function parse(res) {
66
+ invariant(res && hasOwnProperty(res, 'valid'), "Vest parser: expected argument at position 0 to be Vest's result object.");
24
67
  var testedStorage = {};
25
68
  var selectors = {
26
- invalid: res.hasErrors,
27
- tested: function (fieldName) {
28
- if (!fieldName) {
29
- return greaterThan(res.testCount, 0);
30
- }
31
- if (hasOwnProperty(testedStorage, fieldName))
32
- return testedStorage[fieldName];
33
- testedStorage[fieldName] =
34
- hasOwnProperty(res.tests, fieldName) &&
35
- greaterThan(res.tests[fieldName].testCount, 0);
36
- return selectors.tested(fieldName);
37
- },
38
- untested: function (fieldName) {
39
- return res.testCount === 0 || !selectors.tested(fieldName);
40
- },
41
- valid: res.isValid,
42
- warning: res.hasWarnings
69
+ invalid: hasErrors,
70
+ tested: isTested,
71
+ untested: isUntested,
72
+ valid: isValid,
73
+ warning: hasWarnings
43
74
  };
44
75
  return selectors;
76
+ function isTested(fieldName) {
77
+ if (!fieldName) {
78
+ return isPositive(res.testCount);
79
+ }
80
+ if (hasOwnProperty(testedStorage, fieldName))
81
+ return testedStorage[fieldName];
82
+ testedStorage[fieldName] =
83
+ hasOwnProperty(res.tests, fieldName) &&
84
+ isPositive(res.tests[fieldName].testCount);
85
+ return selectors.tested(fieldName);
86
+ }
87
+ function isUntested(fieldName) {
88
+ return res.testCount === 0 || !selectors.tested(fieldName);
89
+ }
90
+ function isValid(fieldName) {
91
+ var _a, _b;
92
+ return Boolean(fieldName ? (_b = (_a = res.tests) === null || _a === void 0 ? void 0 : _a[fieldName]) === null || _b === void 0 ? void 0 : _b.valid : res.valid);
93
+ }
94
+ function hasWarnings(fieldName) {
95
+ return hasFailures(res, SeverityCount.WARN_COUNT, fieldName);
96
+ }
97
+ function hasErrors(fieldName) {
98
+ return hasFailures(res, SeverityCount.ERROR_COUNT, fieldName);
99
+ }
100
+ }
101
+ function hasFailures(res, countKey, fieldName) {
102
+ var _a, _b, _c;
103
+ var failureCount = fieldName
104
+ ? (_b = (_a = res.tests) === null || _a === void 0 ? void 0 : _a[fieldName]) === null || _b === void 0 ? void 0 : _b[countKey]
105
+ : (_c = res[countKey]) !== null && _c !== void 0 ? _c : 0;
106
+ return isPositive(failureCount);
45
107
  }
46
108
 
47
109
  exports.parse = parse;
@@ -1 +1 @@
1
- "use strict";function t(t){var e=Number(t);return!(isNaN(parseFloat(String(t)))||isNaN(Number(t))||!isFinite(e))}function e(e,r){return t(e)&&t(r)&&Number(e)>Number(r)}function r(t,e){return Object.prototype.hasOwnProperty.call(t,e)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.parse=function(t){var n={},s={invalid:t.hasErrors,tested:function(u){return u?r(n,u)?n[u]:(n[u]=r(t.tests,u)&&e(t.tests[u].testCount,0),s.tested(u)):e(t.testCount,0)},untested:function(e){return 0===t.testCount||!s.tested(e)},valid:t.isValid,warning:t.hasWarnings};return s};
1
+ "use strict";function t(t,n){return Object.prototype.hasOwnProperty.call(t,n)}function n(t){return"function"==typeof t}function r(t,r){if(!t)throw r instanceof String?r.valueOf():Error(r?function(t){for(var r=[],e=1;e<arguments.length;e++)r[e-1]=arguments[e];return n(t)?t.apply(void 0,r):t}(r):r)}function e(t){var n=Number(t);return!(isNaN(parseFloat(String(t)))||isNaN(Number(t))||!isFinite(n))}function u(t){return function(t,n){return e(t)&&e(n)&&Number(t)>Number(n)}(t,0)}var o,i,s;function a(t,n,r){var e,o,i;return u(t=r?null===(o=null===(e=t.tests)||void 0===e?void 0:e[r])||void 0===o?void 0:o[n]:null!==(i=t[n])&&void 0!==i?i:0)}Object.defineProperty(exports,"__esModule",{value:!0}),(i=o||(o={})).WARNINGS="warnings",i.ERRORS="errors",function(t){t.ERROR_COUNT="errorCount",t.WARN_COUNT="warnCount"}(s||(s={})),exports.parse=function(n){r(n&&t(n,"valid"),"Vest parser: expected argument at position 0 to be Vest's result object.");var e={},o={invalid:function(t){return a(n,s.ERROR_COUNT,t)},tested:function(r){return r?t(e,r)?e[r]:(e[r]=t(n.tests,r)&&u(n.tests[r].testCount),o.tested(r)):u(n.testCount)},untested:function(t){return 0===n.testCount||!o.tested(t)},valid:function(t){var r,e;return!!(t?null!==(e=null===(r=n.tests)||void 0===r?void 0:r[t])&&void 0!==e&&e.valid:n.valid)},warning:function(t){return a(n,s.WARN_COUNT,t)}};return o};
@@ -4,11 +4,26 @@ function isFunction(value) {
4
4
  return typeof value === 'function';
5
5
  }
6
6
 
7
- /**
8
- * Throws a timed out error.
9
- */
10
- function throwError(devMessage, productionMessage) {
11
- throw new Error(devMessage );
7
+ function optionalFunctionValue(value) {
8
+ var args = [];
9
+ for (var _i = 1; _i < arguments.length; _i++) {
10
+ args[_i - 1] = arguments[_i];
11
+ }
12
+ return isFunction(value) ? value.apply(void 0, args) : value;
13
+ }
14
+
15
+ function invariant(condition,
16
+ // eslint-disable-next-line @typescript-eslint/ban-types
17
+ message) {
18
+ if (condition) {
19
+ return;
20
+ }
21
+ // If message is a string object (rather than string literal)
22
+ // Throw the value directly as a string
23
+ // Alternatively, throw an error with the message
24
+ throw message instanceof String
25
+ ? message.valueOf()
26
+ : new Error(message ? optionalFunctionValue(message) : message);
12
27
  }
13
28
 
14
29
  var promisify = function (validatorFn) {
@@ -17,9 +32,7 @@ var promisify = function (validatorFn) {
17
32
  for (var _i = 0; _i < arguments.length; _i++) {
18
33
  args[_i] = arguments[_i];
19
34
  }
20
- if (!isFunction(validatorFn)) {
21
- throwError('promisify: Expected validatorFn to be a function.');
22
- }
35
+ invariant(isFunction(validatorFn), 'promisify: Expected validatorFn to be a function.');
23
36
  return new Promise(function (resolve) { return validatorFn.apply(void 0, args).done(resolve); });
24
37
  };
25
38
  };
@@ -1 +1 @@
1
- "use strict";function n(n){return"function"==typeof n}function r(r,t){var o;return null!==(o=function(r){for(var t=[],o=1;o<arguments.length;o++)t[o-1]=arguments[o];return n(r)?r.apply(void 0,t):r}(r))&&void 0!==o?o:t}function t(n,t){throw Error(r(t,n))}module.exports=function(r){return function(){for(var o=[],e=0;e<arguments.length;e++)o[e]=arguments[e];return n(r)||t("promisify: Expected validatorFn to be a function."),new Promise((function(n){return r.apply(void 0,o).done(n)}))}};
1
+ "use strict";function n(n){return"function"==typeof n}function t(t,r){if(!t)throw r instanceof String?r.valueOf():Error(r?function(t){for(var r=[],o=1;o<arguments.length;o++)r[o-1]=arguments[o];return n(t)?t.apply(void 0,r):t}(r):r)}module.exports=function(r){return function(){for(var o=[],e=0;e<arguments.length;e++)o[e]=arguments[e];return t(n(r),"promisify: Expected validatorFn to be a function."),new Promise((function(n){return r.apply(void 0,o).done(n)}))}};