vuito
Version:
Simple, lightweight, isomorphic, and template-based validation library.
3 lines (2 loc) • 1.62 kB
JavaScript
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((n="undefined"!=typeof globalThis?globalThis:n||self).vuito={})}(this,(function(n){"use strict";function e(n,e,t,r){return new(t||(t=Promise))((function(o,i){function c(n){try{f(r.next(n))}catch(n){i(n)}}function u(n){try{f(r.throw(n))}catch(n){i(n)}}function f(n){var e;n.done?o(n.value):(e=n.value,e instanceof t?e:new t((function(n){n(e)}))).then(c,u)}f((r=r.apply(n,e||[])).next())}))}function t(n){return(e,t)=>new Promise(((r,o)=>{for(const{message:r,test:i,onlyIf:c}of n)c&&t&&!c(t)||(e&&"string"==typeof e&&(e=e.trim()),i(e)||o(r));r()}))}"function"==typeof SuppressedError&&SuppressedError,n.maxLength=function(n){return e=>!e||e.length<=n},n.maxValue=function(n){return e=>parseInt(e,10)<=n},n.minLength=function(n){return e=>!e||n<=e.length},n.minValue=function(n){return e=>n<=parseInt(e,10)},n.onlyText=function(n){const e=/^[a-z0-9 ]+$/i;return String.prototype.normalize?!n||e.test(n.normalize("NFD").replace(/[\u0300-\u036f]/g,"")):!n||e.test(n)},n.regex=function(n){return e=>new RegExp(n).test((e||"").trim())},n.required=function(n){return!!n},n.templateify=function(n){const r=function(n){return Object.fromEntries(Object.entries(n).map((([n,e])=>[n,Object.assign(Object.assign({},e),{check:t(e)})])))}(n);return Object.assign(Object.assign({},r),{check:(o=r,function(n){return new Promise(((t,r)=>e(this,void 0,void 0,(function*(){for(const[e,t]of Object.entries(o))yield t.check(n[e],n).catch(r);t()}))))})});var o}}));
//# sourceMappingURL=vuito.umd.js.map