vest 4.2.3-dev-87ebfa → 4.3.2-dev-2805e3

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 (41) hide show
  1. package/dist/cjs/classnames.development.js +61 -23
  2. package/dist/cjs/classnames.production.js +1 -1
  3. package/dist/cjs/enforce/compose.development.js +1 -1
  4. package/dist/cjs/enforce/compounds.development.js +20 -5
  5. package/dist/cjs/enforce/compounds.production.js +1 -1
  6. package/dist/cjs/enforce/schema.development.js +1 -1
  7. package/dist/cjs/parser.development.js +87 -22
  8. package/dist/cjs/parser.production.js +1 -1
  9. package/dist/cjs/vest.development.js +548 -566
  10. package/dist/cjs/vest.production.js +1 -1
  11. package/dist/es/classnames.development.js +61 -23
  12. package/dist/es/classnames.production.js +1 -1
  13. package/dist/es/enforce/compose.development.js +1 -1
  14. package/dist/es/enforce/compounds.development.js +20 -5
  15. package/dist/es/enforce/compounds.production.js +1 -1
  16. package/dist/es/enforce/schema.development.js +1 -1
  17. package/dist/es/parser.development.js +87 -22
  18. package/dist/es/parser.production.js +1 -1
  19. package/dist/es/vest.development.js +548 -566
  20. package/dist/es/vest.production.js +1 -1
  21. package/dist/umd/classnames.development.js +61 -23
  22. package/dist/umd/classnames.production.js +1 -1
  23. package/dist/umd/enforce/compose.development.js +34 -30
  24. package/dist/umd/enforce/compose.production.js +1 -1
  25. package/dist/umd/enforce/compounds.development.js +36 -32
  26. package/dist/umd/enforce/compounds.production.js +1 -1
  27. package/dist/umd/enforce/schema.development.js +34 -30
  28. package/dist/umd/enforce/schema.production.js +1 -1
  29. package/dist/umd/parser.development.js +87 -22
  30. package/dist/umd/parser.production.js +1 -1
  31. package/dist/umd/vest.development.js +482 -515
  32. package/dist/umd/vest.production.js +1 -1
  33. package/package.json +1 -1
  34. package/testUtils/suiteDummy.ts +5 -1
  35. package/types/classnames.d.ts +17 -55
  36. package/types/enforce/compose.d.ts +22 -21
  37. package/types/enforce/compounds.d.ts +24 -23
  38. package/types/enforce/schema.d.ts +26 -25
  39. package/types/parser.d.ts +16 -54
  40. package/types/promisify.d.ts +23 -16
  41. package/types/vest.d.ts +109 -101
@@ -12,6 +12,18 @@ function optionalFunctionValue(value) {
12
12
  return isFunction(value) ? value.apply(void 0, args) : value;
13
13
  }
14
14
 
