vest 4.2.3-dev-87ebfa → 4.3.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 (33) hide show
  1. package/dist/cjs/classnames.development.js +58 -23
  2. package/dist/cjs/classnames.production.js +1 -1
  3. package/dist/cjs/parser.development.js +84 -22
  4. package/dist/cjs/parser.production.js +1 -1
  5. package/dist/cjs/vest.development.js +447 -440
  6. package/dist/cjs/vest.production.js +1 -1
  7. package/dist/es/classnames.development.js +58 -23
  8. package/dist/es/classnames.production.js +1 -1
  9. package/dist/es/parser.development.js +84 -22
  10. package/dist/es/parser.production.js +1 -1
  11. package/dist/es/vest.development.js +447 -440
  12. package/dist/es/vest.production.js +1 -1
  13. package/dist/umd/classnames.development.js +58 -23
  14. package/dist/umd/classnames.production.js +1 -1
  15. package/dist/umd/enforce/compose.development.js +16 -16
  16. package/dist/umd/enforce/compose.production.js +1 -1
  17. package/dist/umd/enforce/compounds.development.js +16 -16
  18. package/dist/umd/enforce/compounds.production.js +1 -1
  19. package/dist/umd/enforce/schema.development.js +16 -16
  20. package/dist/umd/enforce/schema.production.js +1 -1
  21. package/dist/umd/parser.development.js +84 -22
  22. package/dist/umd/parser.production.js +1 -1
  23. package/dist/umd/vest.development.js +320 -313
  24. package/dist/umd/vest.production.js +1 -1
  25. package/package.json +3 -3
  26. package/testUtils/suiteDummy.ts +5 -1
  27. package/types/classnames.d.ts +13 -55
  28. package/types/enforce/compose.d.ts +2 -1
  29. package/types/enforce/compounds.d.ts +2 -1
  30. package/types/enforce/schema.d.ts +2 -1
  31. package/types/parser.d.ts +12 -54
  32. package/types/promisify.d.ts +12 -10
  33. package/types/vest.d.ts +63 -61
