vest 4.4.2-dev-ae93bf → 4.5.0-dev-9b46fb
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.
- package/dist/cjs/classnames.development.js +13 -36
- package/dist/cjs/classnames.production.js +1 -1
- package/dist/cjs/enforce/compose.development.js +1 -1
- package/dist/cjs/enforce/compose.production.js +1 -1
- package/dist/cjs/enforce/compounds.development.js +1 -1
- package/dist/cjs/enforce/compounds.production.js +1 -1
- package/dist/cjs/enforce/schema.development.js +1 -1
- package/dist/cjs/enforce/schema.production.js +1 -1
- package/dist/cjs/parser.development.js +13 -36
- package/dist/cjs/parser.production.js +1 -1
- package/dist/cjs/vest.development.js +113 -118
- package/dist/cjs/vest.production.js +1 -1
- package/dist/es/classnames.development.js +14 -37
- package/dist/es/classnames.production.js +1 -1
- package/dist/es/enforce/compose.development.js +1 -1
- package/dist/es/enforce/compose.production.js +1 -1
- package/dist/es/enforce/compounds.development.js +1 -1
- package/dist/es/enforce/compounds.production.js +1 -1
- package/dist/es/enforce/schema.development.js +1 -1
- package/dist/es/enforce/schema.production.js +1 -1
- package/dist/es/parser.development.js +14 -37
- package/dist/es/parser.production.js +1 -1
- package/dist/es/vest.development.js +114 -120
- package/dist/es/vest.production.js +1 -1
- package/dist/umd/classnames.development.js +16 -45
- package/dist/umd/classnames.production.js +1 -1
- package/dist/umd/enforce/compose.development.js +17 -0
- package/dist/umd/enforce/compounds.development.js +68 -51
- package/dist/umd/enforce/compounds.production.js +1 -1
- package/dist/umd/enforce/schema.development.js +17 -0
- package/dist/umd/parser.development.js +16 -45
- package/dist/umd/parser.production.js +1 -1
- package/dist/umd/vest.development.js +131 -119
- package/dist/umd/vest.production.js +1 -1
- package/package.json +4 -4
- package/testUtils/__tests__/partition.test.ts +21 -0
- package/testUtils/partition.ts +13 -0
- package/types/enforce/compose.d.ts +3 -2
- package/types/enforce/compounds.d.ts +3 -2
- package/types/enforce/schema.d.ts +3 -2
- package/types/parser.d.ts +8 -7
- package/types/promisify.d.ts +20 -35
- package/types/vest.d.ts +45 -60
|
@@ -149,6 +149,57 @@
|
|
|
149
149
|
return greaterThan(value, 0);
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
+
function ruleReturn(pass, message) {
|
|
153
|
+
var output = { pass: pass };
|
|
154
|
+
if (message) {
|
|
155
|
+
output.message = message;
|
|
156
|
+
}
|
|
157
|
+
return output;
|
|
158
|
+
}
|
|
159
|
+
function failing() {
|
|
160
|
+
return ruleReturn(false);
|
|
161
|
+
}
|
|
162
|
+
function passing() {
|
|
163
|
+
return ruleReturn(true);
|
|
164
|
+
}
|
|
165
|
+
function defaultToFailing(callback) {
|
|
166
|
+
return defaultTo(callback, failing());
|
|
167
|
+
}
|
|
168
|
+
function defaultToPassing(callback) {
|
|
169
|
+
return defaultTo(callback, passing());
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function runLazyRule(lazyRule, currentValue) {
|
|
173
|
+
try {
|
|
174
|
+
return lazyRule.run(currentValue);
|
|
175
|
+
}
|
|
176
|
+
catch (_a) {
|
|
177
|
+
return failing();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function allOf(value) {
|
|
182
|
+
var rules = [];
|
|
183
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
184
|
+
rules[_i - 1] = arguments[_i];
|
|
185
|
+
}
|
|
186
|
+
return defaultToPassing(mapFirst(rules, function (rule, breakout) {
|
|
187
|
+
var res = runLazyRule(rule, value);
|
|
188
|
+
breakout(!res.pass, res);
|
|
189
|
+
}));
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function anyOf(value) {
|
|
193
|
+
var rules = [];
|
|
194
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
195
|
+
rules[_i - 1] = arguments[_i];
|
|
196
|
+
}
|
|
197
|
+
return defaultToFailing(mapFirst(rules, function (rule, breakout) {
|
|
198
|
+
var res = runLazyRule(rule, value);
|
|
199
|
+
breakout(res.pass, res);
|
|
200
|
+
}));
|
|
201
|
+
}
|
|
202
|
+
|
|
152
203
|
function endsWith(value, arg1) {
|
|
153
204
|
return isStringValue(value) && isStringValue(arg1) && value.endsWith(arg1);
|
|
154
205
|
}
|
|
@@ -490,26 +541,6 @@
|
|
|
490
541
|
}
|
|
491
542
|
}
|
|
492
543
|
|
|
493
|
-
function ruleReturn(pass, message) {
|
|
494
|
-
var output = { pass: pass };
|
|
495
|
-
if (message) {
|
|
496
|
-
output.message = message;
|
|
497
|
-
}
|
|
498
|
-
return output;
|
|
499
|
-
}
|
|
500
|
-
function failing() {
|
|
501
|
-
return ruleReturn(false);
|
|
502
|
-
}
|
|
503
|
-
function passing() {
|
|
504
|
-
return ruleReturn(true);
|
|
505
|
-
}
|
|
506
|
-
function defaultToFailing(callback) {
|
|
507
|
-
return defaultTo(callback, failing());
|
|
508
|
-
}
|
|
509
|
-
function defaultToPassing(callback) {
|
|
510
|
-
return defaultTo(callback, passing());
|
|
511
|
-
}
|
|
512
|
-
|
|
513
544
|
/**
|
|
514
545
|
* Transform the result of a rule into a standard format
|
|
515
546
|
*/
|
|
@@ -534,30 +565,47 @@
|
|
|
534
565
|
|
|
535
566
|
function enforceEager(value) {
|
|
536
567
|
var target = {};
|
|
568
|
+
// This condition is for when we don't have proxy support (ES5).
|
|
569
|
+
// In this case, we need to manually assign the rules to the target object on runtime.
|
|
570
|
+
// The follow up proxy block is used in case we do have proxy support, and we can assign each rule upon invocation.
|
|
537
571
|
if (!isProxySupported()) {
|
|
572
|
+
// We iterate over each of the rules, and add them to the target object being return by enforce
|
|
538
573
|
eachEnforceRule(function (ruleName, ruleFn) {
|
|
574
|
+
// We then wrap the rule with `genRuleCall` that adds the base enforce behavior
|
|
539
575
|
target[ruleName] = genRuleCall(target, ruleFn, ruleName);
|
|
540
576
|
});
|
|
541
577
|
return target;
|
|
542
578
|
}
|
|
579
|
+
// We create a proxy intercepting access to the target object (which is empty).
|
|
543
580
|
var proxy = new Proxy(target, {
|
|
544
581
|
get: function (_, ruleName) {
|
|
582
|
+
// On property access, we identify if it is a rule or not.
|
|
545
583
|
var rule = getRule(ruleName);
|
|
584
|
+
// If it is a rule, we wrap it with `genRuleCall` that adds the base enforce behavior
|
|
546
585
|
if (rule) {
|
|
547
586
|
return genRuleCall(proxy, rule, ruleName);
|
|
548
587
|
}
|
|
549
588
|
}
|
|
550
589
|
});
|
|
551
590
|
return proxy;
|
|
591
|
+
// This function is used to wrap a rule with the base enforce behavior
|
|
592
|
+
// It takes the target object, the rule function, and the rule name
|
|
593
|
+
// It then returns the rule, in a manner that can be used by enforce
|
|
552
594
|
function genRuleCall(target, rule, ruleName) {
|
|
553
595
|
return function ruleCall() {
|
|
554
596
|
var args = [];
|
|
555
597
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
556
598
|
args[_i] = arguments[_i];
|
|
557
599
|
}
|
|
600
|
+
// Order of operation:
|
|
601
|
+
// 1. Create a context with the value being enforced
|
|
602
|
+
// 2. Call the rule within the context, and pass over the arguments passed to it
|
|
603
|
+
// 3. Transform the result to the correct output format
|
|
558
604
|
var transformedResult = ctx.run({ value: value }, function () {
|
|
559
605
|
return transformResult.apply(void 0, __spreadArray([rule.apply(void 0, __spreadArray([value], args, false)), ruleName, value], args, false));
|
|
560
606
|
});
|
|
607
|
+
// On rule failure (the result is false), we either throw an error
|
|
608
|
+
// or throw a string value if the rule has a message defined in it.
|
|
561
609
|
invariant(transformedResult.pass, isNullish(transformedResult.message)
|
|
562
610
|
? "enforce/".concat(ruleName, " failed with ").concat(JSON.stringify(value))
|
|
563
611
|
: StringObject(transformedResult.message));
|
|
@@ -679,37 +727,6 @@
|
|
|
679
727
|
}
|
|
680
728
|
var enforce = genEnforce();
|
|
681
729
|
|
|
682
|
-
function runLazyRule(lazyRule, currentValue) {
|
|
683
|
-
try {
|
|
684
|
-
return lazyRule.run(currentValue);
|
|
685
|
-
}
|
|
686
|
-
catch (_a) {
|
|
687
|
-
return failing();
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
function allOf(value) {
|
|
692
|
-
var rules = [];
|
|
693
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
694
|
-
rules[_i - 1] = arguments[_i];
|
|
695
|
-
}
|
|
696
|
-
return defaultToPassing(mapFirst(rules, function (rule, breakout) {
|
|
697
|
-
var res = runLazyRule(rule, value);
|
|
698
|
-
breakout(!res.pass, res);
|
|
699
|
-
}));
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
function anyOf(value) {
|
|
703
|
-
var rules = [];
|
|
704
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
705
|
-
rules[_i - 1] = arguments[_i];
|
|
706
|
-
}
|
|
707
|
-
return defaultToFailing(mapFirst(rules, function (rule, breakout) {
|
|
708
|
-
var res = runLazyRule(rule, value);
|
|
709
|
-
breakout(res.pass, res);
|
|
710
|
-
}));
|
|
711
|
-
}
|
|
712
|
-
|
|
713
730
|
function noneOf(value) {
|
|
714
731
|
var rules = [];
|
|
715
732
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";!function(n){"function"==typeof define&&define.amd?define(n):n()}((function(){function n(n){return function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return!n.apply(void 0,t)}}function t(n){var t=Number(n);return!(isNaN(parseFloat(String(n)))||isNaN(Number(n))||!isFinite(t))}function r(n,r){return t(n)&&t(r)&&Number(n)===Number(r)}function e(n,t){return r(n.length,t)}function u(n,r){return t(n)&&t(r)&&Number(n)>Number(r)}function i(n){return null===n}function o(n){return void 0===n}function f(n){return null===n||o(n)}function a(n){return"function"==typeof n}function s(n){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];return a(n)?n.apply(void 0,t):n}function c(n,t){var r;return null!==(r=s(n))&&void 0!==r?r:s(t)}function l(n){return!!Array.isArray(n)}function v(n,t){if(!n)throw t instanceof String?t.valueOf():Error(t?s(t):t)}function h(n){return String(n)===n}function g(n){return!!n===n}function p(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 N(n){return!n||(Object.prototype.hasOwnProperty.call(n,"length")?e(n,0):"object"==typeof n&&e(Object.keys(n),0))}function y(n,t){return h(n)&&h(t)&&n.endsWith(t)}function
|
|
1
|
+
"use strict";!function(n){"function"==typeof define&&define.amd?define(n):n()}((function(){function n(n){return function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return!n.apply(void 0,t)}}function t(n){var t=Number(n);return!(isNaN(parseFloat(String(n)))||isNaN(Number(n))||!isFinite(t))}function r(n,r){return t(n)&&t(r)&&Number(n)===Number(r)}function e(n,t){return r(n.length,t)}function u(n,r){return t(n)&&t(r)&&Number(n)>Number(r)}function i(n){return null===n}function o(n){return void 0===n}function f(n){return null===n||o(n)}function a(n){return"function"==typeof n}function s(n){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];return a(n)?n.apply(void 0,t):n}function c(n,t){var r;return null!==(r=s(n))&&void 0!==r?r:s(t)}function l(n){return!!Array.isArray(n)}function v(n,t){if(!n)throw t instanceof String?t.valueOf():Error(t?s(t):t)}function h(n){return String(n)===n}function g(n){return!!n===n}function p(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 N(n){return!n||(Object.prototype.hasOwnProperty.call(n,"length")?e(n,0):"object"==typeof n&&e(Object.keys(n),0))}function y(n,t){return n={pass:n},t&&(n.message=t),n}function d(n,t){try{return n.run(t)}catch(n){return y(!1)}}function m(n,t){return h(n)&&h(t)&&n.endsWith(t)}function O(n,t){return n===t}function b(n,t){return r(n,t)||u(n,t)}function E(n,t){return!!(l(t)||h(t)&&h(n))&&-1!==t.indexOf(n)}function x(n,r){return t(n)&&t(r)&&Number(n)<Number(r)}function w(n,t){return r(n,t)||x(n,t)}function q(n,t,r){return b(n,t)&&w(n,r)}function S(n){return f(n)||h(n)&&!n.trim()}function T(n,t){return n in t}function A(n){return Number.isNaN(n)}function B(n){return"number"==typeof n}function P(n){return!!n}function W(n,t){if(f(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):!!h(t)&&new RegExp(t).test(n)}function k(n,t){return h(n)&&h(t)&&n.startsWith(t)}function F(n){for(var t in cn){var r=cn[t];a(r)&&n(t,r)}}function I(){return null}function J(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 K(){try{return a(Proxy)}catch(n){return!1}}function R(n,t,r){for(var e=[],u=3;u<arguments.length;u++)e[u-3]=arguments[u];return v(g(n)||n&&g(n.pass),"Incorrect return value for rule: "+JSON.stringify(n)),g(n)?y(n):y(n.pass,s.apply(void 0,J([n.message,t,r],e,!1)))}function U(n){function t(t,r,e){return function(){for(var u=[],i=0;i<arguments.length;i++)u[i]=arguments[i];return v((i=ln.run({value:n},(function(){return R.apply(void 0,J([r.apply(void 0,J([n],u,!1)),e,n],u,!1))}))).pass,f(i.message)?"enforce/".concat(e," failed with ").concat(JSON.stringify(n)):new String(s(i.message))),t}}var r={};if(!K())return F((function(n,e){r[n]=t(r,e,n)})),r;var e=new Proxy(r,{get:function(n,r){if(n=cn[r])return t(e,n,r)}});return e}function V(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=cn[e];r.push((function(n){return R.apply(void 0,J([o.apply(void 0,J([n],u,!1)),e,n],u,!1))}));var f={run:function(n){return c(p(r,(function(r,e){var u,i=ln.run({value:n},(function(){return r(n)}));e(!i.pass,y(!!i.pass,null!==(u=s(t,n,i.message))&&void 0!==u?u:i.message))})),y(!0))},test:function(n){return f.run(n).pass},message:function(n){return n&&(t=n),f}};return K()?f=new Proxy(f,{get:function(t,r){return cn[r]?n(r):t[r]}}):(F((function(t){f[t]=n(t)})),f)}}(n)}var X=n(t),z=n(r),C=n(e),M=n(i),D=n(o),G=n(f),H=n(l),L=Object.assign,Q=n(N),Y=n(m),Z=n(O),$=n(E),_=n(q),nn=n(S),tn=n(g),rn=n(T),en=n(A),un=n(B),on=n(h),fn=n(P),an=n(W),sn=n(j),cn={condition:function(n,t){try{return t(n)}catch(n){return!1}},doesNotEndWith:Y,doesNotStartWith:n(k),endsWith:m,equals:O,greaterThan:u,greaterThanOrEquals:b,gt:u,gte:b,inside:E,isArray:l,isBetween:q,isBlank:S,isBoolean:g,isEmpty:N,isEven:function(n){return!!t(n)&&0==n%2},isFalsy:fn,isKeyOf:T,isNaN:A,isNegative:function(n){return x(n,0)},isNotArray:H,isNotBetween:_,isNotBlank:nn,isNotBoolean:tn,isNotEmpty:Q,isNotKeyOf:rn,isNotNaN:en,isNotNull:M,isNotNullish:G,isNotNumber:un,isNotNumeric:X,isNotString:on,isNotUndefined:D,isNotValueOf:an,isNull:i,isNullish:f,isNumber:B,isNumeric:t,isOdd:function(n){return!!t(n)&&0!=n%2},isPositive:function(n){return u(n,0)},isString:h,isTruthy:P,isUndefined:o,isValueOf:W,lengthEquals:e,lengthNotEquals:C,lessThan:x,lessThanOrEquals:w,longerThan:function(n,t){return u(n.length,t)},longerThanOrEquals:function(n,t){return b(n.length,t)},lt:x,lte:w,matches:j,notEquals:Z,notInside:$,notMatches:sn,numberEquals:r,numberNotEquals:z,shorterThan:function(n,t){return x(n.length,t)},shorterThanOrEquals:function(n,t){return w(n.length,t)},startsWith:k},ln=function(n){function t(t,u){var i,o,f=r();return t=L({},f||{},null!==(i=s(n,t,f))&&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,c(n,"Context was used after it was closed")),t}}}((function(n,t){var r={value:n.value,meta:n.meta||{}};return t?n.set?L(r,{parent:function(){return t?{value:t.value,meta:t.meta,parent:t.parent}:t}}):t:L(r,{parent:I})}));(function(){function n(){if(!K())return F((function(n){t[n]=V(n)})),L(U,t)}var t={context:function(){return ln.useX()},extend:function(t){L(cn,t),n()}};return n(),new Proxy(L(U,t),{get:function(n,t){return t in n?n[t]:cn[t]?V(t):void 0}})})().extend({allOf:function(n){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];return c(p(t,(function(t,r){r(!(t=d(t,n)).pass,t)})),y(!0))},anyOf:function(n){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];return c(p(t,(function(t,r){r((t=d(t,n)).pass,t)})),y(!1))},noneOf:function(n){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];return c(p(t,(function(t,r){r((t=d(t,n)).pass,y(!1))})),y(!0))},oneOf:function(n){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];var e=0;return t.some((function(t){if(d(t,n).pass&&e++,u(e,1))return!1})),y(1===e)}})}));
|
|
@@ -532,30 +532,47 @@
|
|
|
532
532
|
|
|
533
533
|
function enforceEager(value) {
|
|
534
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.
|
|
535
538
|
if (!isProxySupported()) {
|
|
539
|
+
// We iterate over each of the rules, and add them to the target object being return by enforce
|
|
536
540
|
eachEnforceRule(function (ruleName, ruleFn) {
|
|
541
|
+
// We then wrap the rule with `genRuleCall` that adds the base enforce behavior
|
|
537
542
|
target[ruleName] = genRuleCall(target, ruleFn, ruleName);
|
|
538
543
|
});
|
|
539
544
|
return target;
|
|
540
545
|
}
|
|
546
|
+
// We create a proxy intercepting access to the target object (which is empty).
|
|
541
547
|
var proxy = new Proxy(target, {
|
|
542
548
|
get: function (_, ruleName) {
|
|
549
|
+
// On property access, we identify if it is a rule or not.
|
|
543
550
|
var rule = getRule(ruleName);
|
|
551
|
+
// If it is a rule, we wrap it with `genRuleCall` that adds the base enforce behavior
|
|
544
552
|
if (rule) {
|
|
545
553
|
return genRuleCall(proxy, rule, ruleName);
|
|
546
554
|
}
|
|
547
555
|
}
|
|
548
556
|
});
|
|
549
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
|
|
550
561
|
function genRuleCall(target, rule, ruleName) {
|
|
551
562
|
return function ruleCall() {
|
|
552
563
|
var args = [];
|
|
553
564
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
554
565
|
args[_i] = arguments[_i];
|
|
555
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
|
|
556
571
|
var transformedResult = ctx.run({ value: value }, function () {
|
|
557
572
|
return transformResult.apply(void 0, __spreadArray([rule.apply(void 0, __spreadArray([value], args, false)), ruleName, value], args, false));
|
|
558
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.
|
|
559
576
|
invariant(transformedResult.pass, isNullish(transformedResult.message)
|
|
560
577
|
? "enforce/".concat(ruleName, " failed with ").concat(JSON.stringify(value))
|
|
561
578
|
: StringObject(transformedResult.message));
|
|
@@ -1,8 +1,8 @@
|
|
|
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
6
|
|
|
7
7
|
function isNumeric(value) {
|
|
8
8
|
var str = String(value);
|
|
@@ -27,11 +27,6 @@
|
|
|
27
27
|
return isFunction(value) ? value.apply(void 0, args) : value;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
function defaultTo(value, defaultValue) {
|
|
31
|
-
var _a;
|
|
32
|
-
return (_a = optionalFunctionValue(value)) !== null && _a !== void 0 ? _a : optionalFunctionValue(defaultValue);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
30
|
/**
|
|
36
31
|
* A safe hasOwnProperty access
|
|
37
32
|
*/
|
|
@@ -57,57 +52,33 @@
|
|
|
57
52
|
return greaterThan(value, 0);
|
|
58
53
|
}
|
|
59
54
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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(
|
|
71
|
+
return isPositive(summary.testCount);
|
|
86
72
|
}
|
|
87
73
|
if (hasOwnProperty(testedStorage, fieldName))
|
|
88
74
|
return testedStorage[fieldName];
|
|
89
75
|
testedStorage[fieldName] =
|
|
90
|
-
hasOwnProperty(
|
|
91
|
-
isPositive(
|
|
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
|
|
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
|
|
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})}));
|