vest 3.2.8-dev-6d7c74 → 3.2.8
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/README.md +115 -0
- package/any.d.ts +3 -0
- package/any.js +1 -0
- package/classNames.d.ts +14 -0
- package/classNames.js +1 -0
- package/docs/.nojekyll +0 -0
- package/docs/README.md +115 -0
- package/docs/_assets/favicon.ico +0 -0
- package/docs/_assets/vest-logo.png +0 -0
- package/docs/_sidebar.md +19 -0
- package/docs/_sidebar.md.bak +14 -0
- package/docs/cross_field_validations.md +79 -0
- package/docs/enforce.md +18 -0
- package/docs/enforce.md.bak +13 -0
- package/docs/exclusion.md +128 -0
- package/docs/getting_started.md +79 -0
- package/docs/group.md +142 -0
- package/docs/index.html +41 -0
- package/docs/migration.md +107 -0
- package/docs/n4s/compound.md +187 -0
- package/docs/n4s/custom.md +52 -0
- package/docs/n4s/external.md +54 -0
- package/docs/n4s/rules.md +1282 -0
- package/docs/n4s/template.md +53 -0
- package/docs/node.md +43 -0
- package/docs/optional.md +51 -0
- package/docs/result.md +238 -0
- package/docs/state.md +102 -0
- package/docs/test.md +172 -0
- package/docs/utilities.md +105 -0
- package/docs/warn.md +82 -0
- package/enforce.d.ts +230 -0
- package/esm/package.json +1 -0
- package/esm/vest.es.development.js +2493 -0
- package/esm/vest.es.production.js +2490 -0
- package/esm/vest.es.production.min.js +1 -0
- package/package.json +65 -12
- package/promisify.d.ts +7 -0
- package/{dist/umd/promisify.production.js → promisify.js} +1 -1
- package/schema.d.ts +26 -0
- package/schema.js +1 -0
- package/vest.cjs.development.js +2494 -0
- package/vest.cjs.production.js +2491 -0
- package/vest.cjs.production.min.js +1 -0
- package/vest.d.ts +254 -0
- package/vest.js +7 -0
- package/vest.umd.development.js +2711 -0
- package/vest.umd.production.js +2708 -0
- package/vest.umd.production.min.js +1 -0
- package/vestResult.d.ts +105 -0
- package/CHANGELOG.md +0 -94
- package/LICENSE +0 -21
- package/classnames/index.js +0 -7
- package/classnames/package.json +0 -1
- package/dist/cjs/classnames.development.js +0 -67
- package/dist/cjs/classnames.production.js +0 -1
- package/dist/cjs/promisify.development.js +0 -20
- package/dist/cjs/promisify.production.js +0 -1
- package/dist/cjs/vest.development.js +0 -1616
- package/dist/cjs/vest.production.js +0 -1
- package/dist/es/classnames.development.js +0 -65
- package/dist/es/classnames.production.js +0 -1
- package/dist/es/promisify.development.js +0 -18
- package/dist/es/promisify.production.js +0 -1
- package/dist/es/vest.development.js +0 -1604
- package/dist/es/vest.production.js +0 -1
- package/dist/umd/classnames.development.js +0 -73
- package/dist/umd/classnames.production.js +0 -1
- package/dist/umd/promisify.development.js +0 -26
- package/dist/umd/vest.development.js +0 -1622
- package/dist/umd/vest.production.js +0 -1
- package/index.js +0 -7
- package/promisify/index.js +0 -7
- package/promisify/package.json +0 -1
- package/types/classnames.d.ts +0 -71
- package/types/classnames.d.ts.map +0 -1
- package/types/promisify.d.ts +0 -61
- package/types/promisify.d.ts.map +0 -1
- package/types/vest.d.ts +0 -271
- package/types/vest.d.ts.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";function e(e){return"function"==typeof e}function t(t,n){return e(t)?t.apply(null,n):t}function n(e){return[].concat(e)}function r(){return(r=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n,r=arguments[t];for(n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}var i=Object.assign;let u=function(e){function t(t,u){var s,o,a=n();return t=r({},a||{},null!==(s=null==e?void 0:e(t,a))&&void 0!==s?s:t),s=i.ctx=Object.freeze(t),i.ancestry.unshift(s),u=u(s),i.ancestry.shift(),i.ctx=null!==(o=i.ancestry[0])&&void 0!==o?o:null,u}function n(){return i.ctx}var i={ancestry:[]};return{run:t,bind:function(e,n){for(var r=arguments.length,i=Array(2<r?r-2:0),u=2;u<r;u++)i[u-2]=arguments[u];return function(){for(var r=arguments.length,u=Array(r),s=0;s<r;s++)u[s]=arguments[s];return t(e,(function(){return n.apply(void 0,i.concat(u))}))}},use:n}}(((e,t)=>t?null:i({},{exclusion:{tests:{},groups:{}}},e))),s=(o=0,()=>""+o++);var o;function a(e){return"function"==typeof e}function l(e){return function(){return!e.apply(this,arguments)}}function c(e){return null===e}let f=l(c);function d(e,t){return e.length===Number(t)}let p=l(d),h=(e=10)=>{const t=[],n=(r,i)=>{const u=n.get(r);return f(u)?u[1]:(i=i(),t.unshift([r.concat(),i]),t.length>e&&(t.length=e),i)};return n.get=e=>t[t.findIndex((([t])=>d(e,t.length)&&e.every(((e,n)=>e===t[n]))))]||null,n},g="warnings",m="errors",y=()=>u.use().stateRef;function b(){return y().carryOverTests()}function N(){return y().pending()}function v(){return y().suiteId()}function w(){return y().testCallbacks()}function F(){return y().testObjects()}function E(){return y().skippedTests()}function C(){return y().optionalFields()}let k=e=>{for(const t in e.tests)e.errorCount+=e.tests[t].errorCount,e.warnCount+=e.tests[t].warnCount,e.testCount+=e.tests[t].testCount;return e},O=(e,t,n)=>{const{fieldName:r,isWarning:i,failed:u,statement:s}=t;return e[r]=e[r]||{errorCount:0,warnCount:0,testCount:0},t=e[r],n||(e[r].testCount++,u&&(i?(e=g,t.warnCount++,s&&(t[e]=(t[e]||[]).concat(s))):(e=m,t.errorCount++,s&&(t[e]=(t[e]||[]).concat(s))))),t};function x(e,t){return e!==g&&t.isWarning||e===g&&!t.isWarning}let A=(e,t)=>{const[n]=F(),{group:r,fieldName:i}=t||{};return t=n.reduce(((t,n)=>(r&&n.groupName!==r||i&&n.fieldName!==i||!n.failed||x(e,n)||(t[n.fieldName]=(t[n.fieldName]||[]).concat(n.statement)),t)),{}),i?t[i]||[]:t};function T(e,t){return A(e,{fieldName:t})}let S=(e,t=Error)=>{throw new t(`[vest]: ${e}`)},j=(e,t,n)=>(t||S(`get${e[0].toUpperCase()}${e.slice(1)}ByGroup requires a group name. Received \`${t}\` instead.`),A(e,{group:t,fieldName:n})),W=(e,t,n)=>!(!e.failed||n&&n!==e.fieldName||x(t,e)),R=(e,t)=>{const[n]=F();return n.some((n=>W(n,e,t)))},q=(e,t,n)=>{const[r]=F();return r.some((r=>t===r.groupName&&W(r,e,n)))};function B(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function I(e){return!(isNaN(parseFloat(e))||isNaN(Number(e))||!isFinite(e))}let P=l(I);function K(e){if(e){if(I(e))return 0===e;if(B(e,"length"))return d(e,0);if("object"==typeof e)return d(Object.keys(e),0)}return!0}let $=l(K),G=e=>{const[{pending:t,lagging:n}]=N(),r=t.concat(n);return!K(r)&&(e?r.some((t=>t.fieldName===e)):$(r))},U="hasWarnings",z="hasErrors";function V(e,t){var n;return null!==(n=Object.getOwnPropertyDescriptor(e,"name"))&&void 0!==n&&n.configurable?Object.defineProperty(e,"name",{value:t}):e}function D(e,t){return V((function(){let t=Array.from(arguments),n=t.splice(e.length-1);return e.apply(null,t.concat([n]))}),t||e.name)}let M=h(20),H=e=>{const{stateRef:t}=u.use(),[n]=F(),r={stateRef:t};return M([n,e],u.bind(r,(()=>[[z,R,m],[U,R,g],["getErrors",T,m],["getWarnings",T,g],["hasErrorsByGroup",q,m],["hasWarningsByGroup",q,g],["getErrorsByGroup",j,m],["getWarningsByGroup",j,g]].concat([["isValid",L]],e?[]:[["done",D(J)]]).reduce(((e,[t,n,i])=>(e[t]=u.bind(r,n,i),e)),(()=>{function e(e,t){e.forEach((e=>{const{fieldName:n,groupName:r}=e;i.tests[n]=O(i.tests,e,t),r&&(i.groups[r]=i.groups[r]||{},i.groups[r][n]=O(i.groups[r],e,t))}))}const[t]=F(),[n]=v(),[r]=E(),i={errorCount:0,warnCount:0,testCount:0,groups:{},name:n.name,tests:{}};return e(t),e(r,!0),k(i)})()))))};function J(e){let[t,n]=e.reverse();var{stateRef:r}=u.use();e=H();let i=n&&(!e.tests[n]||0===e.tests[n].testCount);if(!a(t)||i)return e;let s=u.bind({stateRef:r},(()=>t(H(!0))));return!G()||n&&!G(n)?(s(),e):([,r]=w(),r((e=>(n?e.fieldCallbacks[n]=(e.fieldCallbacks[n]||[]).concat(s):e.doneCallbacks.push(s),e))),e)}function L(){let e=H();if(e.hasErrors())return!1;var[t]=F();if(0===t.length)return!1;[t]=C();let[{pending:n,lagging:r}]=N();if($(n.concat(r).filter((e=>!e.isWarning))))return!1;for(let n in e.tests)if(!t[n]&&0===e.tests[n].testCount)return!1;return!0}let Q=D((r=>{const[i,o]=r.reverse();a(i)||S("Suite initialization error. Expected `tests` to be a function.");const l=[],c=function(n){function r(e,n){return u.references.push(),i(e,t(n)),function(){return[u.references[e],function(n){return i(e,t(n,[u.references[e]]))}]}}function i(t,r){var i=u.references[t];u.references[t]=r,e(t=s[t][1])&&t(r,i),e(n)&&n()}var u={references:[]},s=[];return{registerStateKey:function(e,t){var n=s.length;return s.push([e,t]),r(n,e)},reset:function(){u.references=[],s.forEach((function(e,t){return r(t,e[0])}))}}}((()=>{l.forEach((e=>e({suiteState:f,type:"suiteStateUpdate"})))})),f=function(e,{suiteId:t,name:n}){return{carryOverTests:e.registerStateKey((()=>[])),optionalFields:e.registerStateKey((()=>({}))),pending:e.registerStateKey((()=>({pending:[],lagging:[]}))),skippedTests:e.registerStateKey((()=>[])),suiteId:e.registerStateKey((()=>({id:t,name:n}))),testCallbacks:e.registerStateKey((()=>({fieldCallbacks:{},doneCallbacks:[]}))),testObjects:e.registerStateKey((()=>[]))}}(c,{suiteId:s(),name:o});return(r=u.bind({stateRef:f},(function(){const[e]=F(),[,t]=b(),[{pending:n},r]=N();return c.reset(),t((()=>e)),r({lagging:n,pending:[]}),i.apply(null,arguments),H()}))).get=u.bind({stateRef:f},H,!0),r.reset=c.reset,r.remove=u.bind({stateRef:f},(e=>{const[t]=F();n(t).forEach((t=>{t.fieldName===e&&t.cancel()}))})),r.subscribe=function(e){a(e)&&(l.push(e),e({type:"suiteSubscribeInit",suiteState:f}))},r}));function X(e){i(this,e)}function Y(e){return!!e===e}X.prototype.setFailFast=function(e){return this.failFast=!!e,this},X.unwrap=function(e){return X.is(e)?e.value:e},X.wrap=function(e){return X.is(e)?e:new X({value:e})},X.is=function(e){return e instanceof X};let Z=l(Y);function _(e){return void 0===e}let ee=l(_);function te(e){_(e)||(Y(e)?this.setFailed(!e):this.extend(e))}function ne(e,t){let n=te.is(e),r=te.is(t);if(n&&r){if(e.setFailed(e.failed||t.failed),K(e.children)&&K(t.children))return e;if(e.children&&t.children){for(let n in e.children)ne(e.children[n],t.children[n]);for(let n in t.children)B(e.children,n)||e.setChild(n,t.children[n]);return e}if(e.children){if(!t.children)return e}else e.children=t.children}else{if(n)return e;if(r)return t}return new te(!1)}te.is=function(e){return e instanceof te},te.prototype.asArray=function(){return this.isArray=!0,this},te.prototype.setAttribute=function(e,t){return this[e]=t,this},te.prototype.setFailed=function(e){return this.setAttribute(this.warn?U:z,e),this.setAttribute("failed",e)},te.prototype.setChild=function(e,t){if(c(t))return null;let n=this[U]||t[U]||t.warn||this.warn;return this.setAttribute(U,n&&t.failed||!1),this.setAttribute(z,this[z]||t[z]||!n&&t.failed||!1),this.setFailed(this.failed||t.failed),this.children=this.children||{},this.children[e]=t},te.prototype.getChild=function(e){return(this.children||{})[e]},te.prototype.extend=function(e){if(c(e))return this;e=te.is(e)?e:(new te).setAttribute("warn",!!this.warn).setFailed(!e);let t=this.failed||e.failed,n=ne(e,this).children;i(this,e),K(n)||(this.children=n),this.setFailed(t),this.setAttribute(U,!(!this[U]&&!e[U])),this.setAttribute(z,!(!this[z]&&!e[z]))},Object.defineProperty(te.prototype,"pass",{get(){return!this.failed}});function re(e,t){return!t.pass&&!t.warn&&(!!X.is(e)&&e.failFast)}function ie(e,t){let r=new te(!0);for(let i of n(e)){if(re(t,r))break;r.extend(ue(i,t))}return r}function ue(e,t){return e.run(t)}function se(e,t,n){let r=new te(!0);K(t)&&r.setFailed(!0);let i=[],u=0;for(let s of t){if(c(t=ue(s,e)))return null;let o=t.pass;if(o?u++:i.push(t),n)if("any"===n.mode){if(o){r.extend(t);break}}else{if(r.extend(t),"all"===n.mode&&!o)break;if("one"===n.mode&&(r.setFailed(1!==u),1<u))break}else if(r.extend(t),o)break}return r.pass&&0===u&&(r.setFailed(!0),i.forEach((e=>r.extend(e)))),r}var oe=D((function(e,t){return se(e,t,{mode:"all"})}));var ae=D((function(e,t){return se(e,t,{mode:"any"})}));function le(e){return!!Array.isArray(e)}let ce=l(le);function fe(e,t,n){let r=X.unwrap(e),i=new te(!0);for(let n in t){let u=t[n],s=r[n];if(re(s,i))break;i.setChild(n,ue(u,new X({value:s,obj:r,key:n}).setFailFast(e.failFast)))}if(!(n||{}).loose)for(let e in r)if(!B(t,e))return i.setFailed(!0);return i}var de={allOf:oe,anyOf:ae,isArrayOf:D((function(e,t){let n=X.unwrap(e),r=new te(!0).asArray();if(ce(n))return r.setFailed(!0);for(let i=0;i<n.length;i++)r.setChild(i,se(new X({value:n[i],obj:n,key:i}).setFailFast(e.failFast),t,{mode:"any"}));return r})),loose:(e,t)=>fe(e,t,{loose:!0}),oneOf:D((function(e,t){return se(e,t,{mode:"one"})})),optional:D((function(e,t){let{obj:n,key:r}=e;return!(B(n,r)&&!_(n[r]||c(n[r]))&&!K(t))||se(n[r],t,{mode:"all"})})),shape:fe};function pe(e,t){return a(e)?e.apply(null,t):e}var he={warn:function(e,t=!0){return t},message:function(e,t){return pe(t,[X.unwrap(e)])},when:function(e,t,n){return n(e=!pe(t,[X.unwrap(e)].concat(X.is(e)?[e.key,e.obj]:[])))}};function ge(e){return String(e)===e}function me(e,t){return ge(e)&&ge(t)&&e.endsWith(t)}let ye=l(me);function be(e,t){return e===t}let Ne=l(be);function ve(e,t){return I(e)&&I(t)&&Number(e)>Number(t)}function we(e,t){return I(e)&&I(t)&&Number(e)>=Number(t)}function Fe(e,t){return!!(Array.isArray(t)&&/^[s|n|b]/.test(typeof e)||ge(t)&&ge(e))&&-1!==t.indexOf(e)}let Ee=l(Fe);function Ce(e,t){return I(e)&&I(t)&&Number(e)<=Number(t)}function ke(e,t,n){return we(e,t)&&Ce(e,n)}let Oe=l(ke);function xe(e){return"string"==typeof e&&""===e.trim()}let Ae=l(xe),Te=e=>!!I(e)&&0==e%2;function Se(e){return Number.isNaN(e)}let je=l(Se);function We(e){return!!I(e)&&0>Number(e)}let Re=l(We);function qe(e){return"number"==typeof e}let Be=l(qe),Ie=e=>!!I(e)&&0!=e%2,Pe=l(ge);function Ke(e){return!!e}let $e=l(Ke);function Ge(e,t){return I(e)&&I(t)&&Number(e)<Number(t)}function Ue(e,t){return e.length>Number(t)}function ze(e,t){return e.length>=Number(t)}function Ve(e,t){return t instanceof RegExp?t.test(e):!!ge(t)&&new RegExp(t).test(e)}let De=l(Ve);function Me(e,t){return I(e)&&I(t)&&Number(e)===Number(t)}let He=l(Me);function Je(e,t){return e.length<Number(t)}function Le(e,t){return e.length<=Number(t)}function Qe(e,t){return ge(e)&&ge(t)&&e.startsWith(t)}let Xe=l(Qe);var Ye=i({doesNotEndWith:ye,doesNotStartWith:Xe,endsWith:me,equals:be,greaterThan:ve,greaterThanOrEquals:we,gt:ve,gte:we,inside:Fe,isArray:le,isBetween:ke,isBoolean:Y,isBlank:xe,isEmpty:K,isEven:Te,isFalsy:$e,isNaN:Se,isNegative:We,isNotArray:ce,isNotBetween:Oe,isNotBlank:Ae,isNotBoolean:Z,isNotEmpty:$,isNotNaN:je,isNotNull:f,isNotNumber:Be,isNotNumeric:P,isNotString:Pe,isNotUndefined:ee,isNull:c,isNumber:qe,isNumeric:I,isOdd:Ie,isPositive:Re,isString:ge,isTruthy:Ke,isUndefined:_,lengthEquals:d,lengthNotEquals:p,lessThan:Ge,lessThanOrEquals:Ce,longerThan:Ue,longerThanOrEquals:ze,lt:Ge,lte:Ce,matches:Ve,notEquals:Ne,notInside:Ee,notMatches:De,numberEquals:Me,numberNotEquals:He,shorterThan:Je,shorterThanOrEquals:Le,startsWith:Qe},de,he);let Ze=Function("return this")(),_e=()=>a(Ze.Proxy);function et(e,t){if(_e())return new Proxy(e,{get:(e,n)=>B(e,n)?e[n]:(e=>B(Ye,e)&&a(Ye[e]))(n)?t(n):e[n]});for(let n in Ye)a(e[n])||Object.defineProperties(e,{[n]:{get:()=>t(n)}});return e}function tt(e){return B(de,e.name)}function nt(e){let t=[],n=[],r=e=>D((i=>{const u=Ye[e];he[u.name]===u?n.push(((e,t,n)=>{t.setAttribute(u.name,u(e,i[0],n))})):t.push(V((e=>u.apply(null,[tt(u)?X.wrap(e):X.unwrap(e)].concat(i))),e));const s=et({},r);return s.run=e=>{const r=new te(!0);let i=!1;if(n.forEach((t=>{t(e,r,(e=>i=e))})),i)return null;for(const n of t)try{if(r.extend(n(e)),!r.pass)break}catch(e){r.setFailed(!0);break}return r},s.test=e=>s.run(X.wrap(e).setFailFast(!0)).pass,s}),e);return r(e)}function rt(e,{rule:t,value:n}){return n=function(e){return{message:Error(`invalid ${typeof e} value`)}}(n),function(e,t){Y(e)||e&&Y(e.pass)||S(t.name+"wrong return value")}(e,t),Y(e)?(n.pass=e,n):(n.pass=e.pass,e.message&&(n.message=pe(e.message)),n)}function it(e,t,n=[]){let r=tt(e),i=r?X.wrap(t).setFailFast(!0):X.unwrap(t);if(n=e.apply(null,[i].concat(n)),r||(n=rt(n,{rule:e,value:t})),!n.pass)throw n.message}let ut=e=>{const t=et({},(n=>D((r=>(it(Ye[n],e,r),t)))));return t},st=et(ut,nt);!function(e,t){e.extend=n=>(i(Ye,n),_e()||et(t,nt),e)}(st,ut),function(e){e.template=D((e=>{let t=t=>{it(ie.bind(null,e),t);const n=et({},(e=>D((r=>(it(Ye[e],t,r),n)))));return n};return t.run=t=>ie(e,t),t.test=t=>ie(e,X.wrap(t).setFailFast(!0)).pass,t}))}(st);function ot(e){return dt(ct,"tests",e)}function at(e){return dt(ft,"tests",e)}function lt(e){let{fieldName:t,groupName:n}=e;({exclusion:e}=u.use());let r=e.tests;var i=r[t];if(!1===i)return!0;if(i=!0===i,n){if(function(e){var{exclusion:t}=u.use();if(B(t=t.groups,e))return!1===t[e];for(let e in t)if(!0===t[e])return!0;return!1}(n))return!0;if(!0===e.groups[n])return!i&&(!!pt(r)||!1===r[t])}return!i&&pt(r)}ot.group=e=>dt(ct,"groups",e),at.group=e=>dt(ft,"groups",e);let ct="only",ft="skip",dt=(e,t,r)=>{const i=u.use();r&&(i?n(r).forEach((n=>{if(!ge(n))return null;i.exclusion[t][n]=e===ct})):S(`${e} hook called outside of a running suite.`))},pt=e=>{for(const t in e)if(!0===e[t])return!0;return!1};let ht=()=>S("group initialization error. Incompatible argument passed to group.");function gt(e,t){return e.fieldName===t.fieldName&&e.groupName===t.groupName}let mt=(e,t)=>(-1!==(t=e.indexOf(t))&&e.splice(t,1),e),yt=e=>{const[t,r]=N(),i=n(t.lagging).reduce(((t,n)=>(gt(e,n)&&n.id!==e.id?n.cancel():t.push(n),t)),[]);r((t=>({lagging:i,pending:t.pending.concat(e)})))},bt=e=>{const[,t]=N();t((t=>({pending:mt(t.pending,e),lagging:mt(t.lagging,e)})))};function Nt({fieldName:e,statement:t,testFn:r,group:i}){let u={cancel:function(){u.canceled=!0,bt(this),(e=>{let[,t]=F();t((t=>n(mt(t,e))))})(this)},fail:function(){u.failed=!0},failed:!1,fieldName:e,id:s(),isWarning:!1,statement:t,testFn:r,valueOf:function(){return!0!==u.failed},warn:function(){u.isWarning=!0}};return i&&(u.groupName=i),u}var vt=e=>{let[,t]=F();t((t=>t.concat(e)))};function wt(e){return e&&a(e.then)}function Ft(e){return e.forEach((e=>e()))}let Et=e=>{const{asyncTest:t,statement:n}=e;var{stateRef:r}=u.use();const i=u.bind({stateRef:r},(()=>{bt(e),e.canceled||Ct(e.fieldName)}));r=u.bind({stateRef:r},(t=>{e.statement=ge(t)?t:n,e.fail(),[,t]=F(),t((e=>e.slice())),i()}));try{t.then(i,r)}catch(e){r()}},Ct=e=>{const[{fieldCallbacks:t,doneCallbacks:n}]=w();e&&!G(e)&&Array.isArray(t[e])&&Ft(t[e]),G()||Ft(n)};function kt(e){vt(e);let t=function(e){return u.run({currentTest:e},(()=>{let t;try{t=e.testFn()}catch(n){_(e.statement)&&ge(n)&&(e.statement=n),t=!1}return!1===t&&e.fail(),t}))}(e);try{wt(t)&&(e.asyncTest=t,yt(e),Et(e))}catch(e){}}let Ot=D((function(e,t){const[n,r]=t.reverse();[,t]=E();const{groupName:i}=u.use(),s=Nt({fieldName:e,group:i,statement:r,testFn:n});return lt(s)?(t((e=>e.concat(s))),function(e){let[t,n]=b(),[,r]=F(),[i,u]=function(e,t){return e.reduce(((n,r,i)=>(n[t(r,i,e)?0:1].push(r),n)),[[],[]])}(t,(t=>gt(t,e)));n((()=>u)),r((e=>e.concat(i)))}(s),s):a(n)?(kt(s),s):s}));!function(e){e.each=function(t){return Array.isArray(t)||S("test.each: Expected table to be an array."),D(((r,i)=>{let[u,s]=i.reverse();return t.map((t=>(t=n(t),e(pe(r,t),pe(s,t),(()=>u.apply(null,t))))))}))}}(Ot),function(e){let t=h(100);e.memo=D((function(n,r){var[i]=v();let[u,s,o]=r.reverse();return r=[i.id,n].concat(u),c(i=t.get(r))?t(r,e.bind(null,n,o,s)):([,n]=i,lt(n)||(vt(n),n&&wt(n.asyncTest)&&(yt(n),Et(n))),n)}))}(Ot);var xt={VERSION:"3.2.8",create:Q,enforce:st,group:(e,t)=>{ge(e)||ht(),a(t)||ht(),u.bind({groupName:e},t)()},only:ot,optional:function(e){let[,t]=C();t((t=>(n(e).forEach((e=>{t[e]=!0})),t)))},skip:at,skipWhen:function(e,t){$e(pe(e))&&a(t)&&t()},test:Ot,warn:()=>{const e=u.use();e?e.currentTest?e.currentTest.warn():S("warn called outside of a test."):S("warn hook called outside of a running suite.")}};module.exports=xt;
|
package/vest.d.ts
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { TEnforce } from './enforce';
|
|
2
|
+
import { IVestResult, DraftResult } from './vestResult';
|
|
3
|
+
|
|
4
|
+
type TestCB = () => void | Promise<void | string> | false;
|
|
5
|
+
type TestArgsCB = (...args: any[]) => void | Promise<void | string> | false;
|
|
6
|
+
type MessageFunc = (...args: any[]) => string;
|
|
7
|
+
type ExclusionArg = string | string[] | void;
|
|
8
|
+
|
|
9
|
+
export = vest;
|
|
10
|
+
export as namespace vest;
|
|
11
|
+
|
|
12
|
+
interface VestTest {
|
|
13
|
+
failed: boolean;
|
|
14
|
+
fieldName: string;
|
|
15
|
+
id: string;
|
|
16
|
+
isWarning: boolean;
|
|
17
|
+
statement: string;
|
|
18
|
+
testFn: TestCB;
|
|
19
|
+
asyncTest?: Promise<void | string>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface ITestEach {
|
|
23
|
+
/**
|
|
24
|
+
* Run multiple tests using a parameter table
|
|
25
|
+
* @param {String} fieldName Name of the field to test.
|
|
26
|
+
* @param {String|function} message The message returned in case of a failure. Follows printf syntax.
|
|
27
|
+
* @param {function} testFn The actual test callback.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
*
|
|
31
|
+
* test.each([[1,2,3],[2,1,3]])('test', (a, b, c) => `${a} + ${b} does not equal ${c}`, (a, b, c) => enforce(a + b).equals(c));
|
|
32
|
+
*/
|
|
33
|
+
(
|
|
34
|
+
fieldName: string | MessageFunc,
|
|
35
|
+
message: string | MessageFunc,
|
|
36
|
+
testFn: TestArgsCB
|
|
37
|
+
): VestTest[];
|
|
38
|
+
/**
|
|
39
|
+
* Run multiple tests using a parameter table
|
|
40
|
+
* @param {String} fieldName Name of the field to test.
|
|
41
|
+
* @param {function} testFn The actual test callback.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
*
|
|
45
|
+
* test.each([[1,2,3],[2,1,3]])('test', (a, b, c) => enforce(a + b).equals(c));
|
|
46
|
+
*/
|
|
47
|
+
(fieldName: string | MessageFunc, testFn: TestArgsCB): VestTest[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface ITest {
|
|
51
|
+
/**
|
|
52
|
+
* Runs a single test
|
|
53
|
+
* @param fieldName The name of the field being validated
|
|
54
|
+
* @param message Descriptive message to display on failure
|
|
55
|
+
* @param testFn Test body
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
*
|
|
59
|
+
* test('username', 'Username is required', () => {
|
|
60
|
+
* enforce(username).isNotEmpty();
|
|
61
|
+
* });
|
|
62
|
+
*/
|
|
63
|
+
(fieldName: string, message: string, testFn: TestCB): VestTest;
|
|
64
|
+
/**
|
|
65
|
+
* Runs a single test
|
|
66
|
+
* @param fieldName The name of the field being validated
|
|
67
|
+
* @param testFn Test body
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
*
|
|
71
|
+
* test('username', () => {
|
|
72
|
+
* enforce(username).isNotEmpty();
|
|
73
|
+
* });
|
|
74
|
+
*/
|
|
75
|
+
(fieldName: string, testFn: TestCB): VestTest;
|
|
76
|
+
/**
|
|
77
|
+
* Runs a single test. Memoizes the result based on the dependency array.
|
|
78
|
+
* @param fieldName The name of the field being validated
|
|
79
|
+
* @param message Descriptive message to display on failure
|
|
80
|
+
* @param testFn Test body
|
|
81
|
+
* @param dependencies An array of values to be checked for strict equality ('===')
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
*
|
|
85
|
+
* test.memo('username', 'Username already exists', () => doesUserExist(username), [username])
|
|
86
|
+
*/
|
|
87
|
+
memo(
|
|
88
|
+
fieldName: string,
|
|
89
|
+
message: string,
|
|
90
|
+
testFn: TestCB,
|
|
91
|
+
dependencies: any[]
|
|
92
|
+
): VestTest;
|
|
93
|
+
/**
|
|
94
|
+
* Runs a single test. Memoizes the result based on the dependency array.
|
|
95
|
+
* @param fieldName The name of the field being validated
|
|
96
|
+
* @param testFn Test body
|
|
97
|
+
* @param dependencies An array of values to be checked for strict equality ('===')
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
*
|
|
101
|
+
* test.memo('username', () => doesUserExist(username), [username])
|
|
102
|
+
*/
|
|
103
|
+
memo(fieldName: string, testFn: TestCB, dependencies: any[]): VestTest;
|
|
104
|
+
/**
|
|
105
|
+
* Create test.each with table of parameters
|
|
106
|
+
* @param {any[]} table Array of arrays with params for each run, although it
|
|
107
|
+
* will accept 1d-array and treat every item as size one array (e.g. [1,2,3] -> [[1],[2],[3]])
|
|
108
|
+
* @example
|
|
109
|
+
*
|
|
110
|
+
* test.each([[1,2,3],[2,1,3]])('test', 'failed', (a, b, c) => enforce(a + b).equals(c));
|
|
111
|
+
*/
|
|
112
|
+
each(table: any[]): ITestEach;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
interface ISkip {
|
|
116
|
+
/**
|
|
117
|
+
* Skips provided field from current run.
|
|
118
|
+
* When undefined, the expression is ignored.
|
|
119
|
+
* @param [fieldName] Field name or a list of fields to exclude
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
*
|
|
123
|
+
* vest.skip('username');
|
|
124
|
+
* vest.skip(['username', 'password']);
|
|
125
|
+
*/
|
|
126
|
+
(fieldNames?: ExclusionArg): void;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Skips provided group from current run.
|
|
130
|
+
* When undefined, the expression is ignored.
|
|
131
|
+
* @param [groupName] group name or a list of group to exclude
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
*
|
|
135
|
+
* vest.skip.group('section_1');
|
|
136
|
+
* vest.skip.group(['section_1', 'section_2']);
|
|
137
|
+
*/
|
|
138
|
+
group(groupName?: ExclusionArg): void;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
interface IOnly {
|
|
142
|
+
/**
|
|
143
|
+
* Singles out a field name to be tested.
|
|
144
|
+
* When fieldName is undefined, the expression is ignored.
|
|
145
|
+
* @param [fieldName] Field name or a list of fields to include
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
*
|
|
149
|
+
* vest.only('username');
|
|
150
|
+
* vest.only(['username', 'password']);
|
|
151
|
+
*/
|
|
152
|
+
(fieldName?: ExclusionArg): void;
|
|
153
|
+
/**
|
|
154
|
+
* Singles out a group name to be tested.
|
|
155
|
+
* When groupName is undefined, the expression is ignored.
|
|
156
|
+
* @param [groupName] Field name or a list of groups to include.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
*
|
|
160
|
+
* vest.only.group('section_1');
|
|
161
|
+
* vest.only.group(['section_1', 'section_2']);
|
|
162
|
+
*/
|
|
163
|
+
group(groupName?: ExclusionArg): void;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
interface ISubscribePayload {
|
|
167
|
+
type: string;
|
|
168
|
+
suiteState: Record<string, any>;
|
|
169
|
+
key?: string;
|
|
170
|
+
value?: any;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
interface ICreateResult {
|
|
174
|
+
(...args: any[]): IVestResult;
|
|
175
|
+
get: () => DraftResult;
|
|
176
|
+
reset: () => void;
|
|
177
|
+
remove: (fieldName: string) => void;
|
|
178
|
+
|
|
179
|
+
subscribe: (payload: ISubscribePayload) => void;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
interface ISkipWhen {
|
|
183
|
+
(conditional: boolean | (() => boolean), callback: () => void): void;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
declare namespace vest {
|
|
187
|
+
const enforce: TEnforce;
|
|
188
|
+
const test: ITest;
|
|
189
|
+
const only: IOnly;
|
|
190
|
+
const skip: ISkip;
|
|
191
|
+
const skipWhen: ISkipWhen;
|
|
192
|
+
|
|
193
|
+
function optional(optionalFields: string | string[]): boolean;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Runs a stateful validation suite.
|
|
197
|
+
* @param [suiteName] Unique suite name.
|
|
198
|
+
* @param tests Suite body.
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
*
|
|
202
|
+
* const validate = vest.create('form_name', (data = {}) => {
|
|
203
|
+
* // your tests go here
|
|
204
|
+
* });
|
|
205
|
+
*
|
|
206
|
+
* const res = validate({username: 'example'});
|
|
207
|
+
*/
|
|
208
|
+
function create(
|
|
209
|
+
suiteName: string,
|
|
210
|
+
tests: (...args: any[]) => void
|
|
211
|
+
): ICreateResult;
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Runs a stateful validation suite.
|
|
215
|
+
* @param tests Suite body.
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
*
|
|
219
|
+
* const validate = vest.create((data = {}) => {
|
|
220
|
+
* // your tests go here
|
|
221
|
+
* });
|
|
222
|
+
*
|
|
223
|
+
* const res = validate({username: 'example'});
|
|
224
|
+
*/
|
|
225
|
+
function create(tests: (...args: any[]) => void): ICreateResult;
|
|
226
|
+
/**
|
|
227
|
+
* Allows grouping tests so you can handle them together
|
|
228
|
+
* @param groupName Group name.
|
|
229
|
+
* @param testFn Group body.
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
*
|
|
233
|
+
* group('sign_up', () => {
|
|
234
|
+
* // your tests go here
|
|
235
|
+
* });
|
|
236
|
+
*/
|
|
237
|
+
function group(groupName: string, testFn: () => void): void;
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Marks a test as warning.
|
|
241
|
+
* Needs to run within a test body.
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
*
|
|
245
|
+
* test('password', 'Consider using a longer password.', () => {
|
|
246
|
+
* vest.warn();
|
|
247
|
+
*
|
|
248
|
+
* enforce(password).longerThan(10);
|
|
249
|
+
* });
|
|
250
|
+
*/
|
|
251
|
+
function warn(): void;
|
|
252
|
+
|
|
253
|
+
const VERSION: string;
|
|
254
|
+
}
|