@@ -4,6 +4,39 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.parser = {}));
5
5
  }(this, (function (exports) { 'use strict';
6
6
 
7
+ /**
8
+ * A safe hasOwnProperty access
9
+ */
10
+ function hasOwnProperty(obj, key) {
11
+ return Object.prototype.hasOwnProperty.call(obj, key);
12
+ }
13
+
14
+ function isFunction(value) {
15
+ return typeof value === 'function';
16
+ }
17
+
18
+ function optionalFunctionValue(value) {
19
+ var args = [];
20
+ for (var _i = 1; _i < arguments.length; _i++) {
21
+ args[_i - 1] = arguments[_i];
22
+ }
23
+ return isFunction(value) ? value.apply(void 0, args) : value;
24
+ }
25
+
26
+ function invariant(condition,
27
+ // eslint-disable-next-line @typescript-eslint/ban-types
28
+ message) {
29
+ if (condition) {
30
+ return;
31
+ }
32
+ // If message is a string object (rather than string literal)
33
+ // Throw the value directly as a string
34
+ // Alternatively, throw an error with the message
35
+ throw message instanceof String
36
+ ? message.valueOf()
37
+ : new Error(message ? optionalFunctionValue(message) : message);
38
+ }
39
+
7
40
  function isNumeric(value) {
8
41
  var str = String(value);
9
42
  var num = Number(value);
@@ -15,35 +48,64 @@
15
48
  return isNumeric(value) && isNumeric(gt) && Number(value) > Number(gt);
16
49
  }
17
50
 
18
- /**
19
- * A safe hasOwnProperty access
20
- */
21
- function hasOwnProperty(obj, key) {
22
- return Object.prototype.hasOwnProperty.call(obj, key);
51
+ function isPositive(value) {
52
+ return greaterThan(value, 0);
23
53
  }
24
54
 
55
+ var Severity;
56
+ (function (Severity) {
57
+ Severity["WARNINGS"] = "warnings";
58
+ Severity["ERRORS"] = "errors";
59
+ })(Severity || (Severity = {}));
60
+ var SeverityCount;
61
+ (function (SeverityCount) {
62
+ SeverityCount["ERROR_COUNT"] = "errorCount";
63
+ SeverityCount["WARN_COUNT"] = "warnCount";
64
+ })(SeverityCount || (SeverityCount = {}));
65
+
66
+ // eslint-disable-next-line max-lines-per-function
25
67
  function parse(res) {
68
+ invariant(res && hasOwnProperty(res, 'valid'), "Vest parser: expected argument at position 0 to be Vest's result object.");
26
69
  var testedStorage = {};
27
70
  var selectors = {
28
- invalid: res.hasErrors,
29
- tested: function (fieldName) {
30
- if (!fieldName) {
31
- return greaterThan(res.testCount, 0);
32
- }
33
- if (hasOwnProperty(testedStorage, fieldName))
34
- return testedStorage[fieldName];
35
- testedStorage[fieldName] =
36
- hasOwnProperty(res.tests, fieldName) &&
37
- greaterThan(res.tests[fieldName].testCount, 0);
38
- return selectors.tested(fieldName);
39
- },
40
- untested: function (fieldName) {
41
- return res.testCount === 0 || !selectors.tested(fieldName);
42
- },
43
- valid: res.isValid,
44
- warning: res.hasWarnings
71
+ invalid: hasErrors,
72
+ tested: isTested,
73
+ untested: isUntested,
74
+ valid: isValid,
75
+ warning: hasWarnings
45
76
  };
46
77
  return selectors;
78
+ function isTested(fieldName) {
79
+ if (!fieldName) {
80
+ return isPositive(res.testCount);
81
+ }
82
+ if (hasOwnProperty(testedStorage, fieldName))
83
+ return testedStorage[fieldName];
84
+ testedStorage[fieldName] =
85
+ hasOwnProperty(res.tests, fieldName) &&
86
+ isPositive(res.tests[fieldName].testCount);
87
+ return selectors.tested(fieldName);
88
+ }
89
+ function isUntested(fieldName) {
90
+ return res.testCount === 0 || !selectors.tested(fieldName);
91
+ }
92
+ function isValid(fieldName) {
93
+ var _a, _b;
94
+ 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);
95
+ }
96
+ function hasWarnings(fieldName) {
97
+ return hasFailures(res, SeverityCount.WARN_COUNT, fieldName);
98
+ }
99
+ function hasErrors(fieldName) {
100
+ return hasFailures(res, SeverityCount.ERROR_COUNT, fieldName);
101
+ }
102
+ }
103
+ function hasFailures(res, countKey, fieldName) {
104
+ var _a, _b, _c;
105
+ var failureCount = fieldName
106
+ ? (_b = (_a = res.tests) === null || _a === void 0 ? void 0 : _a[fieldName]) === null || _b === void 0 ? void 0 : _b[countKey]
107
+ : (_c = res[countKey]) !== null && _c !== void 0 ? _c : 0;
108
+ return isPositive(failureCount);
47
109
  }
48
110
 
49
111
  exports.parse = parse;
@@ -1 +1 @@
1
- "use strict";!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).parser={})}(this,(function(e){function t(e){var t=Number(e);return!(isNaN(parseFloat(String(e)))||isNaN(Number(e))||!isFinite(t))}function n(e,n){return t(e)&&t(n)&&Number(e)>Number(n)}e.parse=function(e){var t={},r={invalid:e.hasErrors,tested:function(s){return s?Object.prototype.hasOwnProperty.call(t,s)?t[s]:(t[s]=Object.prototype.hasOwnProperty.call(e.tests,s)&&n(e.tests[s].testCount,0),r.tested(s)):n(e.testCount,0)},untested:function(t){return 0===e.testCount||!r.tested(t)},valid:e.isValid,warning:e.hasWarnings};return r},Object.defineProperty(e,"__esModule",{value:!0})}));
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){var e=Number(t);return!(isNaN(parseFloat(String(t)))||isNaN(Number(t))||!isFinite(e))}function n(t,n){return e(t)&&e(n)&&Number(t)>Number(n)}function r(t,e,r){var o,i,u;return n(t=r?null===(i=null===(o=t.tests)||void 0===o?void 0:o[r])||void 0===i?void 0:i[e]:null!==(u=t[e])&&void 0!==u?u:0,0)}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(t,e){if(!t)throw e instanceof String?e.valueOf():Error(e?function(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}(e):e)}(t&&Object.prototype.hasOwnProperty.call(t,"valid"),"Vest parser: expected argument at position 0 to be Vest's result object.");var e={},o={invalid:function(e){return r(t,u.ERROR_COUNT,e)},tested:function(r){return r?Object.prototype.hasOwnProperty.call(e,r)?e[r]:(e[r]=Object.prototype.hasOwnProperty.call(t.tests,r)&&n(t.tests[r].testCount,0),o.tested(r)):n(t.testCount,0)},untested:function(e){return 0===t.testCount||!o.tested(e)},valid:function(e){var n,r;return!!(e?null!==(r=null===(n=t.tests)||void 0===n?void 0:n[e])&&void 0!==r&&r.valid:t.valid)},warning:function(e){return r(t,u.WARN_COUNT,e)}};return o},Object.defineProperty(t,"__esModule",{value:!0})}));