vest 4.0.0-dev-366a8b → 4.0.0-dev-e266d9
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/CHANGELOG.md +70 -49
- package/README.md +2 -112
- package/dist/cjs/classnames.development.js +3 -3
- package/dist/cjs/classnames.production.js +1 -1
- package/dist/cjs/compose.js +7 -0
- package/dist/cjs/compounds.js +7 -0
- package/dist/cjs/enforce/compose.development.js +139 -0
- package/dist/cjs/enforce/compose.production.js +1 -0
- package/dist/cjs/enforce/compounds.development.js +132 -0
- package/dist/cjs/enforce/compounds.production.js +1 -0
- package/dist/cjs/enforce/package.json +1 -0
- package/dist/cjs/enforce/schema.development.js +144 -0
- package/dist/cjs/enforce/schema.production.js +1 -0
- package/dist/cjs/promisify.development.js +1 -1
- package/dist/cjs/promisify.production.js +1 -1
- package/dist/cjs/schema.js +7 -0
- package/dist/cjs/vest.development.js +608 -1097
- package/dist/cjs/vest.production.js +1 -1
- package/dist/es/classnames.development.js +3 -3
- package/dist/es/classnames.production.js +1 -1
- package/dist/es/enforce/compose.development.js +137 -0
- package/dist/es/enforce/compose.production.js +1 -0
- package/dist/es/enforce/compounds.development.js +130 -0
- package/dist/es/enforce/compounds.production.js +1 -0
- package/dist/es/enforce/package.json +1 -0
- package/dist/es/enforce/schema.development.js +140 -0
- package/dist/es/enforce/schema.production.js +1 -0
- package/dist/es/promisify.development.js +1 -1
- package/dist/es/promisify.production.js +1 -1
- package/dist/es/vest.development.js +602 -1097
- package/dist/es/vest.production.js +1 -1
- package/dist/umd/classnames.development.js +3 -3
- package/dist/umd/classnames.production.js +1 -1
- package/dist/umd/enforce/compose.development.js +143 -0
- package/dist/umd/enforce/compose.production.js +1 -0
- package/dist/umd/enforce/compounds.development.js +136 -0
- package/dist/umd/enforce/compounds.production.js +1 -0
- package/dist/umd/enforce/schema.development.js +148 -0
- package/dist/umd/enforce/schema.production.js +1 -0
- package/dist/umd/promisify.development.js +1 -1
- package/dist/umd/promisify.production.js +1 -1
- package/dist/umd/vest.development.js +1693 -2185
- package/dist/umd/vest.production.js +1 -1
- package/enforce/compose/package.json +7 -0
- package/enforce/compounds/package.json +7 -0
- package/enforce/schema/package.json +7 -0
- package/package.json +107 -13
- package/testUtils/mockThrowError.ts +16 -0
- package/types/classnames.d.ts +2 -2
- package/types/enforce/compose.d.ts +134 -0
- package/types/enforce/compounds.d.ts +146 -0
- package/types/enforce/schema.d.ts +151 -0
- package/types/vest.d.ts +31 -196
- package/docs/.nojekyll +0 -0
- package/docs/README.md +0 -113
- package/docs/_assets/favicon.ico +0 -0
- package/docs/_assets/vest-logo.png +0 -0
- package/docs/_sidebar.md +0 -14
- package/docs/cross_field_validations.md +0 -33
- package/docs/enforce.md +0 -11
- package/docs/exclusion.md +0 -129
- package/docs/getting_started.md +0 -72
- package/docs/group.md +0 -142
- package/docs/index.html +0 -41
- package/docs/migration.md +0 -202
- package/docs/n4s/rules.md +0 -1282
- package/docs/node.md +0 -36
- package/docs/optional.md +0 -103
- package/docs/result.md +0 -249
- package/docs/state.md +0 -102
- package/docs/test.md +0 -172
- package/docs/utilities.md +0 -109
- package/docs/warn.md +0 -82
|
@@ -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).vest={})}(this,(function(n){function t(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||t)}function r(n){return"function"==typeof n}function e(n,t){function r(n){e=!0,u=n}for(var e=!1,u=null,i=0;i<n.length;i++)if(t(n[i],r,i),e)return u}function u(n){for(var t=[],e=1;e<arguments.length;e++)t[e-1]=arguments[e];return r(n)?n.apply(void 0,t):n}function i(n,t){var r;return null!==(r=u(n))&&void 0!==r?r:t}function o(n,t){return n={pass:n},t&&(n.message=t),n}function s(n,t){try{return n.run(t)}catch(n){return o(!1)}}function a(n){return function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return!n.apply(void 0,t)}}function c(n,t){return n.length===Number(t)}function f(n,t){return n.length>Number(t)}function l(n){return null===n}function p(n){return void 0===n}function v(n){return String(n)===n}function d(n,t){return v(n)&&v(t)&&n.endsWith(t)}function h(n,t){return n===t}function g(n){var t=Number(n);return!(isNaN(parseFloat(String(n)))||isNaN(Number(n))||!isFinite(t))}function m(n,t){return g(n)&&g(t)&&Number(n)>Number(t)}function y(n,t){return g(n)&&g(t)&&Number(n)>=Number(t)}function N(n){return!!Array.isArray(n)}function b(n,t){return!!(N(t)||v(t)&&v(n))&&-1!==t.indexOf(n)}function E(n,t){return g(n)&&g(t)&&Number(n)<=Number(t)}function C(n,t,r){return y(n,t)&&E(n,r)}function O(n){return v(n)&&!n.trim()}function T(n){return!!n===n}function w(n){return"number"==typeof n}function S(n){if(n){if(w(n))return 0===n;if(Object.prototype.hasOwnProperty.call(n,"length"))return c(n,0);if("object"==typeof n)return c(Object.keys(n),0)}return!0}function P(n){return Number.isNaN(n)}function x(n){return!!g(n)&&0>Number(n)}function k(n){return!!n}function F(n,t){return g(n)&&g(t)&&Number(n)<Number(t)}function I(n,t){return t instanceof RegExp?t.test(n):!!v(t)&&new RegExp(t).test(n)}function A(n,t){return g(n)&&g(t)&&Number(n)===Number(t)}function W(n,t){return v(n)&&v(t)&&n.startsWith(t)}function j(n,t){throw Error(i(t,n))}function R(n){function t(t,u){var i,o,s=r();return t=Mn({},s||{},null!==(i=null==n?void 0:n(t,s))&&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;return null!==(t=e.ctx)&&void 0!==t?t:j(i(n,"Context was used after it was closed"))}}}function X(){return null}function U(n,t){var r,e=function(r){var e=n[r],u=t[r];if(!(r=vt.run({value:e,set:!0,meta:{key:r}},(function(){return s(u,e)}))).pass)return{value:r}};for(r in t){var u=e(r);if("object"==typeof u)return u.value}return o(!0)}function D(n){for(var t in dt){var e=dt[t];r(e)&&n(t,e)}}function L(){return"function"==typeof Proxy}function G(n,r,e){for(var i=[],s=3;s<arguments.length;s++)i[s-3]=arguments[s];return T(n)||n&&T(n.pass)||j("Incorrect return value for rule: "+JSON.stringify(n)),T(n)?o(n):o(n.pass,u.apply(void 0,t([n.message,r,e],i)))}function q(n){function r(r,e,u){return function(){for(var i=[],o=0;o<arguments.length;o++)i[o]=arguments[o];if(!(o=G.apply(void 0,t([vt.run({value:n},(function(){return e.apply(void 0,t([n],i))})),u,n],i))).pass){if(!S(o.message))throw o.message;j("enforce/"+u+" failed with "+JSON.stringify(n))}return r}}var e={};if(!L())return D((function(n,t){e[n]=r(e,t,n)})),e;var u=new Proxy(e,{get:function(n,t){if(n=dt[t])return r(u,n,t)}});return u}function B(n){var r,s=[];return function n(a){return function(){for(var c=[],f=0;f<arguments.length;f++)c[f]=arguments[f];var l=dt[a];s.push((function(n){return G.apply(void 0,t([l.apply(void 0,t([n],c)),a,n],c))}));var p={run:function(n){return i(e(s,(function(t,e){var i,s=vt.run({value:n},(function(){return t(n)}));s.pass||e(o(!!s.pass,null!==(i=u(r,n,s.message))&&void 0!==i?i:s.message))})),o(!0))},test:function(n){return p.run(n).pass},message:function(n){return n&&(r=n),p}};return L()?p=new Proxy(p,{get:function(t,r){return dt[r]?n(r):t[r]}}):(D((function(t){p[t]=n(t)})),p)}}(n)}function _(n){var t,r={};for(t in n)r[t]=ht.optional(n[t]);return r}function K(n){return(n=[].concat(n))[n.length-1]}function H(){function n(){t=[0]}var t=[];return n(),{addLevel:function(){t.push(0)},cursorAt:function(){return K(t)},getCursor:function(){return[].concat(t)},next:function(){return t[t.length-1]++,K(t)},removeLevel:function(){t.pop()},reset:n}}function M(n,t){return n.map((function(n){return N(n)?M(n,t):t(n)}))}function J(n,t){for(var r=[],e=0;e<n.length;e++){var u=n[e];N(u)?r.push(J(u,t)):t(u)&&r.push(u)}return r}function V(n){return[].concat(n).reduce((function(n,t){return N(t)?n.concat(V(t)):[].concat(n).concat(t)}),[])}function z(n,t){return Y(n,t).splice(t[K(t)],1),n}function Y(n,t){var r=0;for(t=t.slice(0,-1);r<t.length;r++){var e=t[r];n[e]=i(n[e],[]),n=n[e]}return n}function Q(n){void 0===n&&(n=1);var t=[],r=function(e,u){var i=r.get(e);return i?i[1]:(u=u(),t.unshift([e.concat(),u]),f(t,n)&&(t.length=n),u)};return r.invalidate=function(n){var r=t.findIndex((function(t){var r=t[0];return c(n,r.length)&&n.every((function(n,t){return n===r[t]}))}));-1<r&&t.splice(r,1)},r.get=function(n){return t[t.findIndex((function(t){var r=t[0];return c(n,r.length)&&n.every((function(n,t){return n===r[t]}))}))]||null},r}function Z(){return yt.useX().stateRef}function $(){(0,Z().testObjects()[1])((function(n){return{prev:n.prev,current:[].concat(n.current)}}))}function nn(n){(0,Z().testObjects()[1])((function(t){return{prev:t.prev,current:[].concat(n(t.current))}}))}function tn(){return V(J(Z().testObjects()[0].current,(function(n){return n.isPending()})))}function rn(){var n=Z().testObjects()[0].current;return Nt([n],(function(){return V(n)}))}function en(){return yt.useX().testCursor.getCursor()}function un(n,t){if(n=void 0===(n=n.type)?_n.DEFAULT:n,r(t)){var e=en();return yt.run({isolate:{type:n}},(function(){yt.useX().testCursor.addLevel(),nn((function(n){return Y(n,e)[K(e)]=[],n}));var n=t();return yt.useX().testCursor.removeLevel(),yt.useX().testCursor.next(),n}))}}function on(n,t){return!(!t||n.fieldName!==t)}function sn(){var n=Z().optionalFields()[0];if(!S(n)){var t={};nn((function(e){return M(e,(function(e){var u=e.fieldName;if(t.hasOwnProperty(u))t[e.fieldName]&&e.omit();else{var i=n[u];r(i)&&(t[u]=i(),t[e.fieldName]&&e.omit())}return e}))}))}}function an(n){var t=tn();return!S(t)&&(n?t.some((function(t){return on(t,n)})):it(t))}function cn(n,t){function r(n,t){i[n]++,u&&(i[t]=(i[t]||[]).concat(u))}var e=t.fieldName,u=t.message;n[e]=n[e]||{errorCount:0,warnCount:0,testCount:0};var i=n[e];return t.isSkipped()||(n[e].testCount++,t.isFailing()?r("errorCount","errors"):t.isWarning()&&r("warnCount","warnings")),i}function fn(n,t,r){var e;void 0===r&&(r={});var u=(r=r||{}).group,i=r.fieldName;return t.reduce((function(t,r){return u&&r.groupName!==u||i&&!on(r,i)||"warnings"===n!=!!r.warns||!r.hasFailures()||(t[r.fieldName]=(t[r.fieldName]||[]).concat(r.message||[])),t}),Hn({},i&&((e={})[i]=[],e)))}function ln(n){return vn("errors",n)}function pn(n){return vn("warnings",n)}function vn(n,t){return n=fn(n,rn(),{fieldName:t}),t?n[t]:n}function dn(n,t){return n=gn("errors",n,t),t?n[t]:n}function hn(n,t){return n=gn("warnings",n,t),t?n[t]:n}function gn(n,t,r){return t||j("get"+n[0].toUpperCase()+n.slice(1)+"ByGroup requires a group name. Received `"+t+"` instead."),fn(n,rn(),{group:t,fieldName:r})}function mn(n,t,r){return!(!n.hasFailures()||r&&!on(n,r)||"warnings"===t!=!!n.warns)}function yn(n){return bn("errors",n)}function Nn(n){return bn("warnings",n)}function bn(n,t){return rn().some((function(r){return mn(r,n,t)}))}function En(n,t){return On("errors",n,t)}function Cn(n,t){return On("warnings",n,t)}function On(n,t,r){return rn().some((function(e){return t===e.groupName&&mn(e,n,r)}))}function Tn(){var n=rn(),t={stateRef:Z()};return bt([n],yt.bind(t,(function(){return Mn(function(){var n={errorCount:0,groups:{},testCount:0,tests:{},warnCount:0};return rn().forEach((function(t){var r=t.fieldName,e=t.groupName;n.tests[r]=cn(n.tests,t),e&&(n.groups[e]=n.groups[e]||{},n.groups[e][r]=cn(n.groups[e],t))})),function(n){for(var t in n.tests)n.errorCount+=n.tests[t].errorCount,n.warnCount+=n.tests[t].warnCount,n.testCount+=n.tests[t].testCount;return n}(n)}(),{getErrors:yt.bind(t,ln),getErrorsByGroup:yt.bind(t,dn),getWarnings:yt.bind(t,pn),getWarningsByGroup:yt.bind(t,hn),hasErrors:yt.bind(t,yn),hasErrorsByGroup:yt.bind(t,En),hasWarnings:yt.bind(t,Nn),hasWarningsByGroup:yt.bind(t,Cn),isValid:yt.bind(t,(function(n){var t=Tn(),r=rn().reduce((function(n,t){return n[t.fieldName]||t.isOmitted()&&(n[t.fieldName]=!0),n}),{});return(r=!!n&&!!r[n])?n=!0:t.hasErrors(n)?n=!1:n=!(S(r=rn())||n&&S(t.tests[n])||function(n){var t=Z().optionalFields()[0];return it(tn().filter((function(r){return!(n&&!on(r,n))&&!0!==t[r.fieldName]})))}(n))&&function(n){var t=rn(),r=Z().optionalFields()[0];return t.every((function(t){return!(!n||on(t,n))||!0===r[t.fieldName]||t.isTested()||t.isOmitted()}))}(n),n}))})})))}function wn(){var n=rn(),t={stateRef:Z()};return Et([n],yt.bind(t,(function(){return Mn({},Tn(),{done:yt.bind(t,Ct)})})))}function Sn(n,t,e){return!(r(n)&&(!t||e.tests[t]&&0!==e.tests[t].testCount))}function Pn(n){return!(an()&&(!n||an(n)))}function xn(n,t){var r=yt.bind({},n);(0,Z().testCallbacks()[1])((function(n){return t?n.fieldCallbacks[t]=(n.fieldCallbacks[t]||[]).concat(r):n.doneCallbacks.push(r),n}))}function kn(n){return n.forEach((function(n){return n()}))}function Fn(){var n=yt.useX();return n.bus||j(),n.bus}function In(n){return Wn("only","tests",n)}function An(n){return Wn("skip","tests",n)}function Wn(n,t,r){var e=yt.useX("hook called outside of a running suite.");r&&[].concat(r).forEach((function(r){v(r)&&(e.exclusion[t][r]="only"===n)}))}function jn(n){for(var t in n)if(!0===n[t])return!0;return!1}function Rn(n){j("Wrong arguments passed to group. Group "+n+".")}function Xn(n){var t=n.asyncTest,e=n.message;if(t&&r(t.then)){var u=Fn().emit,i=Z(),o=yt.bind({stateRef:i},(function(){$(),u(mt.TEST_COMPLETED,n)}));i=yt.bind({stateRef:i},(function(t){n.isCanceled()||(n.message=v(t)?t:e,n.fail(),o())}));try{t.then(o,i)}catch(n){i()}}}function Un(n){var t=Z().testObjects(),r=t[1],e=t[0].prev;if(S(e))return Dn(n),n;if(Gn(t=Ln(e),n)){for(function(n,t){yt.useX().isolate.type!==_n.EACH&&function(n,t){setTimeout((function(){j(n,t)}),0)}("Vest Critical Error: Tests called in different order than previous run.\n expected: "+n.fieldName+"\n received: "+t.fieldName+"\n This usually happens when you conditionally call your tests using if/else.\n This might lead to unexpected validation results.\n Replacing if/else with skipWhen solves these issues.")}(t,n);Gn(t,n);)t=Z().testObjects()[0],t=Ln(e=z(t.prev,en()));r((function(n){return{prev:e,current:n.current}}))}return Dn(n=i(t,n)),n}function Dn(n){var t=en();nn((function(r){return Y(r,t)[K(t)]=n,r}))}function Ln(n){var t=en();return Y(n,t)[K(t)]}function Gn(n,t){return it(n)&&!(n.fieldName===t.fieldName&&n.groupName===t.groupName)}function qn(n){var t=Un(n);if(function(n){var t=n.fieldName;n=n.groupName;var r=yt.useX();if(r.skipped)return!0;var e=(r=r.exclusion).tests,u=e[t];if(!1===u)return!0;if(u=!0===u,n){n:{var i=yt.useX().exclusion.groups;if(Object.prototype.hasOwnProperty.call(i,n))var o=!1===i[n];else{for(o in i)if(!0===i[o]){o=!0;break n}o=!1}}if(o)return!0;if(!0===r.groups[n])return!(u||!jn(e)&&!1!==e[t])}return!u&&jn(e)}(n))return n.skip(),yt.useX().testCursor.next(),t;if(n!==t&&t.fieldName===n.fieldName&&t.groupName===n.groupName&&t.isPending()&&t.cancel(),Dn(n),yt.useX().testCursor.next(),n.isUntested()){t=Fn().emit;var e=function(n){return yt.run({currentTest:n},(function(){try{var t=n.testFn()}catch(r){t=r,p(n.message)&&v(t)&&(n.message=r),t=!1}return!1===t&&n.fail(),t}))}(n);try{e&&r(e.then)?(n.asyncTest=e,n.setPending(),Xn(n)):t(mt.TEST_COMPLETED,n)}catch(t){j("Your test function "+n.fieldName+" returned "+JSON.stringify(e)+'. Only "false" or a Promise are supported. Return values may cause unexpected behavior.')}}else(t=n.asyncTest)&&r(t.then)&&(n.setPending(),Xn(n));return n}function Bn(n){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];r=t.reverse(),t=r[0],r=r[1];var e=yt.useX();return qn(t=new Ot(n,t,{message:r,groupName:null==e?void 0:e.groupName}))}var _n,Kn,Hn=function(){return(Hn=Object.assign||function(n){for(var t,r=1,e=arguments.length;r<e;r++)for(var u in t=arguments[r])Object.prototype.hasOwnProperty.call(t,u)&&(n[u]=t[u]);return n}).apply(this,arguments)},Mn=Object.assign,Jn=a(c),Vn=a(l),zn=a(p),Yn=a(d),Qn=a(h),Zn=a(g),$n=a(N),nt=a(b),tt=a(C),rt=a(O),et=a(T),ut=a(w),it=a(S),ot=a(P),st=a(x),at=a(v),ct=a(k),ft=a(I),lt=a(A),pt=a(W),vt=R((function(n,t){var r={value:n.value,meta:n.meta||{}};return t?n.set?Mn(r,{parent:function(){return t?{value:t.value,meta:t.meta,parent:t.parent}:t}}):t:Mn(r,{parent:X})})),dt=Mn({condition:function(n,t){try{return t(n)}catch(n){return!1}},doesNotEndWith:Yn,doesNotStartWith:pt,endsWith:d,equals:h,greaterThan:m,greaterThanOrEquals:y,gt:m,gte:y,inside:b,isArray:N,isBetween:C,isBlank:O,isBoolean:T,isEmpty:S,isEven:function(n){return!!g(n)&&0==n%2},isFalsy:ct,isNaN:P,isNegative:x,isNotArray:$n,isNotBetween:tt,isNotBlank:rt,isNotBoolean:et,isNotEmpty:it,isNotNaN:ot,isNotNull:Vn,isNotNumber:ut,isNotNumeric:Zn,isNotString:at,isNotUndefined:zn,isNull:l,isNumber:w,isNumeric:g,isOdd:function(n){return!!g(n)&&0!=n%2},isPositive:st,isString:v,isTruthy:k,isUndefined:p,lengthEquals:c,lengthNotEquals:Jn,lessThan:F,lessThanOrEquals:E,longerThan:f,longerThanOrEquals:function(n,t){return n.length>=Number(t)},lt:F,lte:E,matches:I,notEquals:Qn,notInside:nt,notMatches:ft,numberEquals:A,numberNotEquals:lt,shorterThan:function(n,t){return n.length<Number(t)},shorterThanOrEquals:function(n,t){return n.length<=Number(t)},startsWith:W},{allOf:function(n){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];return i(e(t,(function(t,r){(t=s(t,n)).pass||r(t)})),o(!0))},anyOf:function(n){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];return i(e(t,(function(t,r){(t=s(t,n)).pass&&r(t)})),o(!1))},noneOf:function(n){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];return i(e(t,(function(t,r){s(t,n).pass&&r(o(!1))})),o(!0))},oneOf:function(n){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];var e=[];return t.some((function(t){if(f(e,1))return!1;(t=s(t,n)).pass&&e.push(t)})),o(c(e,1))},optional:function(n,t){return p(n)||null===n?o(!0):s(t,n)}},{shape:function(n,t){var r=U(n,t);if(!r.pass)return r;for(var e in n)if(!Object.prototype.hasOwnProperty.call(t,e))return o(!1);return o(!0)},loose:U,isArrayOf:function(n,t){return i(e(n,(function(n,r,e){(e=vt.run({value:n,set:!0,meta:{index:e}},(function(){return s(t,n)}))).pass||r(e)})),o(!0))}}),ht=(Kn=Hn({context:function(){return vt.useX()},extend:function(n){Mn(dt,n)}},{partial:_}),L()?new Proxy(Mn(q,Kn),{get:function(n,t){return t in n?n[t]:dt[t]?B(t):void 0}}):(D((function(n){Kn[n]=B(n)})),Kn)),gt=function(n){return function(){return""+n++}}(0);!function(n){n[n.DEFAULT=0]="DEFAULT",n[n.SUITE=1]="SUITE",n[n.EACH=2]="EACH",n[n.SKIP_WHEN=3]="SKIP_WHEN",n[n.GROUP=4]="GROUP"}(_n||(_n={}));var mt,yt=R((function(n,t){return t?null:Mn({},{isolate:{type:_n.DEFAULT},testCursor:H(),exclusion:{tests:{},groups:{}}},n)})),Nt=Q(),bt=Q(20),Et=Q(20),Ct=function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var r=(n=n.reverse())[0];if(n=n[1],t=wn(),Sn(r,n,t))return t;var e=function(){return r(Tn())};return Pn(n)?(e(),t):(xn(e,n),t)};(mt||(mt={})).TEST_COMPLETED="test_completed",In.group=function(n){return Wn("only","groups",n)},An.group=function(n){return Wn("skip","groups",n)};var Ot=function(){function n(n,t,r){var e=void 0===r?{}:r;r=e.message,e=e.groupName,this.id=gt(),this.warns=!1,this.status=Tt,this.fieldName=n,this.testFn=t,e&&(this.groupName=e),r&&(this.message=r)}return n.prototype.run=function(){try{var n=this.testFn()}catch(t){n=t,p(this.message)&&v(n)&&(this.message=t),n=!1}return!1===n&&this.fail(),n},n.prototype.setStatus=function(n){this.isFinalStatus()&&n!==It||(this.status=n)},n.prototype.setPending=function(){this.setStatus(kt)},n.prototype.fail=function(){this.setStatus(this.warns?Pt:St)},n.prototype.done=function(){this.isFinalStatus()||this.setStatus(xt)},n.prototype.warn=function(){this.warns=!0},n.prototype.isFinalStatus=function(){return this.hasFailures()||this.isCanceled()||this.isPassing()},n.prototype.skip=function(){this.setStatus(wt)},n.prototype.cancel=function(){this.setStatus(Ft),$()},n.prototype.omit=function(){this.setStatus(It)},n.prototype.valueOf=function(){return!this.isFailing()},n.prototype.hasFailures=function(){return this.isFailing()||this.isWarning()},n.prototype.isPending=function(){return this.status===kt},n.prototype.isTested=function(){return this.hasFailures()||this.isPassing()},n.prototype.isOmitted=function(){return this.status===It},n.prototype.isUntested=function(){return this.status===Tt},n.prototype.isFailing=function(){return this.status===St},n.prototype.isCanceled=function(){return this.status===Ft},n.prototype.isSkipped=function(){return this.status===wt},n.prototype.isPassing=function(){return this.status===xt},n.prototype.isWarning=function(){return this.status===Pt},n}(),Tt="UNTESTED",wt="SKIPPED",St="FAILED",Pt="WARNING",xt="PASSING",kt="PENDING",Ft="CANCELED",It="OMITTED",At=Mn(Bn,{each:function(n){return function(r){return N(r)||j("test.each: Expected table to be an array."),function(e){for(var i=[],o=1;o<arguments.length;o++)i[o-1]=arguments[o];var s=(i=i.reverse())[0],a=i[1];return un({type:_n.EACH},(function(){return r.map((function(r){return r=[].concat(r),n(u.apply(void 0,t([e],r)),u.apply(void 0,t([a],r)),(function(){return s.apply(void 0,r)}))}))}))}}}(Bn),memo:function(n){var t=Q(100);return function(r){for(var e=[],u=1;u<arguments.length;u++)e[u-1]=arguments[u];u=Z().suiteId()[0];var i=yt.useX().testCursor.cursorAt(),o=(e=e.reverse())[1],s=e[2];return e=[u,r,i].concat(e[0]),null===(u=t.get(e))?t(e,(function(){return n(r,s,o)})):u[1].isCanceled()?(t.invalidate(e),t(e,(function(){return n(r,s,o)}))):qn(u[1])}}(Bn)});n.VERSION="4.0.0-dev-366a8b",n.create=function(n){r(n)||j("Suite initialization error. Expected `tests` to be a function.");var t=function(){var n=function(){var n={};return{emit:function(t,r){n[t]&&n[t].forEach((function(n){n(r)}))},on:function(t,r){return n[t]||(n[t]=[]),n[t].push(r),{off:function(){n[t]=n[t].filter((function(n){return n!==r}))}}}}}();return n.on(mt.TEST_COMPLETED,(function(n){if(!n.isCanceled()){n.done(),n=n.fieldName;var t=Z().testCallbacks()[0].fieldCallbacks;n&&!an(n)&&N(t[n])&&kn(t[n]),n=Z().testCallbacks()[0].doneCallbacks,an()||kn(n)}})),n}(),e=function(n){function t(n,t,r){return i.references.push(),e(n,u(t,r)),function(){return[i.references[n],function(t){return e(n,u(t,i.references[n]))}]}}function e(t,e){var u=i.references[t];i.references[t]=e,r(t=o[t][1])&&t(e,u),r(n)&&n()}var i={references:[]},o=[];return{registerStateKey:function(n,r){var e=o.length;return o.push([n,r]),t(e,n)},reset:function(){var n=i.references;i.references=[],o.forEach((function(r,e){return t(e,r[0],n[e])}))}}}(),o=function(n,t){return t=t.suiteId,{optionalFields:n.registerStateKey((function(){return{}})),suiteId:n.registerStateKey(t),testCallbacks:n.registerStateKey((function(){return{fieldCallbacks:{},doneCallbacks:[]}})),testObjects:n.registerStateKey((function(n){return{prev:i(null==n?void 0:n.current,[]),current:[]}}))}}(e,{suiteId:gt()});return Mn(yt.bind({stateRef:o,bus:t},(function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return e.reset(),un({type:_n.SUITE},(function(){n.apply(void 0,t)})),sn(),wn()})),{get:yt.bind({stateRef:o},Tn),remove:yt.bind({stateRef:o},(function(n){rn().forEach((function(t){on(t,n)&&(t.cancel(),function(n){nn((function(t){return J(t,(function(t){return n!==t}))}))}(t))}))})),reset:e.reset})},n.enforce=ht,n.group=function(n,t){v(n)||Rn("name must be a string"),r(t)||Rn("callback must be a function"),un({type:_n.GROUP},(function(){yt.run({groupName:n},t)}))},n.only=In,n.optional=function(n){(0,Z().optionalFields()[1])((function(t){if(N(n)||v(n))[].concat(n).forEach((function(n){t[n]=!0}));else for(var r in n)t[r]=n[r];return t}))},n.skip=An,n.skipWhen=function(n,t){un({type:_n.SKIP_WHEN},(function(){yt.run({skipped:u(n)},(function(){return t()}))}))},n.test=At,n.warn=function(){var n=yt.useX("warn hook called outside of a running suite.");n.currentTest||j("warn called outside of a test."),n.currentTest.warn()},Object.defineProperty(n,"__esModule",{value:!0})}));
|
|
1
|
+
"use strict";!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("n4s"),require("context")):"function"==typeof define&&define.amd?define(["exports","n4s","context"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).vest={},t.n4s,t.context)}(this,(function(t,n,e){function r(t){return"function"==typeof t}function u(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];return r(t)?t.apply(void 0,n):t}function i(t,n){var e;return null!==(e=u(t))&&void 0!==e?e:n}function o(t,n){throw Error(i(n,t))}function s(t,n){setTimeout((function(){o(t,n)}),0)}function a(t){function n(t,n,r){return i.references.push(),e(t,u(n,r)),function(){return[i.references[t],function(n){return e(t,u(n,i.references[t]))}]}}function e(n,e){var u=i.references[n];i.references[n]=e,r(n=o[n][1])&&n(e,u),r(t)&&t()}var i={references:[]},o=[];return{registerStateKey:function(t,e){var r=o.length;return o.push([t,e]),n(r,t)},reset:function(){var t=i.references;i.references=[],o.forEach((function(e,r){return n(r,e[0],t[r])}))}}}function c(t,n){var e=n.suiteId;return n=n.suiteName,{optionalFields:t.registerStateKey((function(){return{}})),suiteId:t.registerStateKey(e),suiteName:t.registerStateKey(n),testCallbacks:t.registerStateKey((function(){return{fieldCallbacks:{},doneCallbacks:[]}})),testObjects:t.registerStateKey((function(t){return{prev:t?t.current:[],current:[]}}))}}function f(t){return(t=[].concat(t))[t.length-1]}function l(){function t(){n=[0]}var n=[];return t(),{addLevel:function(){n.push(0)},cursorAt:function(){return f(n)},getCursor:function(){return[].concat(n)},next:function(){return n[n.length-1]++,f(n)},removeLevel:function(){n.pop()},reset:t}}function p(t){return function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return!t.apply(void 0,n)}}function d(t,n){for(var e=[],r=0;r<t.length;r++){var u=t[r];Array.isArray(u)?e.push(d(u,n)):(u=n(u),ht(u)&&e.push(u))}return e}function v(t){return[].concat(t).reduce((function(t,n){return Array.isArray(n)?t.concat(v(n)):[].concat(t).concat(n)}),[])}function g(t,n){var e=0;for(n=n.slice(0,-1);e<n.length;e++){var r=n[e];t[r]=i(t[r],[]),t=t[r]}return t}function h(t){return null==t}function y(t){return String(t)===t}function m(t){void 0===t&&(t=1);var n=[],e=function(r,u){var i=e.get(r);return i?i[1]:(u=u(),n.unshift([r.concat(),u]),n.length>Number(t)&&(n.length=t),u)};return e.invalidate=function(t){var e=n.findIndex((function(n){var e=n[0];return t.length===Number(e.length)&&t.every((function(t,n){return t===e[n]}))}));-1<e&&n.splice(e,1)},e.get=function(t){return n[n.findIndex((function(n){var e=n[0];return t.length===Number(e.length)&&t.every((function(t,n){return t===e[n]}))}))]||null},e}function E(){return gt.useX().stateRef}function b(){return E().testObjects()}function N(){(0,b()[1])((function(t){return{prev:t.prev,current:[].concat(t.current)}}))}function C(t){(0,b()[1])((function(n){return{prev:n.prev,current:[].concat(t(n.current))}}))}function k(){return v(d(b()[0].current,(function(t){return t.isPending()?t:null})))}function T(){var t=b()[0].current;return yt([t],(function(){return v(t)}))}function S(){return gt.useX().testCursor.getCursor()}function O(t,n){if(t=void 0===(t=t.type)?ft.DEFAULT:t,r(n)){var e={current:{},prev:{}},u=S();return gt.run({isolate:{type:t,keys:e}},(function(){gt.useX().testCursor.addLevel(),e.prev=function(){var t=b()[0].prev;return[].concat(g(t,S())).reduce((function(t,n){return n instanceof Et&&!h(n.key)?(t[n.key]=n,t):t}),{})}(),C((function(t){return g(t,u)[f(u)]=[],t}));var t=n();return gt.useX().testCursor.removeLevel(),gt.useX().testCursor.next(),t}))}}function P(t){if(t){if("number"==typeof t)return 0===t;if(Object.prototype.hasOwnProperty.call(t,"length"))return t.length===Number(0);if("object"==typeof t)return Object.keys(t).length===Number(0)}return!0}function w(t,n){return!(!n||t.fieldName!==n)}function F(t){var n=k();return!P(n)&&(t?n.some((function(n){return w(n,t)})):wt(n))}function I(t,n){function e(t,n){i[t]++,u&&(i[n]=(i[n]||[]).concat(u))}var r=n.fieldName,u=n.message;t[r]=t[r]||{errorCount:0,warnCount:0,testCount:0};var i=t[r];return n.isSkipped()||(t[r].testCount++,n.isFailing()?e("errorCount","errors"):n.isWarning()&&e("warnCount","warnings")),i}function A(t,n,e){if(e||2===arguments.length)for(var r,u=0,i=n.length;u<i;u++)!r&&u in n||(r||(r=Array.prototype.slice.call(n,0,u)),r[u]=n[u]);return t.concat(r||n)}function x(t,n,e){var r;void 0===e&&(e={});var u=(e=e||{}).group,i=e.fieldName;return n.reduce((function(n,e){if(u&&e.groupName!==u)var r=!0;else i&&!w(e,i)?r=!0:(r=e.warns(),r="warnings"===t!=!!r);return r||!e.hasFailures()||(n[e.fieldName]=(n[e.fieldName]||[]).concat(e.message||[])),n}),Ft({},i&&((r={})[i]=[],r)))}function X(t){return L("errors",t)}function D(t){return L("warnings",t)}function L(t,n){return t=x(t,T(),{fieldName:n}),n?t[n]:t}function U(t,n){return t=W("errors",t,n),n?t[n]:t}function _(t,n){return t=W("warnings",t,n),n?t[n]:t}function W(t,n,e){return n||o("get"+t[0].toUpperCase()+t.slice(1)+"ByGroup requires a group name. Received `"+n+"` instead."),x(t,T(),{group:n,fieldName:e})}function R(t,n,e){return(e=!t.hasFailures()||e&&!w(t,e))||(e="warnings"===n!=!!(t=t.warns())),!e}function j(t){return M("errors",t)}function G(t){return M("warnings",t)}function M(t,n){return T().some((function(e){return R(e,t,n)}))}function K(t,n){return V("errors",t,n)}function H(t,n){return V("warnings",t,n)}function V(t,n,e){return T().some((function(r){return n===r.groupName&&R(r,t,e)}))}function B(){var t=T(),n={stateRef:E()};return It([t],gt.bind(n,(function(){var t=E().suiteName()[0];return pt(function(){var t={errorCount:0,groups:{},testCount:0,tests:{},warnCount:0};return T().forEach((function(n){var e=n.fieldName,r=n.groupName;t.tests[e]=I(t.tests,n),r&&(t.groups[r]=t.groups[r]||{},t.groups[r][e]=I(t.groups[r],n))})),function(t){for(var n in t.tests)t.errorCount+=t.tests[n].errorCount,t.warnCount+=t.tests[n].warnCount,t.testCount+=t.tests[n].testCount;return t}(t)}(),{getErrors:gt.bind(n,X),getErrorsByGroup:gt.bind(n,U),getWarnings:gt.bind(n,D),getWarningsByGroup:gt.bind(n,_),hasErrors:gt.bind(n,j),hasErrorsByGroup:gt.bind(n,K),hasWarnings:gt.bind(n,G),hasWarningsByGroup:gt.bind(n,H),isValid:gt.bind(n,(function(t){var n=B(),e=T().reduce((function(t,n){return t[n.fieldName]||n.isOmitted()&&(t[n.fieldName]=!0),t}),{});return(e=!!t&&!!e[t])?t=!0:n.hasErrors(t)?t=!1:t=!(P(e=T())||t&&P(n.tests[t])||function(t){var n=E().optionalFields()[0];return wt(k().filter((function(e){return!(t&&!w(e,t))&&!0!==n[e.fieldName]})))}(t))&&function(t){var n=T(),e=E().optionalFields()[0];return n.every((function(n){return!(!t||w(n,t))||!0===e[n.fieldName]||n.isTested()||n.isOmitted()}))}(t),t})),suiteName:t})})))}function q(){var t=T(),n={stateRef:E()};return At([t],gt.bind(n,(function(){return pt({},B(),{done:gt.bind(n,xt)})})))}function Y(t,n,e){return!(r(t)&&(!n||e.tests[n]&&!P(e.tests[n].testCount)))}function z(t){return!(F()&&(!t||F(t)))}function J(t,n){var e=gt.bind({},t);(0,E().testCallbacks()[1])((function(t){return n?t.fieldCallbacks[n]=(t.fieldCallbacks[n]||[]).concat(e):t.doneCallbacks.push(e),t}))}function Q(t){return t.forEach((function(t){return t()}))}function Z(){var t=function(){var t={};return{emit:function(n,e){t[n]&&t[n].forEach((function(t){t(e)}))},on:function(n,e){return t[n]||(t[n]=[]),t[n].push(e),{off:function(){t[n]=t[n].filter((function(t){return t!==e}))}}}}}();return t.on(mt.TEST_COMPLETED,(function(t){if(!t.isCanceled()){t.done(),t=t.fieldName;var n=E().testCallbacks()[0].fieldCallbacks;t&&!F(t)&&Array.isArray(n[t])&&Q(n[t]),t=E().testCallbacks()[0].doneCallbacks,F()||Q(t)}})),t.on(mt.SUITE_COMPLETED,(function(){!function(){var t=E().optionalFields()[0];if(!P(t)){var n={};C((function(e){return d(e,(function(e){var u=e.fieldName;if(n.hasOwnProperty(u))n[e.fieldName]&&e.omit();else{var i=t[u];r(i)&&(n[u]=i(),n[e.fieldName]&&e.omit())}return e}))}))}}()})),t.on(mt.REMOVE_FIELD,(function(t){T().forEach((function(n){w(n,t)&&(n.cancel(),function(t){C((function(n){return d(n,(function(n){return t!==n?n:null}))}))}(n))}))})),t}function $(){var t=gt.useX();return t.bus||o(),t.bus}function tt(t){return et(0,"tests",t)}function nt(t){return et(1,"tests",t)}function et(t,n,e){var r=gt.useX("hook called outside of a running suite.");e&&[].concat(e).forEach((function(e){y(e)&&(r.exclusion[n][e]=0===t)}))}function rt(t){for(var n in t)if(!0===t[n])return!0;return!1}function ut(t){o("Wrong arguments passed to group. Group "+t+".")}function it(t){var n=t.asyncTest,e=t.message;if(n&&r(n.then)){var u=$().emit,i=E(),o=gt.bind({stateRef:i},(function(){N(),u(mt.TEST_COMPLETED,t)}));i=gt.bind({stateRef:i},(function(n){t.isCanceled()||(t.message=y(n)?n:e,t.fail(),o())}));try{n.then(o,i)}catch(t){i()}}}function ot(t){var n=S();C((function(e){return g(e,n)[f(n)]=t,e}))}function st(t){var n=b()[0].prev;if(P(n))ot(t),n=t;else{var e=S();if(n=g(n,e)[f(e)],h(t.key))!wt(e=n)||e.fieldName===t.fieldName&&e.groupName===t.groupName||(gt.useX().isolate.type!==ft.EACH&&s("Vest Critical Error: Tests called in different order than previous run.\n expected: "+n.fieldName+"\n received: "+t.fieldName+'\n This can happen on one of two reasons:\n 1. You\'re using if/else statements to conditionally select tests. Instead, use "skipWhen".\n 2. You are iterating over a list of tests, and their order changed. Use "each" and a custom key prop so that Vest retains their state.'),function(){var t=b(),n=t[1],e=t[0].prev;t=g(e,S());var r=gt.useX().testCursor.cursorAt();t.splice(r),n((function(t){return{prev:e,current:t.current}}))}(),n=null),ot(n=i(n,t));else{n=t.key;var u=gt.useX().isolate.keys.prev[n];e=t,u&&(e=u),u=e;var a=gt.useX().isolate.keys.current;h(a[n])?a[n]=u:s('Encountered the same test key "'+n+"\" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted."),ot(n=e)}}if(function(t){var n=t.fieldName;if(t=t.groupName,gt.useX().skipped)return!0;var e=gt.useX().exclusion,r=e.tests,u=r[n];if(!1===u)return!0;if(u=!0===u,t){t:{var i=gt.useX().exclusion.groups;if(Object.prototype.hasOwnProperty.call(i,t))var o=!1===i[t];else{for(o in i)if(!0===i[o]){o=!0;break t}o=!1}}if(o)return!0;if(!0===e.groups[t])return!(u||!rt(r)&&!1!==r[n])}n=gt.useX().exclusion;t:{for(s in(e=gt.useX().exclusion).groups)if(e.groups[s]){var s=!0;break t}s=!1}return!(!s||t&&t in n.groups&&n.groups[t])||!u&&rt(r)}(t))return n.skip(!!gt.useX().skipped),gt.useX().testCursor.next(),n;if(t!==n&&n.fieldName===t.fieldName&&n.groupName===t.groupName&&n.isPending()&&n.cancel(),ot(t),gt.useX().testCursor.next(),t.isUntested()){n=$(),e=function(t){return gt.run({currentTest:t},(function(){try{var n=t.testFn()}catch(e){n=e,void 0===t.message&&y(n)&&(t.message=e),n=!1}return!1===n&&t.fail(),n}))}(t);try{e&&r(e.then)?(t.asyncTest=e,t.setPending(),it(t)):n.emit(mt.TEST_COMPLETED,t)}catch(n){o("Your test function "+t.fieldName+' returned a value. Only "false" or Promise returns are supported.')}}else(n=t.asyncTest)&&r(n.then)&&(t.setPending(),it(t));return t}function at(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];var u=r(n[1])?n:A([void 0],n);n=u[0],e=u[1],u=u[2],Xt(t)&&ct("fieldName","string"),r(e)||ct("Test callback","function");var i=gt.useX();return st(n=new Et(t,e,{message:n,groupName:i.groupName,key:u}))}function ct(t,n){o("Incompatible params passed to test function. "+t+" must be a "+n)}var ft,lt,pt=Object.assign,dt=(lt=0,function(){return""+lt++});!function(t){t[t.DEFAULT=0]="DEFAULT",t[t.SUITE=1]="SUITE",t[t.EACH=2]="EACH",t[t.SKIP_WHEN=3]="SKIP_WHEN",t[t.GROUP=4]="GROUP"}(ft||(ft={}));var vt,gt=e.createContext((function(t,n){return n?null:pt({},{exclusion:{tests:{},groups:{}},isolate:{type:ft.DEFAULT,keys:{current:{},prev:{}}},testCursor:l()},t)})),ht=p((function(t){return null===t})),yt=m();!function(t){t.Error="error",t.Warning="warning"}(vt||(vt={}));var mt,Et=function(){function t(t,n,e){var r=void 0===e?{}:e;e=r.message;var u=r.groupName;r=r.key,this.key=null,this.id=dt(),this.severity=vt.Error,this.status=bt,this.fieldName=t,this.testFn=n,u&&(this.groupName=u),e&&(this.message=e),r&&(this.key=r)}return t.prototype.run=function(){try{var t=this.testFn()}catch(n){t=n,void 0===this.message&&y(t)&&(this.message=n),t=!1}return!1===t&&this.fail(),t},t.prototype.setStatus=function(t){this.isFinalStatus()&&t!==Pt||(this.status=t)},t.prototype.warns=function(){return this.severity===vt.Warning},t.prototype.setPending=function(){this.setStatus(St)},t.prototype.fail=function(){this.setStatus(this.warns()?kt:Ct)},t.prototype.done=function(){this.isFinalStatus()||this.setStatus(Tt)},t.prototype.warn=function(){this.severity=vt.Warning},t.prototype.isFinalStatus=function(){return this.hasFailures()||this.isCanceled()||this.isPassing()},t.prototype.skip=function(t){this.isPending()&&!t||this.setStatus(Nt)},t.prototype.cancel=function(){this.setStatus(Ot),N()},t.prototype.omit=function(){this.setStatus(Pt)},t.prototype.valueOf=function(){return!this.isFailing()},t.prototype.hasFailures=function(){return this.isFailing()||this.isWarning()},t.prototype.isPending=function(){return this.status===St},t.prototype.isTested=function(){return this.hasFailures()||this.isPassing()},t.prototype.isOmitted=function(){return this.status===Pt},t.prototype.isUntested=function(){return this.status===bt},t.prototype.isFailing=function(){return this.status===Ct},t.prototype.isCanceled=function(){return this.status===Ot},t.prototype.isSkipped=function(){return this.status===Nt},t.prototype.isPassing=function(){return this.status===Tt},t.prototype.isWarning=function(){return this.status===kt},t}(),bt="UNTESTED",Nt="SKIPPED",Ct="FAILED",kt="WARNING",Tt="PASSING",St="PENDING",Ot="CANCELED",Pt="OMITTED",wt=p(P),Ft=function(){return(Ft=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var u in n=arguments[e])Object.prototype.hasOwnProperty.call(n,u)&&(t[u]=n[u]);return t}).apply(this,arguments)},It=m(20),At=m(20),xt=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var e=(t=t.reverse())[0];if(t=t[1],n=q(),Y(e,t,n))return n;var r=function(){return e(B())};return z(t)?(r(),n):(J(r,t),n)};!function(t){t.TEST_COMPLETED="test_completed",t.REMOVE_FIELD="remove_field",t.SUITE_COMPLETED="suite_completed"}(mt||(mt={})),tt.group=function(t){return et(0,"groups",t)},nt.group=function(t){return et(1,"groups",t)};var Xt=p(y),Dt=pt(at,{memo:function(t){var n=m(100);return function(e){for(var r=[],u=1;u<arguments.length;u++)r[u-1]=arguments[u];u=gt.useX().testCursor.cursorAt();var i=(r=r.reverse())[0],o=r[1],s=r[2];return u=[E().suiteId()[0],e,u].concat(i),null===(r=n.get(u))?n(u,(function(){return t(e,s,o)})):r[1].isCanceled()?(n.invalidate(u),n(u,(function(){return t(e,s,o)}))):st(r[1])}}(at)});Object.defineProperty(t,"enforce",{enumerable:!0,get:function(){return n.enforce}}),t.VERSION="4.0.0-dev-e266d9",t.create=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var e=(t=t.reverse())[0];t=t[1],r(e)||o("vest.create: Expected callback to be a function.");var u=Z(),i=a();return t={stateRef:c(i,{suiteId:dt(),suiteName:t}),bus:u},pt(gt.bind(t,(function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return i.reset(),O({type:ft.SUITE},(function(){e.apply(void 0,t)})),u.emit(mt.SUITE_COMPLETED),q()})),{get:gt.bind(t,B),reset:i.reset,remove:gt.bind(t,(function(t){u.emit(mt.REMOVE_FIELD,t)}))})},t.each=function(t,n){r(n)||o("callback must be a function"),O({type:ft.EACH},(function(){t.forEach((function(t,e){n(t,e)}))}))},t.group=function(t,n){y(t)||ut("name must be a string"),r(n)||ut("callback must be a function"),O({type:ft.GROUP},(function(){gt.run({groupName:t},n)}))},t.only=tt,t.optional=function(t){(0,E().optionalFields()[1])((function(n){if(Array.isArray(t)||y(t))[].concat(t).forEach((function(t){n[t]=!0}));else for(var e in t)n[e]=t[e];return n}))},t.skip=nt,t.skipWhen=function(t,n){O({type:ft.SKIP_WHEN},(function(){gt.run({skipped:u(t,u(B))},(function(){return n()}))}))},t.test=Dt,t.warn=function(){var t=gt.useX("warn hook called outside of a running suite.");t.currentTest||o("warn called outside of a test."),t.currentTest.warn()},Object.defineProperty(t,"__esModule",{value:!0})}));
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "4.0.0-dev-
|
|
2
|
+
"version": "4.0.0-dev-e266d9",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "vest",
|
|
5
5
|
"author": "ealush",
|
|
@@ -19,6 +19,10 @@
|
|
|
19
19
|
"bugs": {
|
|
20
20
|
"url": "https://github.com/ealush/vest.git/issues"
|
|
21
21
|
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"context": "next",
|
|
24
|
+
"n4s": "next"
|
|
25
|
+
},
|
|
22
26
|
"homepage": "https://vestjs.dev/",
|
|
23
27
|
"exports": {
|
|
24
28
|
"./classnames": {
|
|
@@ -46,10 +50,100 @@
|
|
|
46
50
|
"browser": "./dist/es/classnames.production.js",
|
|
47
51
|
"umd": "./dist/umd/classnames.production.js",
|
|
48
52
|
"import": "./dist/es/classnames.production.js",
|
|
49
|
-
"require": "./dist/cjs/classnames.js",
|
|
50
|
-
"node": "./dist/cjs/classnames.js",
|
|
53
|
+
"require": "./dist/cjs/classnames.production.js",
|
|
54
|
+
"node": "./dist/cjs/classnames.production.js",
|
|
51
55
|
"module": "./dist/es/classnames.production.js",
|
|
52
|
-
"default": "./dist/cjs/classnames.js"
|
|
56
|
+
"default": "./dist/cjs/classnames.production.js"
|
|
57
|
+
},
|
|
58
|
+
"./enforce/compose": {
|
|
59
|
+
"production": {
|
|
60
|
+
"types": "./types/enforce/compose.d.ts",
|
|
61
|
+
"browser": "./dist/es/enforce/compose.production.js",
|
|
62
|
+
"umd": "./dist/umd/enforce/compose.production.js",
|
|
63
|
+
"import": "./dist/es/enforce/compose.production.js",
|
|
64
|
+
"require": "./dist/cjs/enforce/compose.production.js",
|
|
65
|
+
"node": "./dist/cjs/enforce/compose.production.js",
|
|
66
|
+
"module": "./dist/es/enforce/compose.production.js",
|
|
67
|
+
"default": "./dist/cjs/enforce/compose.production.js"
|
|
68
|
+
},
|
|
69
|
+
"development": {
|
|
70
|
+
"types": "./types/enforce/compose.d.ts",
|
|
71
|
+
"browser": "./dist/es/enforce/compose.development.js",
|
|
72
|
+
"umd": "./dist/umd/enforce/compose.development.js",
|
|
73
|
+
"import": "./dist/es/enforce/compose.development.js",
|
|
74
|
+
"require": "./dist/cjs/enforce/compose.development.js",
|
|
75
|
+
"node": "./dist/cjs/enforce/compose.development.js",
|
|
76
|
+
"module": "./dist/es/enforce/compose.development.js",
|
|
77
|
+
"default": "./dist/cjs/enforce/compose.development.js"
|
|
78
|
+
},
|
|
79
|
+
"types": "./types/enforce/compose.d.ts",
|
|
80
|
+
"browser": "./dist/es/enforce/compose.production.js",
|
|
81
|
+
"umd": "./dist/umd/enforce/compose.production.js",
|
|
82
|
+
"import": "./dist/es/enforce/compose.production.js",
|
|
83
|
+
"require": "./dist/cjs/enforce/compose.production.js",
|
|
84
|
+
"node": "./dist/cjs/enforce/compose.production.js",
|
|
85
|
+
"module": "./dist/es/enforce/compose.production.js",
|
|
86
|
+
"default": "./dist/cjs/enforce/compose.production.js"
|
|
87
|
+
},
|
|
88
|
+
"./enforce/compounds": {
|
|
89
|
+
"production": {
|
|
90
|
+
"types": "./types/enforce/compounds.d.ts",
|
|
91
|
+
"browser": "./dist/es/enforce/compounds.production.js",
|
|
92
|
+
"umd": "./dist/umd/enforce/compounds.production.js",
|
|
93
|
+
"import": "./dist/es/enforce/compounds.production.js",
|
|
94
|
+
"require": "./dist/cjs/enforce/compounds.production.js",
|
|
95
|
+
"node": "./dist/cjs/enforce/compounds.production.js",
|
|
96
|
+
"module": "./dist/es/enforce/compounds.production.js",
|
|
97
|
+
"default": "./dist/cjs/enforce/compounds.production.js"
|
|
98
|
+
},
|
|
99
|
+
"development": {
|
|
100
|
+
"types": "./types/enforce/compounds.d.ts",
|
|
101
|
+
"browser": "./dist/es/enforce/compounds.development.js",
|
|
102
|
+
"umd": "./dist/umd/enforce/compounds.development.js",
|
|
103
|
+
"import": "./dist/es/enforce/compounds.development.js",
|
|
104
|
+
"require": "./dist/cjs/enforce/compounds.development.js",
|
|
105
|
+
"node": "./dist/cjs/enforce/compounds.development.js",
|
|
106
|
+
"module": "./dist/es/enforce/compounds.development.js",
|
|
107
|
+
"default": "./dist/cjs/enforce/compounds.development.js"
|
|
108
|
+
},
|
|
109
|
+
"types": "./types/enforce/compounds.d.ts",
|
|
110
|
+
"browser": "./dist/es/enforce/compounds.production.js",
|
|
111
|
+
"umd": "./dist/umd/enforce/compounds.production.js",
|
|
112
|
+
"import": "./dist/es/enforce/compounds.production.js",
|
|
113
|
+
"require": "./dist/cjs/enforce/compounds.production.js",
|
|
114
|
+
"node": "./dist/cjs/enforce/compounds.production.js",
|
|
115
|
+
"module": "./dist/es/enforce/compounds.production.js",
|
|
116
|
+
"default": "./dist/cjs/enforce/compounds.production.js"
|
|
117
|
+
},
|
|
118
|
+
"./enforce/schema": {
|
|
119
|
+
"production": {
|
|
120
|
+
"types": "./types/enforce/schema.d.ts",
|
|
121
|
+
"browser": "./dist/es/enforce/schema.production.js",
|
|
122
|
+
"umd": "./dist/umd/enforce/schema.production.js",
|
|
123
|
+
"import": "./dist/es/enforce/schema.production.js",
|
|
124
|
+
"require": "./dist/cjs/enforce/schema.production.js",
|
|
125
|
+
"node": "./dist/cjs/enforce/schema.production.js",
|
|
126
|
+
"module": "./dist/es/enforce/schema.production.js",
|
|
127
|
+
"default": "./dist/cjs/enforce/schema.production.js"
|
|
128
|
+
},
|
|
129
|
+
"development": {
|
|
130
|
+
"types": "./types/enforce/schema.d.ts",
|
|
131
|
+
"browser": "./dist/es/enforce/schema.development.js",
|
|
132
|
+
"umd": "./dist/umd/enforce/schema.development.js",
|
|
133
|
+
"import": "./dist/es/enforce/schema.development.js",
|
|
134
|
+
"require": "./dist/cjs/enforce/schema.development.js",
|
|
135
|
+
"node": "./dist/cjs/enforce/schema.development.js",
|
|
136
|
+
"module": "./dist/es/enforce/schema.development.js",
|
|
137
|
+
"default": "./dist/cjs/enforce/schema.development.js"
|
|
138
|
+
},
|
|
139
|
+
"types": "./types/enforce/schema.d.ts",
|
|
140
|
+
"browser": "./dist/es/enforce/schema.production.js",
|
|
141
|
+
"umd": "./dist/umd/enforce/schema.production.js",
|
|
142
|
+
"import": "./dist/es/enforce/schema.production.js",
|
|
143
|
+
"require": "./dist/cjs/enforce/schema.production.js",
|
|
144
|
+
"node": "./dist/cjs/enforce/schema.production.js",
|
|
145
|
+
"module": "./dist/es/enforce/schema.production.js",
|
|
146
|
+
"default": "./dist/cjs/enforce/schema.production.js"
|
|
53
147
|
},
|
|
54
148
|
"./parser": {
|
|
55
149
|
"production": {
|
|
@@ -76,10 +170,10 @@
|
|
|
76
170
|
"browser": "./dist/es/parser.production.js",
|
|
77
171
|
"umd": "./dist/umd/parser.production.js",
|
|
78
172
|
"import": "./dist/es/parser.production.js",
|
|
79
|
-
"require": "./dist/cjs/parser.js",
|
|
80
|
-
"node": "./dist/cjs/parser.js",
|
|
173
|
+
"require": "./dist/cjs/parser.production.js",
|
|
174
|
+
"node": "./dist/cjs/parser.production.js",
|
|
81
175
|
"module": "./dist/es/parser.production.js",
|
|
82
|
-
"default": "./dist/cjs/parser.js"
|
|
176
|
+
"default": "./dist/cjs/parser.production.js"
|
|
83
177
|
},
|
|
84
178
|
"./promisify": {
|
|
85
179
|
"production": {
|
|
@@ -106,10 +200,10 @@
|
|
|
106
200
|
"browser": "./dist/es/promisify.production.js",
|
|
107
201
|
"umd": "./dist/umd/promisify.production.js",
|
|
108
202
|
"import": "./dist/es/promisify.production.js",
|
|
109
|
-
"require": "./dist/cjs/promisify.js",
|
|
110
|
-
"node": "./dist/cjs/promisify.js",
|
|
203
|
+
"require": "./dist/cjs/promisify.production.js",
|
|
204
|
+
"node": "./dist/cjs/promisify.production.js",
|
|
111
205
|
"module": "./dist/es/promisify.production.js",
|
|
112
|
-
"default": "./dist/cjs/promisify.js"
|
|
206
|
+
"default": "./dist/cjs/promisify.production.js"
|
|
113
207
|
},
|
|
114
208
|
".": {
|
|
115
209
|
"development": {
|
|
@@ -126,10 +220,10 @@
|
|
|
126
220
|
"browser": "./dist/es/vest.production.js",
|
|
127
221
|
"umd": "./dist/umd/vest.production.js",
|
|
128
222
|
"import": "./dist/es/vest.production.js",
|
|
129
|
-
"require": "./dist/cjs/vest.js",
|
|
130
|
-
"node": "./dist/cjs/vest.js",
|
|
223
|
+
"require": "./dist/cjs/vest.production.js",
|
|
224
|
+
"node": "./dist/cjs/vest.production.js",
|
|
131
225
|
"module": "./dist/es/vest.production.js",
|
|
132
|
-
"default": "./dist/cjs/vest.js"
|
|
226
|
+
"default": "./dist/cjs/vest.production.js"
|
|
133
227
|
},
|
|
134
228
|
"./package.json": "./package.json",
|
|
135
229
|
"./": "./"
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export default function mockThrowError() {
|
|
2
|
+
const throwErrorDeferred = jest.fn();
|
|
3
|
+
const throwError = jest.fn();
|
|
4
|
+
jest.resetModules();
|
|
5
|
+
jest.mock('throwError', () => ({
|
|
6
|
+
throwErrorDeferred,
|
|
7
|
+
default: throwError,
|
|
8
|
+
}));
|
|
9
|
+
const vest = require('vest');
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
throwErrorDeferred,
|
|
13
|
+
throwError,
|
|
14
|
+
vest,
|
|
15
|
+
};
|
|
16
|
+
}
|
package/types/classnames.d.ts
CHANGED
|
@@ -59,7 +59,7 @@ interface IDone {
|
|
|
59
59
|
/**
|
|
60
60
|
* Creates a function that returns class names that match the validation result
|
|
61
61
|
*/
|
|
62
|
-
declare function
|
|
62
|
+
declare function classnames(res: IVestResult | TDraftResult, classes?: TSupportedClasses): (fieldName: string) => string;
|
|
63
63
|
type TSupportedClasses = {
|
|
64
64
|
valid?: string;
|
|
65
65
|
tested?: string;
|
|
@@ -67,4 +67,4 @@ type TSupportedClasses = {
|
|
|
67
67
|
warning?: string;
|
|
68
68
|
untested?: string;
|
|
69
69
|
};
|
|
70
|
-
export {
|
|
70
|
+
export { classnames as default };
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
type DropFirst<T extends unknown[]> = T extends [
|
|
2
|
+
unknown,
|
|
3
|
+
...infer U
|
|
4
|
+
] ? U : never;
|
|
5
|
+
type TStringable = string | ((...args: any[]) => string);
|
|
6
|
+
type TRuleReturn = boolean | {
|
|
7
|
+
pass: boolean;
|
|
8
|
+
message?: TStringable;
|
|
9
|
+
};
|
|
10
|
+
type TRuleDetailedResult = {
|
|
11
|
+
pass: boolean;
|
|
12
|
+
message?: string;
|
|
13
|
+
};
|
|
14
|
+
type TArgs = any[];
|
|
15
|
+
type TBaseRules = typeof baseRules;
|
|
16
|
+
type KBaseRules = keyof TBaseRules;
|
|
17
|
+
declare function condition(value: any, callback: (value: any) => TRuleReturn): TRuleReturn;
|
|
18
|
+
declare function endsWith(value: string, arg1: string): boolean;
|
|
19
|
+
declare function equals(value: unknown, arg1: unknown): boolean;
|
|
20
|
+
declare function greaterThan(value: number | string, gt: number | string): boolean;
|
|
21
|
+
declare function greaterThanOrEquals(value: string | number, gte: string | number): boolean;
|
|
22
|
+
declare function inside(value: unknown, arg1: string | unknown[]): boolean;
|
|
23
|
+
// The module is named "isArrayValue" since it
|
|
24
|
+
// is conflicting with a nested npm dependency.
|
|
25
|
+
// We may need to revisit this in the future.
|
|
26
|
+
declare function isArray(value: unknown): value is Array<unknown>;
|
|
27
|
+
declare function isBetween(value: number | string, min: number | string, max: number | string): boolean;
|
|
28
|
+
declare function isBlank(value: unknown): boolean;
|
|
29
|
+
declare function isBoolean(value: unknown): value is boolean;
|
|
30
|
+
declare function isEmpty(value: unknown): boolean;
|
|
31
|
+
declare function isNaN(value: unknown): boolean;
|
|
32
|
+
declare function isNegative(value: number | string): boolean;
|
|
33
|
+
declare function isNull(value: unknown): value is null;
|
|
34
|
+
declare function isNullish(value: any): value is null | undefined;
|
|
35
|
+
declare function isNumber(value: unknown): value is number;
|
|
36
|
+
declare function isNumeric(value: string | number): boolean;
|
|
37
|
+
declare function isStringValue(v: unknown): v is string;
|
|
38
|
+
declare function isTruthy(value: unknown): boolean;
|
|
39
|
+
declare function isUndefined(value?: unknown): boolean;
|
|
40
|
+
declare function lengthEquals(value: string | unknown[], arg1: string | number): boolean;
|
|
41
|
+
declare function lessThan(value: string | number, lt: string | number): boolean;
|
|
42
|
+
declare function lessThanOrEquals(value: string | number, lte: string | number): boolean;
|
|
43
|
+
declare function longerThan(value: string | unknown[], arg1: string | number): boolean;
|
|
44
|
+
declare function longerThanOrEquals(value: string | unknown[], arg1: string | number): boolean;
|
|
45
|
+
declare function matches(value: string, regex: RegExp | string): boolean;
|
|
46
|
+
declare function numberEquals(value: string | number, eq: string | number): boolean;
|
|
47
|
+
declare function shorterThan(value: string | unknown[], arg1: string | number): boolean;
|
|
48
|
+
declare function shorterThanOrEquals(value: string | unknown[], arg1: string | number): boolean;
|
|
49
|
+
declare function startsWith(value: string, arg1: string): boolean;
|
|
50
|
+
declare const baseRules: {
|
|
51
|
+
condition: typeof condition;
|
|
52
|
+
doesNotEndWith: (value: string, arg1: string) => boolean;
|
|
53
|
+
doesNotStartWith: (value: string, arg1: string) => boolean;
|
|
54
|
+
endsWith: typeof endsWith;
|
|
55
|
+
equals: typeof equals;
|
|
56
|
+
greaterThan: typeof greaterThan;
|
|
57
|
+
greaterThanOrEquals: typeof greaterThanOrEquals;
|
|
58
|
+
gt: typeof greaterThan;
|
|
59
|
+
gte: typeof greaterThanOrEquals;
|
|
60
|
+
inside: typeof inside;
|
|
61
|
+
isArray: typeof isArray;
|
|
62
|
+
isBetween: typeof isBetween;
|
|
63
|
+
isBlank: typeof isBlank;
|
|
64
|
+
isBoolean: typeof isBoolean;
|
|
65
|
+
isEmpty: typeof isEmpty;
|
|
66
|
+
isEven: (value: any) => boolean;
|
|
67
|
+
isFalsy: (value: unknown) => boolean;
|
|
68
|
+
isNaN: typeof isNaN;
|
|
69
|
+
isNegative: typeof isNegative;
|
|
70
|
+
isNotArray: (value: unknown) => boolean;
|
|
71
|
+
isNotBetween: (value: string | number, min: string | number, max: string | number) => boolean;
|
|
72
|
+
isNotBlank: (value: unknown) => boolean;
|
|
73
|
+
isNotBoolean: (value: unknown) => boolean;
|
|
74
|
+
isNotEmpty: (value: unknown) => boolean;
|
|
75
|
+
isNotNaN: (value: unknown) => boolean;
|
|
76
|
+
isNotNull: (value: unknown) => boolean;
|
|
77
|
+
isNotNullish: (value: any) => boolean;
|
|
78
|
+
isNotNumber: (value: unknown) => boolean;
|
|
79
|
+
isNotNumeric: (value: string | number) => boolean;
|
|
80
|
+
isNotString: (v: unknown) => boolean;
|
|
81
|
+
isNotUndefined: (value?: unknown) => boolean;
|
|
82
|
+
isNull: typeof isNull;
|
|
83
|
+
isNullish: typeof isNullish;
|
|
84
|
+
isNumber: typeof isNumber;
|
|
85
|
+
isNumeric: typeof isNumeric;
|
|
86
|
+
isOdd: (value: any) => boolean;
|
|
87
|
+
isPositive: (value: string | number) => boolean;
|
|
88
|
+
isString: typeof isStringValue;
|
|
89
|
+
isTruthy: typeof isTruthy;
|
|
90
|
+
isUndefined: typeof isUndefined;
|
|
91
|
+
lengthEquals: typeof lengthEquals;
|
|
92
|
+
lengthNotEquals: (value: string | unknown[], arg1: string | number) => boolean;
|
|
93
|
+
lessThan: typeof lessThan;
|
|
94
|
+
lessThanOrEquals: typeof lessThanOrEquals;
|
|
95
|
+
longerThan: typeof longerThan;
|
|
96
|
+
longerThanOrEquals: typeof longerThanOrEquals;
|
|
97
|
+
lt: typeof lessThan;
|
|
98
|
+
lte: typeof lessThanOrEquals;
|
|
99
|
+
matches: typeof matches;
|
|
100
|
+
notEquals: (value: unknown, arg1: unknown) => boolean;
|
|
101
|
+
notInside: (value: unknown, arg1: string | unknown[]) => boolean;
|
|
102
|
+
notMatches: (value: string, regex: string | RegExp) => boolean;
|
|
103
|
+
numberEquals: typeof numberEquals;
|
|
104
|
+
numberNotEquals: (value: string | number, eq: string | number) => boolean;
|
|
105
|
+
shorterThan: typeof shorterThan;
|
|
106
|
+
shorterThanOrEquals: typeof shorterThanOrEquals;
|
|
107
|
+
startsWith: typeof startsWith;
|
|
108
|
+
};
|
|
109
|
+
type TRules<E = Record<string, unknown>> = n4s.EnforceCustomMatchers<TRules<E> & E> & Record<string, (...args: TArgs) => TRules<E> & E> & {
|
|
110
|
+
[P in KBaseRules]: (...args: DropFirst<Parameters<TBaseRules[P]>> | TArgs) => TRules<E> & E;
|
|
111
|
+
};
|
|
112
|
+
/* eslint-disable @typescript-eslint/no-namespace, @typescript-eslint/no-empty-interface */
|
|
113
|
+
declare global {
|
|
114
|
+
namespace n4s {
|
|
115
|
+
interface IRules<E> extends TRules<E> {
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
type TLazyRules = n4s.IRules<TLazyRuleMethods>;
|
|
120
|
+
type TLazy = TLazyRules & TLazyRuleMethods &
|
|
121
|
+
// This is a "catch all" hack to make TS happy while not
|
|
122
|
+
// losing type hints
|
|
123
|
+
Record<string, (...args: any[]) => any>;
|
|
124
|
+
type TLazyRuleMethods = TLazyRuleRunners & {
|
|
125
|
+
message: (message: TLazyMessage) => TLazy;
|
|
126
|
+
};
|
|
127
|
+
type TLazyRuleRunners = {
|
|
128
|
+
test: (value: unknown) => boolean;
|
|
129
|
+
run: (value: unknown) => TRuleDetailedResult;
|
|
130
|
+
};
|
|
131
|
+
type TComposeResult = TLazyRuleRunners & ((value: any) => void);
|
|
132
|
+
type TLazyMessage = string | ((value: unknown, originalMessage?: TStringable) => string);
|
|
133
|
+
declare function compose(...composites: TLazyRuleRunners[]): TComposeResult;
|
|
134
|
+
export { compose as default };
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
type DropFirst<T extends unknown[]> = T extends [
|
|
2
|
+
unknown,
|
|
3
|
+
...infer U
|
|
4
|
+
] ? U : never;
|
|
5
|
+
type TStringable = string | ((...args: any[]) => string);
|
|
6
|
+
type TRuleReturn = boolean | {
|
|
7
|
+
pass: boolean;
|
|
8
|
+
message?: TStringable;
|
|
9
|
+
};
|
|
10
|
+
type TRuleDetailedResult = {
|
|
11
|
+
pass: boolean;
|
|
12
|
+
message?: string;
|
|
13
|
+
};
|
|
14
|
+
type TArgs = any[];
|
|
15
|
+
type TBaseRules = typeof baseRules;
|
|
16
|
+
type KBaseRules = keyof TBaseRules;
|
|
17
|
+
declare function condition(value: any, callback: (value: any) => TRuleReturn): TRuleReturn;
|
|
18
|
+
declare function endsWith(value: string, arg1: string): boolean;
|
|
19
|
+
declare function equals(value: unknown, arg1: unknown): boolean;
|
|
20
|
+
declare function greaterThan(value: number | string, gt: number | string): boolean;
|
|
21
|
+
declare function greaterThanOrEquals(value: string | number, gte: string | number): boolean;
|
|
22
|
+
declare function inside(value: unknown, arg1: string | unknown[]): boolean;
|
|
23
|
+
// The module is named "isArrayValue" since it
|
|
24
|
+
// is conflicting with a nested npm dependency.
|
|
25
|
+
// We may need to revisit this in the future.
|
|
26
|
+
declare function isArray(value: unknown): value is Array<unknown>;
|
|
27
|
+
declare function isBetween(value: number | string, min: number | string, max: number | string): boolean;
|
|
28
|
+
declare function isBlank(value: unknown): boolean;
|
|
29
|
+
declare function isBoolean(value: unknown): value is boolean;
|
|
30
|
+
declare function isEmpty(value: unknown): boolean;
|
|
31
|
+
declare function isNaN(value: unknown): boolean;
|
|
32
|
+
declare function isNegative(value: number | string): boolean;
|
|
33
|
+
declare function isNull(value: unknown): value is null;
|
|
34
|
+
declare function isNullish(value: any): value is null | undefined;
|
|
35
|
+
declare function isNumber(value: unknown): value is number;
|
|
36
|
+
declare function isNumeric(value: string | number): boolean;
|
|
37
|
+
declare function isStringValue(v: unknown): v is string;
|
|
38
|
+
declare function isTruthy(value: unknown): boolean;
|
|
39
|
+
declare function isUndefined(value?: unknown): boolean;
|
|
40
|
+
declare function lengthEquals(value: string | unknown[], arg1: string | number): boolean;
|
|
41
|
+
declare function lessThan(value: string | number, lt: string | number): boolean;
|
|
42
|
+
declare function lessThanOrEquals(value: string | number, lte: string | number): boolean;
|
|
43
|
+
declare function longerThan(value: string | unknown[], arg1: string | number): boolean;
|
|
44
|
+
declare function longerThanOrEquals(value: string | unknown[], arg1: string | number): boolean;
|
|
45
|
+
declare function matches(value: string, regex: RegExp | string): boolean;
|
|
46
|
+
declare function numberEquals(value: string | number, eq: string | number): boolean;
|
|
47
|
+
declare function shorterThan(value: string | unknown[], arg1: string | number): boolean;
|
|
48
|
+
declare function shorterThanOrEquals(value: string | unknown[], arg1: string | number): boolean;
|
|
49
|
+
declare function startsWith(value: string, arg1: string): boolean;
|
|
50
|
+
declare const baseRules: {
|
|
51
|
+
condition: typeof condition;
|
|
52
|
+
doesNotEndWith: (value: string, arg1: string) => boolean;
|
|
53
|
+
doesNotStartWith: (value: string, arg1: string) => boolean;
|
|
54
|
+
endsWith: typeof endsWith;
|
|
55
|
+
equals: typeof equals;
|
|
56
|
+
greaterThan: typeof greaterThan;
|
|
57
|
+
greaterThanOrEquals: typeof greaterThanOrEquals;
|
|
58
|
+
gt: typeof greaterThan;
|
|
59
|
+
gte: typeof greaterThanOrEquals;
|
|
60
|
+
inside: typeof inside;
|
|
61
|
+
isArray: typeof isArray;
|
|
62
|
+
isBetween: typeof isBetween;
|
|
63
|
+
isBlank: typeof isBlank;
|
|
64
|
+
isBoolean: typeof isBoolean;
|
|
65
|
+
isEmpty: typeof isEmpty;
|
|
66
|
+
isEven: (value: any) => boolean;
|
|
67
|
+
isFalsy: (value: unknown) => boolean;
|
|
68
|
+
isNaN: typeof isNaN;
|
|
69
|
+
isNegative: typeof isNegative;
|
|
70
|
+
isNotArray: (value: unknown) => boolean;
|
|
71
|
+
isNotBetween: (value: string | number, min: string | number, max: string | number) => boolean;
|
|
72
|
+
isNotBlank: (value: unknown) => boolean;
|
|
73
|
+
isNotBoolean: (value: unknown) => boolean;
|
|
74
|
+
isNotEmpty: (value: unknown) => boolean;
|
|
75
|
+
isNotNaN: (value: unknown) => boolean;
|
|
76
|
+
isNotNull: (value: unknown) => boolean;
|
|
77
|
+
isNotNullish: (value: any) => boolean;
|
|
78
|
+
isNotNumber: (value: unknown) => boolean;
|
|
79
|
+
isNotNumeric: (value: string | number) => boolean;
|
|
80
|
+
isNotString: (v: unknown) => boolean;
|
|
81
|
+
isNotUndefined: (value?: unknown) => boolean;
|
|
82
|
+
isNull: typeof isNull;
|
|
83
|
+
isNullish: typeof isNullish;
|
|
84
|
+
isNumber: typeof isNumber;
|
|
85
|
+
isNumeric: typeof isNumeric;
|
|
86
|
+
isOdd: (value: any) => boolean;
|
|
87
|
+
isPositive: (value: string | number) => boolean;
|
|
88
|
+
isString: typeof isStringValue;
|
|
89
|
+
isTruthy: typeof isTruthy;
|
|
90
|
+
isUndefined: typeof isUndefined;
|
|
91
|
+
lengthEquals: typeof lengthEquals;
|
|
92
|
+
lengthNotEquals: (value: string | unknown[], arg1: string | number) => boolean;
|
|
93
|
+
lessThan: typeof lessThan;
|
|
94
|
+
lessThanOrEquals: typeof lessThanOrEquals;
|
|
95
|
+
longerThan: typeof longerThan;
|
|
96
|
+
longerThanOrEquals: typeof longerThanOrEquals;
|
|
97
|
+
lt: typeof lessThan;
|
|
98
|
+
lte: typeof lessThanOrEquals;
|
|
99
|
+
matches: typeof matches;
|
|
100
|
+
notEquals: (value: unknown, arg1: unknown) => boolean;
|
|
101
|
+
notInside: (value: unknown, arg1: string | unknown[]) => boolean;
|
|
102
|
+
notMatches: (value: string, regex: string | RegExp) => boolean;
|
|
103
|
+
numberEquals: typeof numberEquals;
|
|
104
|
+
numberNotEquals: (value: string | number, eq: string | number) => boolean;
|
|
105
|
+
shorterThan: typeof shorterThan;
|
|
106
|
+
shorterThanOrEquals: typeof shorterThanOrEquals;
|
|
107
|
+
startsWith: typeof startsWith;
|
|
108
|
+
};
|
|
109
|
+
type TRules<E = Record<string, unknown>> = n4s.EnforceCustomMatchers<TRules<E> & E> & Record<string, (...args: TArgs) => TRules<E> & E> & {
|
|
110
|
+
[P in KBaseRules]: (...args: DropFirst<Parameters<TBaseRules[P]>> | TArgs) => TRules<E> & E;
|
|
111
|
+
};
|
|
112
|
+
/* eslint-disable @typescript-eslint/no-namespace, @typescript-eslint/no-empty-interface */
|
|
113
|
+
declare global {
|
|
114
|
+
namespace n4s {
|
|
115
|
+
interface IRules<E> extends TRules<E> {
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
type TLazyRules = n4s.IRules<TLazyRuleMethods>;
|
|
120
|
+
type TLazy = TLazyRules & TLazyRuleMethods &
|
|
121
|
+
// This is a "catch all" hack to make TS happy while not
|
|
122
|
+
// losing type hints
|
|
123
|
+
Record<string, (...args: any[]) => any>;
|
|
124
|
+
type TLazyRuleMethods = TLazyRuleRunners & {
|
|
125
|
+
message: (message: TLazyMessage) => TLazy;
|
|
126
|
+
};
|
|
127
|
+
type TLazyRuleRunners = {
|
|
128
|
+
test: (value: unknown) => boolean;
|
|
129
|
+
run: (value: unknown) => TRuleDetailedResult;
|
|
130
|
+
};
|
|
131
|
+
type TLazyMessage = string | ((value: unknown, originalMessage?: TStringable) => string);
|
|
132
|
+
declare function allOf(value: unknown, ...rules: TLazy[]): TRuleDetailedResult;
|
|
133
|
+
declare function anyOf(value: unknown, ...rules: TLazy[]): TRuleDetailedResult;
|
|
134
|
+
declare function noneOf(value: unknown, ...rules: TLazy[]): TRuleDetailedResult;
|
|
135
|
+
declare function oneOf(value: unknown, ...rules: TLazy[]): TRuleDetailedResult;
|
|
136
|
+
declare global {
|
|
137
|
+
namespace n4s {
|
|
138
|
+
interface EnforceCustomMatchers<R> {
|
|
139
|
+
allOf: (...args: DropFirst<Parameters<typeof allOf>>) => R;
|
|
140
|
+
anyOf: (...args: DropFirst<Parameters<typeof anyOf>>) => R;
|
|
141
|
+
noneOf: (...args: DropFirst<Parameters<typeof noneOf>>) => R;
|
|
142
|
+
oneOf: (...args: DropFirst<Parameters<typeof oneOf>>) => R;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
export {};
|