15
+ function defaultTo(callback, defaultValue) {
16
+ var _a;
17
+ return (_a = optionalFunctionValue(callback)) !== null && _a !== void 0 ? _a : defaultValue;
18
+ }
19
+
20
+ /**
21
+ * A safe hasOwnProperty access
22
+ */
23
+ function hasOwnProperty(obj, key) {
24
+ return Object.prototype.hasOwnProperty.call(obj, key);
25
+ }
26
+
15
27
  function invariant(condition,
16
28
  // eslint-disable-next-line @typescript-eslint/ban-types
17
29
  message) {
@@ -37,35 +49,62 @@ function greaterThan(value, gt) {
37
49
  return isNumeric(value) && isNumeric(gt) && Number(value) > Number(gt);
38
50
  }
39
51
 
40
- /**
41
- * A safe hasOwnProperty access
42
- */
43
- function hasOwnProperty(obj, key) {
44
- return Object.prototype.hasOwnProperty.call(obj, key);
52
+ function isPositive(value) {
53
+ return greaterThan(value, 0);
45
54
  }
46
55
 
56
+ var Severity;
57
+ (function (Severity) {
58
+ Severity["WARNINGS"] = "warnings";
59
+ Severity["ERRORS"] = "errors";
60
+ })(Severity || (Severity = {}));
61
+ var SeverityCount;
62
+ (function (SeverityCount) {
63
+ SeverityCount["ERROR_COUNT"] = "errorCount";
64
+ SeverityCount["WARN_COUNT"] = "warnCount";
65
+ })(SeverityCount || (SeverityCount = {}));
66
+
67
+ // eslint-disable-next-line max-lines-per-function
47
68
  function parse(res) {
69
+ invariant(res && hasOwnProperty(res, 'valid'), "Vest parser: expected argument at position 0 to be Vest's result object.");
48
70
  var testedStorage = {};
49
71
  var selectors = {
50
- invalid: res.hasErrors,
51
- tested: function (fieldName) {
52
- if (!fieldName) {
53
- return greaterThan(res.testCount, 0);
54
- }
55
- if (hasOwnProperty(testedStorage, fieldName))
56
- return testedStorage[fieldName];
57
- testedStorage[fieldName] =
58
- hasOwnProperty(res.tests, fieldName) &&
59
- greaterThan(res.tests[fieldName].testCount, 0);
60
- return selectors.tested(fieldName);
61
- },
62
- untested: function (fieldName) {
63
- return res.testCount === 0 || !selectors.tested(fieldName);
64
- },
65
- valid: res.isValid,
66
- warning: res.hasWarnings
72
+ invalid: hasErrors,
73
+ tested: isTested,
74
+ untested: isUntested,
75
+ valid: isValid,
76
+ warning: hasWarnings
67
77
  };
68
78
  return selectors;
79
+ function isTested(fieldName) {
80
+ if (!fieldName) {
81
+ return isPositive(res.testCount);
82
+ }
83
+ if (hasOwnProperty(testedStorage, fieldName))
84
+ return testedStorage[fieldName];
85
+ testedStorage[fieldName] =
86
+ hasOwnProperty(res.tests, fieldName) &&
87
+ isPositive(res.tests[fieldName].testCount);
88
+ return selectors.tested(fieldName);
89
+ }
90
+ function isUntested(fieldName) {
91
+ return res.testCount === 0 || !selectors.tested(fieldName);
92
+ }
93
+ function isValid(fieldName) {
94
+ var _a;
95
+ return fieldName ? Boolean((_a = res.tests[fieldName]) === null || _a === void 0 ? void 0 : _a.valid) : res.valid;
96
+ }
97
+ function hasWarnings(fieldName) {
98
+ return hasFailures(SeverityCount.WARN_COUNT, fieldName);
99
+ }
100
+ function hasErrors(fieldName) {
101
+ return hasFailures(SeverityCount.ERROR_COUNT, fieldName);
102
+ }
103
+ function hasFailures(countKey, fieldName) {
104
+ var _a;
105
+ var failureCount = defaultTo(fieldName ? (_a = res.tests[fieldName]) === null || _a === void 0 ? void 0 : _a[countKey] : res[countKey], 0);
106
+ return isPositive(failureCount);
107
+ }
69
108
  }
70
109
 
71
110
  /**
@@ -73,7 +112,6 @@ function parse(res) {
73
112
  */
74
113
  function classnames(res, classes) {
75
114
  if (classes === void 0) { classes = {}; }
76
- invariant(res && isFunction(res.hasErrors), "classnames: Expected first argument to be Vest's result object.");
77
115
  var selectors = parse(res);
78
116
  return function (key) {
79
117
  var classesArray = [];
@@ -1 +1 @@
1
- "use strict";function t(t){return"function"==typeof t}function r(r,n){if(!r)throw n instanceof String?n.valueOf():Error(n?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}(n):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,s){void 0===s&&(s={}),r(n&&t(n.hasErrors),"classnames: Expected first argument to be Vest's result object.");var i=function(t){var r={},n={invalid:t.hasErrors,tested:function(s){return s?u(r,s)?r[s]:(r[s]=u(t.tests,s)&&e(t.tests[s].testCount,0),n.tested(s)):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 s){var u=n;t(i[u])&&i[u](r)&&e.push(s[u])}return e.join(" ")}};
1
+ "use strict";function t(t){return"function"==typeof t}function n(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 r(t,n){return Object.prototype.hasOwnProperty.call(t,n)}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){function e(r,e){var o;return u(r=function(t,r){var e;return null!==(e=n(t))&&void 0!==e?e:r}(e?null===(o=t.tests[e])||void 0===o?void 0:o[r]:t[r],0))}!function(t,r){if(!t)throw r instanceof String?r.valueOf():Error(r?n(r):r)}(t&&r(t,"valid"),"Vest parser: expected argument at position 0 to be Vest's result object.");var o={},i={invalid:function(t){return e(s.ERROR_COUNT,t)},tested:function(n){return n?r(o,n)?o[n]:(o[n]=r(t.tests,n)&&u(t.tests[n].testCount),i.tested(n)):u(t.testCount)},untested:function(n){return 0===t.testCount||!i.tested(n)},valid:function(n){var r;return n?!(null===(r=t.tests[n])||void 0===r||!r.valid):t.valid},warning:function(t){return e(s.WARN_COUNT,t)}};return i}(i=o||(o={})).WARNINGS="warnings",i.ERRORS="errors",function(t){t.ERROR_COUNT="errorCount",t.WARN_COUNT="warnCount"}(s||(s={})),module.exports=function(n,r){void 0===r&&(r={});var e=a(n);return function(n){var u,o=[];for(u in r){var i=u;t(e[i])&&e[i](n)&&o.push(r[i])}return o.join(" ")}};
@@ -91,7 +91,7 @@ function compose() {
91
91
  return n4s.ctx.run({ value: value }, function () {
92
92
  return defaultToPassing(mapFirst(composites, function (composite, breakout) {
93
93
  /* HACK: Just a small white lie. ~~HELP WANTED~~.
94
- 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.
95
95
  The problem is that lazy rules can't really be passed to this function due to some generic hell
96
96
  so we're limiting it to a small set of functions.
97
97
  */
@@ -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;
@@ -118,13 +133,13 @@ function oneOf(value) {
118
133
  }
119
134
  var passing = [];
120
135
  rules.some(function (rule) {
121
- if (longerThan(passing, REQUIRED_COUNT)) {
122
- return false;
123
- }
124
136
  var res = runLazyRule(rule, value);
125
137
  if (res.pass) {
126
138
  passing.push(res);
127
139
  }
140
+ if (longerThan(passing, REQUIRED_COUNT)) {
141
+ return false;
142
+ }
128
143
  });
129
144
  return ruleReturn(lengthEquals(passing, REQUIRED_COUNT));
130
145
  }
@@ -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((r=c(r,n)).pass&&u.push(r),l(u,1))return!1})),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,44 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
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 defaultTo(callback, defaultValue) {
18
+ var _a;
19
+ return (_a = optionalFunctionValue(callback)) !== null && _a !== void 0 ? _a : defaultValue;
20
+ }
21
+
22
+ /**
23
+ * A safe hasOwnProperty access
24
+ */
25
+ function hasOwnProperty(obj, key) {
26
+ return Object.prototype.hasOwnProperty.call(obj, key);
27
+ }
28
+
29
+ function invariant(condition,
30
+ // eslint-disable-next-line @typescript-eslint/ban-types
31
+ message) {
32
+ if (condition) {
33
+ return;
34
+ }
35
+ // If message is a string object (rather than string literal)
36
+ // Throw the value directly as a string
37
+ // Alternatively, throw an error with the message
38
+ throw message instanceof String
39
+ ? message.valueOf()
40
+ : new Error(message ? optionalFunctionValue(message) : message);
41
+ }
42
+
5
43
  function isNumeric(value) {
6
44
  var str = String(value);
7
45
  var num = Number(value);
@@ -13,35 +51,62 @@ function greaterThan(value, gt) {
13
51
  return isNumeric(value) && isNumeric(gt) && Number(value) > Number(gt);
14
52
  }
15
53
 
16
- /**
17
- * A safe hasOwnProperty access
18
- */
19
- function hasOwnProperty(obj, key) {
20
- return Object.prototype.hasOwnProperty.call(obj, key);
54
+ function isPositive(value) {
55
+ return greaterThan(value, 0);
21
56
  }
22
57
 
58
+ var Severity;
59
+ (function (Severity) {
60
+ Severity["WARNINGS"] = "warnings";
61
+ Severity["ERRORS"] = "errors";
62
+ })(Severity || (Severity = {}));
63
+ var SeverityCount;
64
+ (function (SeverityCount) {
65
+ SeverityCount["ERROR_COUNT"] = "errorCount";
66
+ SeverityCount["WARN_COUNT"] = "warnCount";
67
+ })(SeverityCount || (SeverityCount = {}));
68
+
69
+ // eslint-disable-next-line max-lines-per-function
23
70
  function parse(res) {
71
+ invariant(res && hasOwnProperty(res, 'valid'), "Vest parser: expected argument at position 0 to be Vest's result object.");
24
72
  var testedStorage = {};
25
73
  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
74
+ invalid: hasErrors,
75
+ tested: isTested,
76
+ untested: isUntested,
77
+ valid: isValid,
78
+ warning: hasWarnings
43
79
  };
44
80
  return selectors;
81
+ function isTested(fieldName) {
82
+ if (!fieldName) {
83
+ return isPositive(res.testCount);
84
+ }
85
+ if (hasOwnProperty(testedStorage, fieldName))
86
+ return testedStorage[fieldName];
87
+ testedStorage[fieldName] =
88
+ hasOwnProperty(res.tests, fieldName) &&
89
+ isPositive(res.tests[fieldName].testCount);
90
+ return selectors.tested(fieldName);
91
+ }
92
+ function isUntested(fieldName) {
93
+ return res.testCount === 0 || !selectors.tested(fieldName);
94
+ }
95
+ function isValid(fieldName) {
96
+ var _a;
97
+ return fieldName ? Boolean((_a = res.tests[fieldName]) === null || _a === void 0 ? void 0 : _a.valid) : res.valid;
98
+ }
99
+ function hasWarnings(fieldName) {
100
+ return hasFailures(SeverityCount.WARN_COUNT, fieldName);
101
+ }
102
+ function hasErrors(fieldName) {
103
+ return hasFailures(SeverityCount.ERROR_COUNT, fieldName);
104
+ }
105
+ function hasFailures(countKey, fieldName) {
106
+ var _a;
107
+ var failureCount = defaultTo(fieldName ? (_a = res.tests[fieldName]) === null || _a === void 0 ? void 0 : _a[countKey] : res[countKey], 0);
108
+ return isPositive(failureCount);
109
+ }
45
110
  }
46
111
 
47
112
  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){return"function"==typeof t}function n(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 r(t,n){return Object.prototype.hasOwnProperty.call(t,n)}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;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(t){function e(r,e){var o;return u(r=function(t,r){var e;return null!==(e=n(t))&&void 0!==e?e:r}(e?null===(o=t.tests[e])||void 0===o?void 0:o[r]:t[r],0))}!function(t,r){if(!t)throw r instanceof String?r.valueOf():Error(r?n(r):r)}(t&&r(t,"valid"),"Vest parser: expected argument at position 0 to be Vest's result object.");var o={},i={invalid:function(t){return e(s.ERROR_COUNT,t)},tested:function(n){return n?r(o,n)?o[n]:(o[n]=r(t.tests,n)&&u(t.tests[n].testCount),i.tested(n)):u(t.testCount)},untested:function(n){return 0===t.testCount||!i.tested(n)},valid:function(n){var r;return n?!(null===(r=t.tests[n])||void 0===r||!r.valid):t.valid},warning:function(t){return e(s.WARN_COUNT,t)}};return i};