@lemoncode/fonk
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -1463,2 +1463,7 @@ 'use strict'; | ||
} | ||
}, { | ||
key: "updateValidationSchema", | ||
value: function updateValidationSchema(validationSchema) { | ||
this.setupValidationSchema(validationSchema); | ||
} | ||
}]); | ||
@@ -1714,12 +1719,3 @@ | ||
var FormValidationExtended = { | ||
validateField: validateField, | ||
validateRecord: validateRecord, | ||
validateForm: validateForm, | ||
mapToInternalFieldValidationSchema: mapToInternalFieldValidationSchema, | ||
mapToInternalRecordValidationSchema: mapToInternalRecordValidationSchema, | ||
FormValidation: FormValidation | ||
}; | ||
exports.FormValidationExtended = FormValidationExtended; | ||
exports.FormValidation = FormValidation; | ||
exports.Validators = index; | ||
@@ -1726,0 +1722,0 @@ exports.createDefaultFormValidationResult = createDefaultFormValidationResult; |
@@ -1459,2 +1459,7 @@ function _typeof(obj) { | ||
} | ||
}, { | ||
key: "updateValidationSchema", | ||
value: function updateValidationSchema(validationSchema) { | ||
this.setupValidationSchema(validationSchema); | ||
} | ||
}]); | ||
@@ -1710,11 +1715,2 @@ | ||
var FormValidationExtended = { | ||
validateField: validateField, | ||
validateRecord: validateRecord, | ||
validateForm: validateForm, | ||
mapToInternalFieldValidationSchema: mapToInternalFieldValidationSchema, | ||
mapToInternalRecordValidationSchema: mapToInternalRecordValidationSchema, | ||
FormValidation: FormValidation | ||
}; | ||
export { FormValidationExtended, index as Validators, createDefaultFormValidationResult, createDefaultRecordValidationResult, createDefaultValidationResult, createFormValidation, parseMessageWithCustomArgs }; | ||
export { FormValidation, index as Validators, createDefaultFormValidationResult, createDefaultRecordValidationResult, createDefaultValidationResult, createFormValidation, parseMessageWithCustomArgs }; |
@@ -1465,2 +1465,7 @@ (function (global, factory) { | ||
} | ||
}, { | ||
key: "updateValidationSchema", | ||
value: function updateValidationSchema(validationSchema) { | ||
this.setupValidationSchema(validationSchema); | ||
} | ||
}]); | ||
@@ -1716,12 +1721,3 @@ | ||
var FormValidationExtended = { | ||
validateField: validateField, | ||
validateRecord: validateRecord, | ||
validateForm: validateForm, | ||
mapToInternalFieldValidationSchema: mapToInternalFieldValidationSchema, | ||
mapToInternalRecordValidationSchema: mapToInternalRecordValidationSchema, | ||
FormValidation: FormValidation | ||
}; | ||
exports.FormValidationExtended = FormValidationExtended; | ||
exports.FormValidation = FormValidation; | ||
exports.Validators = index; | ||
@@ -1728,0 +1724,0 @@ exports.createDefaultFormValidationResult = createDefaultFormValidationResult; |
@@ -15,2 +15,2 @@ !function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e=e||self)["@lemoncode/fonk"]={})}(this,(function(e){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function t(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function n(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){if(!(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)))return;var t=[],n=!0,o=!1,u=void 0;try{for(var i,a=e[Symbol.iterator]();!(n=(i=a.next()).done)&&(t.push(i.value),!r||t.length!==r);n=!0);}catch(e){o=!0,u=e}finally{try{n||null==a.return||a.return()}finally{if(o)throw u}}return t}(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")} | ||
and limitations under the License. | ||
***************************************************************************** */()}function o(e,r){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)r.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(t[n[o]]=e[n[o]])}return t}var u=function(e){return function(e){return Array.isArray(e)?e.length:0}(e)>0},i=function(e){return"function"==typeof e},a=function(e){return null==e},c=function(e){return e instanceof Promise},s=function(e){return Boolean(e)?Object.keys(e):[]},l="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},f="Expected a function",d="__lodash_hash_undefined__",p=1/0,v="[object Function]",h="[object GeneratorFunction]",m="[object Symbol]",y=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,g=/^\w*$/,_=/^\./,b=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,E=/\\(\\)?/g,j=/^\[object .+?Constructor\]$/,w="object"==r(l)&&l&&l.Object===Object&&l,O="object"==("undefined"==typeof self?"undefined":r(self))&&self&&self.Object===Object&&self,A=w||O||Function("return this")();var S,P=Array.prototype,x=Function.prototype,k=Object.prototype,V=A["__core-js_shared__"],F=(S=/[^.]+$/.exec(V&&V.keys&&V.keys.IE_PROTO||""))?"Symbol(src)_1."+S:"",R=x.toString,T=k.hasOwnProperty,M=k.toString,$=RegExp("^"+R.call(T).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),N=A.Symbol,I=P.splice,z=W(A,"Map"),L=W(Object,"create"),C=N?N.prototype:void 0,D=C?C.toString:void 0;function G(e){var r=-1,t=e?e.length:0;for(this.clear();++r<t;){var n=e[r];this.set(n[0],n[1])}}function U(e){var r=-1,t=e?e.length:0;for(this.clear();++r<t;){var n=e[r];this.set(n[0],n[1])}}function B(e){var r=-1,t=e?e.length:0;for(this.clear();++r<t;){var n=e[r];this.set(n[0],n[1])}}function H(e,r){for(var t,n,o=e.length;o--;)if((t=e[o][0])===(n=r)||t!=t&&n!=n)return o;return-1}function Z(e,t){for(var n,o=0,u=(t=function(e,t){if(Y(e))return!1;var n=r(e);if("number"==n||"symbol"==n||"boolean"==n||null==e||re(e))return!0;return g.test(e)||!y.test(e)||null!=t&&e in Object(t)}(t,e)?[t]:Y(n=t)?n:X(n)).length;null!=e&&o<u;)e=e[J(t[o++])];return o&&o==u?e:void 0}function q(e){return!(!ee(e)||(r=e,F&&F in r))&&(function(e){var r=ee(e)?M.call(e):"";return r==v||r==h}(e)||function(e){var r=!1;if(null!=e&&"function"!=typeof e.toString)try{r=!!(e+"")}catch(e){}return r}(e)?$:j).test(function(e){if(null!=e){try{return R.call(e)}catch(e){}try{return e+""}catch(e){}}return""}(e));var r}function Q(e,t){var n,o,u=e.__data__;return("string"==(o=r(n=t))||"number"==o||"symbol"==o||"boolean"==o?"__proto__"!==n:null===n)?u["string"==typeof t?"string":"hash"]:u.map}function W(e,r){var t=function(e,r){return null==e?void 0:e[r]}(e,r);return q(t)?t:void 0}G.prototype.clear=function(){this.__data__=L?L(null):{}},G.prototype.delete=function(e){return this.has(e)&&delete this.__data__[e]},G.prototype.get=function(e){var r=this.__data__;if(L){var t=r[e];return t===d?void 0:t}return T.call(r,e)?r[e]:void 0},G.prototype.has=function(e){var r=this.__data__;return L?void 0!==r[e]:T.call(r,e)},G.prototype.set=function(e,r){return this.__data__[e]=L&&void 0===r?d:r,this},U.prototype.clear=function(){this.__data__=[]},U.prototype.delete=function(e){var r=this.__data__,t=H(r,e);return!(t<0)&&(t==r.length-1?r.pop():I.call(r,t,1),!0)},U.prototype.get=function(e){var r=this.__data__,t=H(r,e);return t<0?void 0:r[t][1]},U.prototype.has=function(e){return H(this.__data__,e)>-1},U.prototype.set=function(e,r){var t=this.__data__,n=H(t,e);return n<0?t.push([e,r]):t[n][1]=r,this},B.prototype.clear=function(){this.__data__={hash:new G,map:new(z||U),string:new G}},B.prototype.delete=function(e){return Q(this,e).delete(e)},B.prototype.get=function(e){return Q(this,e).get(e)},B.prototype.has=function(e){return Q(this,e).has(e)},B.prototype.set=function(e,r){return Q(this,e).set(e,r),this};var X=K((function(e){var r;e=null==(r=e)?"":function(e){if("string"==typeof e)return e;if(re(e))return D?D.call(e):"";var r=e+"";return"0"==r&&1/e==-p?"-0":r}(r);var t=[];return _.test(e)&&t.push(""),e.replace(b,(function(e,r,n,o){t.push(n?o.replace(E,"$1"):r||e)})),t}));function J(e){if("string"==typeof e||re(e))return e;var r=e+"";return"0"==r&&1/e==-p?"-0":r}function K(e,r){if("function"!=typeof e||r&&"function"!=typeof r)throw new TypeError(f);var t=function t(){var n=arguments,o=r?r.apply(this,n):n[0],u=t.cache;if(u.has(o))return u.get(o);var i=e.apply(this,n);return t.cache=u.set(o,i),i};return t.cache=new(K.Cache||B),t}K.Cache=B;var Y=Array.isArray;function ee(e){var t=r(e);return!!e&&("object"==t||"function"==t)}function re(e){return"symbol"==r(e)||function(e){return!!e&&"object"==r(e)}(e)&&M.call(e)==m}var te=function(e,r,t){var n=null==e?void 0:Z(e,r);return void 0===n?t:n},ne=function(){return{type:"",succeeded:!0,message:""}},oe=function(){return{succeeded:!0,recordErrors:{}}},ue=function(){return{succeeded:!0,fieldErrors:{},recordErrors:{}}},ie=function(e){return function(r){var t=e?e(r):{type:"",succeeded:!0,message:""};return c(t)?t:Promise.resolve(t)}},ae=function(e){return function(r){var t=e?e(r):{type:"",succeeded:!0,message:""};return c(t)?t:Promise.resolve(t)}},ce=function(e){return i(e)?{validator:ie(e),message:void 0,customArgs:void 0}:{validator:ie(e.validator),customArgs:e.customArgs,message:e.message}},se=function(e){return Array.isArray(e)?e.map(ce):[]},le=function(e){var r=e instanceof Object?e:{},t=Object.entries(r).map((function(e){var r=n(e,2),t=r[0],o=r[1];return[t,se(o)]}));return t.reduce((function(e,r){var t=n(r,2),o=t[0],u=t[1];return e[o]=u,e}),{})},fe=function(e){return i(e)?{validator:ae(e),message:void 0}:{validator:ae(e.validator),message:e.message}},de=function(e){return Array.isArray(e)?e.map(fe):[]},pe=function(e){var r=e instanceof Object?e:{},t=Object.entries(r).map((function(e){var r=n(e,2),t=r[0],o=r[1];return[t,de(o)]}));return t.reduce((function(e,r){var t=n(r,2),o=t[0],u=t[1];return e[o]=u,e}),{})},ve=function(e,r,t,n){return e.map((function(e){return n(e,r,t)}))},he=function(e){var r=e;return e&&!a(e.succeeded)||(console.error("form-validators: One of the record validator is returning a non expected value."),r={key:"",type:"",succeeded:!0,message:""}),r},me=function(e,r){return r.validator({values:e,message:r.message}).then(he)},ye=function(e,r){return u(r)?function(e,r){return r.reduce((function(r,t){return r.then((function(r){return r.succeeded?me(e,t):r}))}),me(e,r[0]))}(e,r):Promise.resolve({key:"",type:"",succeeded:!0,message:""})},ge=function(e){var r=e;return e&&!a(e.succeeded)||(console.error("form-validators: One of the field validator is returning a non expected value."),r={key:"",type:"",succeeded:!0,message:""}),r},_e=function(e,r,t){return t.validator({value:e,values:r,customArgs:t.customArgs,message:t.message}).then(ge)},be=function(e,r,t){return u(t)?function(e,r,t){return t.reduce((function(t,n){return t.then((function(t){return t.succeeded?_e(e,r,n):t}))}),_e(e,r,t[0]))}(e,r,t):Promise.resolve({key:"",type:"",succeeded:!0,message:""})},Ee=function(e){return e.every((function(e){return e.succeeded}))},je=function(e){return e.reduce((function(e,r){var t=r.key,n=o(r,["key"]);return e[t]=Object.assign({},n),e}),{})},we=function(e){var r={succeeded:!0,recordErrors:{}};return u(e)&&(r.succeeded=Ee(e),r.recordErrors=je(e)),r},Oe=function(e,r){return!a(r)&&!a(r[e])},Ae=function(e,r,t,n){return Oe(e,n)?be(r,t,n[e]).then((function(r){return r.key=e,r})).catch((function(r){var t="Validation Exception, field: ".concat(e);throw console.error(t),r})):Promise.resolve({key:"",type:"",succeeded:!0,message:""})},Se=function(e,r,t){return Oe(e,t)?ye(r,t[e]).then((function(r){return r.key=e,r})).catch((function(r){var t="Validation Exception, record: ".concat(e);throw console.error(t),r})):Promise.resolve({key:"",type:"",succeeded:!0,message:""})},Pe=function(e,r){var t=ve(s(r),e,r,Se);return Promise.all(t).then((function(e){return we(e)})).catch((function(e){throw console.error("Uncontrolled error validating records"),e}))},xe=function(e,r,t){var o=function(e,r,t,n){return e.map((function(e){return n(e,te(r,e,void 0),r,t)}))}(s(r),e,r,Ae),i=ve(s(t),e,t,Se);return Promise.all(o).then((function(e){return Promise.all(i).then((function(r){return[e,r]}))})).then((function(e){var r=n(e,2);return function(e,r){var t={succeeded:!0,fieldErrors:{},recordErrors:{}};if(u(e)&&(t.succeeded=Ee(e),t.fieldErrors=je(e)),u(r)){var n=we(r);t.succeeded=t.succeeded&&n.succeeded,t.recordErrors=n.recordErrors}return t}(r[0],r[1])})).catch((function(e){throw console.error("Uncontrolled error validating records"),e}))},ke=function(){function e(r){!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e),this.fieldSchema={},this.recordSchema={},this.setupValidationSchema(r)}var n,u,i;return n=e,(u=[{key:"setupValidationSchema",value:function(e){if(e&&"object"===r(e)){var t=e.record,n=e.field;n&&"object"===r(n)&&(this.fieldSchema=le(e.field)),t&&"object"===r(t)&&(this.recordSchema=pe(e.record))}else console.error("ValidationSchema must be a valid object")}},{key:"validateField",value:function(e,r,t){return Ae(e,r,t,this.fieldSchema).then((function(e){e.key;var r=o(e,["key"]);return Object.assign({},r)}))}},{key:"validateRecord",value:function(e){return Pe(e,this.recordSchema)}},{key:"validateForm",value:function(e){return xe(e,this.fieldSchema,this.recordSchema)}}])&&t(n.prototype,u),i&&t(n,i),e}(),Ve=function(e,r){return e?function(e,r){var t=function(e){return e.match(/{{[^{}][\w\.]*}}/g)}(e);return Array.isArray(t)?t.reduce((function(e,t){return e.replace(t,te(r,function(e){return e.replace(/[{}]/g,"")}(t),t))}),e):e}(e,r):""},Fe="Please fill in this mandatory field.",Re={trim:!0},Te=function(e,r){return!!function(e){return null==e||""===e}(e)||r.test(e)},Me="Please enter a valid email address.",$e=/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,Ne="Please provide a valid format.",Ie="FieldValidationError: pattern option for pattern validation is mandatory. Example: { pattern: /d+/ }.";function ze(e){var r=e.pattern;if("boolean"==typeof r||null===r)throw new Error(Ie);return function(e){return e instanceof RegExp?e:new RegExp(e)}(r)}function Le(e,r){var t=null===e.length?NaN:Number(e.length);if(isNaN(t))throw new Error(r);return t}function Ce(e,r,t){return"string"!=typeof e||t(e,r)}var De="The value provided does not fulfill min length",Ge='FieldValidationError: Parameter "length" for minLength in customArgs is mandatory and should be a valid number. Example: { length: 4 }.',Ue=function(e,r){return e.length>=r},Be="The value provided does not fulfill max length",He='FieldValidationError: Parameter "length" for maxLength in customArgs is mandatory and should be a valid number. Example: { length: 4 }.',Ze=function(e,r){return e.length<=r},qe={required:Object.freeze({__proto__:null,setErrorMessage:function(e){return Fe=e},validator:function(e){var r=e.value,t=e.customArgs,n=void 0===t?Re:t,o=e.message,u=void 0===o?Fe:o,i=function(e,r){return"string"==typeof e?function(e,r){return r?e.trim().length>0:e.length>0}(e,r):function(e){return null!=e}(e)}(r,Boolean(n.trim));return{succeeded:i,message:i?"":Ve(u,n),type:"REQUIRED"}}}),email:Object.freeze({__proto__:null,setErrorMessage:function(e){return Me=e},validator:function(e){var r=e.value,t=e.message,n=void 0===t?Me:t,o=function(e){return Te(e,$e)}(r);return{succeeded:o,message:o?"":n,type:"EMAIL"}}}),pattern:Object.freeze({__proto__:null,setErrorMessage:function(e){return Ne=e},validator:function(e){if(!e.customArgs)throw new Error(Ie);var r=e.value,t=e.customArgs,n=void 0===t?null:t,o=e.message,u=void 0===o?Ne:o,i=ze(n),a=Te(r,i);return{succeeded:a,message:a?"":Ve(u,n),type:"PATTERN"}}}),minLength:Object.freeze({__proto__:null,setErrorMessage:function(e){return De=e},validator:function(e){if(!e.customArgs)throw new Error(Ge);var r=e.value,t=e.customArgs,n=void 0===t?null:t,o=e.message,u=void 0===o?De:o,i=Ce(r,Le(n,Ge),Ue);return{succeeded:i,message:i?"":Ve(u,n),type:"MIN_LENGTH"}}}),maxLength:Object.freeze({__proto__:null,setErrorMessage:function(e){return Be=e},validator:function(e){if(!e.customArgs)throw new Error(He);var r=e.value,t=e.customArgs,n=void 0===t?null:t,o=e.message,u=void 0===o?Be:o,i=Ce(r,Le(n,He),Ze);return{succeeded:i,message:i?"":Ve(u,n),type:"MAX_LENGTH"}}})},Qe={validateField:Ae,validateRecord:Pe,validateForm:xe,mapToInternalFieldValidationSchema:le,mapToInternalRecordValidationSchema:pe,FormValidation:ke};e.FormValidationExtended=Qe,e.Validators=qe,e.createDefaultFormValidationResult=ue,e.createDefaultRecordValidationResult=oe,e.createDefaultValidationResult=ne,e.createFormValidation=function(e){return new ke(e)},e.parseMessageWithCustomArgs=Ve,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
***************************************************************************** */()}function o(e,r){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)r.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(t[n[o]]=e[n[o]])}return t}var u=function(e){return function(e){return Array.isArray(e)?e.length:0}(e)>0},i=function(e){return"function"==typeof e},a=function(e){return null==e},c=function(e){return e instanceof Promise},s=function(e){return Boolean(e)?Object.keys(e):[]},l="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},f="Expected a function",d="__lodash_hash_undefined__",p=1/0,v="[object Function]",h="[object GeneratorFunction]",y="[object Symbol]",m=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,g=/^\w*$/,_=/^\./,b=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,E=/\\(\\)?/g,j=/^\[object .+?Constructor\]$/,w="object"==r(l)&&l&&l.Object===Object&&l,O="object"==("undefined"==typeof self?"undefined":r(self))&&self&&self.Object===Object&&self,A=w||O||Function("return this")();var S,P=Array.prototype,k=Function.prototype,x=Object.prototype,V=A["__core-js_shared__"],F=(S=/[^.]+$/.exec(V&&V.keys&&V.keys.IE_PROTO||""))?"Symbol(src)_1."+S:"",R=k.toString,T=x.hasOwnProperty,M=x.toString,$=RegExp("^"+R.call(T).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),N=A.Symbol,z=P.splice,L=W(A,"Map"),I=W(Object,"create"),C=N?N.prototype:void 0,D=C?C.toString:void 0;function G(e){var r=-1,t=e?e.length:0;for(this.clear();++r<t;){var n=e[r];this.set(n[0],n[1])}}function U(e){var r=-1,t=e?e.length:0;for(this.clear();++r<t;){var n=e[r];this.set(n[0],n[1])}}function B(e){var r=-1,t=e?e.length:0;for(this.clear();++r<t;){var n=e[r];this.set(n[0],n[1])}}function H(e,r){for(var t,n,o=e.length;o--;)if((t=e[o][0])===(n=r)||t!=t&&n!=n)return o;return-1}function Z(e,t){for(var n,o=0,u=(t=function(e,t){if(Y(e))return!1;var n=r(e);if("number"==n||"symbol"==n||"boolean"==n||null==e||re(e))return!0;return g.test(e)||!m.test(e)||null!=t&&e in Object(t)}(t,e)?[t]:Y(n=t)?n:X(n)).length;null!=e&&o<u;)e=e[J(t[o++])];return o&&o==u?e:void 0}function q(e){return!(!ee(e)||(r=e,F&&F in r))&&(function(e){var r=ee(e)?M.call(e):"";return r==v||r==h}(e)||function(e){var r=!1;if(null!=e&&"function"!=typeof e.toString)try{r=!!(e+"")}catch(e){}return r}(e)?$:j).test(function(e){if(null!=e){try{return R.call(e)}catch(e){}try{return e+""}catch(e){}}return""}(e));var r}function Q(e,t){var n,o,u=e.__data__;return("string"==(o=r(n=t))||"number"==o||"symbol"==o||"boolean"==o?"__proto__"!==n:null===n)?u["string"==typeof t?"string":"hash"]:u.map}function W(e,r){var t=function(e,r){return null==e?void 0:e[r]}(e,r);return q(t)?t:void 0}G.prototype.clear=function(){this.__data__=I?I(null):{}},G.prototype.delete=function(e){return this.has(e)&&delete this.__data__[e]},G.prototype.get=function(e){var r=this.__data__;if(I){var t=r[e];return t===d?void 0:t}return T.call(r,e)?r[e]:void 0},G.prototype.has=function(e){var r=this.__data__;return I?void 0!==r[e]:T.call(r,e)},G.prototype.set=function(e,r){return this.__data__[e]=I&&void 0===r?d:r,this},U.prototype.clear=function(){this.__data__=[]},U.prototype.delete=function(e){var r=this.__data__,t=H(r,e);return!(t<0)&&(t==r.length-1?r.pop():z.call(r,t,1),!0)},U.prototype.get=function(e){var r=this.__data__,t=H(r,e);return t<0?void 0:r[t][1]},U.prototype.has=function(e){return H(this.__data__,e)>-1},U.prototype.set=function(e,r){var t=this.__data__,n=H(t,e);return n<0?t.push([e,r]):t[n][1]=r,this},B.prototype.clear=function(){this.__data__={hash:new G,map:new(L||U),string:new G}},B.prototype.delete=function(e){return Q(this,e).delete(e)},B.prototype.get=function(e){return Q(this,e).get(e)},B.prototype.has=function(e){return Q(this,e).has(e)},B.prototype.set=function(e,r){return Q(this,e).set(e,r),this};var X=K((function(e){var r;e=null==(r=e)?"":function(e){if("string"==typeof e)return e;if(re(e))return D?D.call(e):"";var r=e+"";return"0"==r&&1/e==-p?"-0":r}(r);var t=[];return _.test(e)&&t.push(""),e.replace(b,(function(e,r,n,o){t.push(n?o.replace(E,"$1"):r||e)})),t}));function J(e){if("string"==typeof e||re(e))return e;var r=e+"";return"0"==r&&1/e==-p?"-0":r}function K(e,r){if("function"!=typeof e||r&&"function"!=typeof r)throw new TypeError(f);var t=function t(){var n=arguments,o=r?r.apply(this,n):n[0],u=t.cache;if(u.has(o))return u.get(o);var i=e.apply(this,n);return t.cache=u.set(o,i),i};return t.cache=new(K.Cache||B),t}K.Cache=B;var Y=Array.isArray;function ee(e){var t=r(e);return!!e&&("object"==t||"function"==t)}function re(e){return"symbol"==r(e)||function(e){return!!e&&"object"==r(e)}(e)&&M.call(e)==y}var te=function(e,r,t){var n=null==e?void 0:Z(e,r);return void 0===n?t:n},ne=function(){return{type:"",succeeded:!0,message:""}},oe=function(){return{succeeded:!0,recordErrors:{}}},ue=function(){return{succeeded:!0,fieldErrors:{},recordErrors:{}}},ie=function(e){return function(r){var t=e?e(r):{type:"",succeeded:!0,message:""};return c(t)?t:Promise.resolve(t)}},ae=function(e){return function(r){var t=e?e(r):{type:"",succeeded:!0,message:""};return c(t)?t:Promise.resolve(t)}},ce=function(e){return i(e)?{validator:ie(e),message:void 0,customArgs:void 0}:{validator:ie(e.validator),customArgs:e.customArgs,message:e.message}},se=function(e){return Array.isArray(e)?e.map(ce):[]},le=function(e){var r=e instanceof Object?e:{},t=Object.entries(r).map((function(e){var r=n(e,2),t=r[0],o=r[1];return[t,se(o)]}));return t.reduce((function(e,r){var t=n(r,2),o=t[0],u=t[1];return e[o]=u,e}),{})},fe=function(e){return i(e)?{validator:ae(e),message:void 0}:{validator:ae(e.validator),message:e.message}},de=function(e){return Array.isArray(e)?e.map(fe):[]},pe=function(e){var r=e instanceof Object?e:{},t=Object.entries(r).map((function(e){var r=n(e,2),t=r[0],o=r[1];return[t,de(o)]}));return t.reduce((function(e,r){var t=n(r,2),o=t[0],u=t[1];return e[o]=u,e}),{})},ve=function(e,r,t,n){return e.map((function(e){return n(e,r,t)}))},he=function(e){var r=e;return e&&!a(e.succeeded)||(console.error("form-validators: One of the record validator is returning a non expected value."),r={key:"",type:"",succeeded:!0,message:""}),r},ye=function(e,r){return r.validator({values:e,message:r.message}).then(he)},me=function(e,r){return u(r)?function(e,r){return r.reduce((function(r,t){return r.then((function(r){return r.succeeded?ye(e,t):r}))}),ye(e,r[0]))}(e,r):Promise.resolve({key:"",type:"",succeeded:!0,message:""})},ge=function(e){var r=e;return e&&!a(e.succeeded)||(console.error("form-validators: One of the field validator is returning a non expected value."),r={key:"",type:"",succeeded:!0,message:""}),r},_e=function(e,r,t){return t.validator({value:e,values:r,customArgs:t.customArgs,message:t.message}).then(ge)},be=function(e,r,t){return u(t)?function(e,r,t){return t.reduce((function(t,n){return t.then((function(t){return t.succeeded?_e(e,r,n):t}))}),_e(e,r,t[0]))}(e,r,t):Promise.resolve({key:"",type:"",succeeded:!0,message:""})},Ee=function(e){return e.every((function(e){return e.succeeded}))},je=function(e){return e.reduce((function(e,r){var t=r.key,n=o(r,["key"]);return e[t]=Object.assign({},n),e}),{})},we=function(e){var r={succeeded:!0,recordErrors:{}};return u(e)&&(r.succeeded=Ee(e),r.recordErrors=je(e)),r},Oe=function(e,r){return!a(r)&&!a(r[e])},Ae=function(e,r,t,n){return Oe(e,n)?be(r,t,n[e]).then((function(r){return r.key=e,r})).catch((function(r){var t="Validation Exception, field: ".concat(e);throw console.error(t),r})):Promise.resolve({key:"",type:"",succeeded:!0,message:""})},Se=function(e,r,t){return Oe(e,t)?me(r,t[e]).then((function(r){return r.key=e,r})).catch((function(r){var t="Validation Exception, record: ".concat(e);throw console.error(t),r})):Promise.resolve({key:"",type:"",succeeded:!0,message:""})},Pe=function(e,r,t){var o=function(e,r,t,n){return e.map((function(e){return n(e,te(r,e,void 0),r,t)}))}(s(r),e,r,Ae),i=ve(s(t),e,t,Se);return Promise.all(o).then((function(e){return Promise.all(i).then((function(r){return[e,r]}))})).then((function(e){var r=n(e,2);return function(e,r){var t={succeeded:!0,fieldErrors:{},recordErrors:{}};if(u(e)&&(t.succeeded=Ee(e),t.fieldErrors=je(e)),u(r)){var n=we(r);t.succeeded=t.succeeded&&n.succeeded,t.recordErrors=n.recordErrors}return t}(r[0],r[1])})).catch((function(e){throw console.error("Uncontrolled error validating records"),e}))},ke=function(){function e(r){!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e),this.fieldSchema={},this.recordSchema={},this.setupValidationSchema(r)}var n,u,i;return n=e,(u=[{key:"setupValidationSchema",value:function(e){if(e&&"object"===r(e)){var t=e.record,n=e.field;n&&"object"===r(n)&&(this.fieldSchema=le(e.field)),t&&"object"===r(t)&&(this.recordSchema=pe(e.record))}else console.error("ValidationSchema must be a valid object")}},{key:"validateField",value:function(e,r,t){return Ae(e,r,t,this.fieldSchema).then((function(e){e.key;var r=o(e,["key"]);return Object.assign({},r)}))}},{key:"validateRecord",value:function(e){return function(e,r){var t=ve(s(r),e,r,Se);return Promise.all(t).then((function(e){return we(e)})).catch((function(e){throw console.error("Uncontrolled error validating records"),e}))}(e,this.recordSchema)}},{key:"validateForm",value:function(e){return Pe(e,this.fieldSchema,this.recordSchema)}},{key:"updateValidationSchema",value:function(e){this.setupValidationSchema(e)}}])&&t(n.prototype,u),i&&t(n,i),e}(),xe=function(e,r){return e?function(e,r){var t=function(e){return e.match(/{{[^{}][\w\.]*}}/g)}(e);return Array.isArray(t)?t.reduce((function(e,t){return e.replace(t,te(r,function(e){return e.replace(/[{}]/g,"")}(t),t))}),e):e}(e,r):""},Ve="Please fill in this mandatory field.",Fe={trim:!0},Re=function(e,r){return!!function(e){return null==e||""===e}(e)||r.test(e)},Te="Please enter a valid email address.",Me=/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,$e="Please provide a valid format.",Ne="FieldValidationError: pattern option for pattern validation is mandatory. Example: { pattern: /d+/ }.";function ze(e){var r=e.pattern;if("boolean"==typeof r||null===r)throw new Error(Ne);return function(e){return e instanceof RegExp?e:new RegExp(e)}(r)}function Le(e,r){var t=null===e.length?NaN:Number(e.length);if(isNaN(t))throw new Error(r);return t}function Ie(e,r,t){return"string"!=typeof e||t(e,r)}var Ce="The value provided does not fulfill min length",De='FieldValidationError: Parameter "length" for minLength in customArgs is mandatory and should be a valid number. Example: { length: 4 }.',Ge=function(e,r){return e.length>=r},Ue="The value provided does not fulfill max length",Be='FieldValidationError: Parameter "length" for maxLength in customArgs is mandatory and should be a valid number. Example: { length: 4 }.',He=function(e,r){return e.length<=r},Ze={required:Object.freeze({__proto__:null,setErrorMessage:function(e){return Ve=e},validator:function(e){var r=e.value,t=e.customArgs,n=void 0===t?Fe:t,o=e.message,u=void 0===o?Ve:o,i=function(e,r){return"string"==typeof e?function(e,r){return r?e.trim().length>0:e.length>0}(e,r):function(e){return null!=e}(e)}(r,Boolean(n.trim));return{succeeded:i,message:i?"":xe(u,n),type:"REQUIRED"}}}),email:Object.freeze({__proto__:null,setErrorMessage:function(e){return Te=e},validator:function(e){var r=e.value,t=e.message,n=void 0===t?Te:t,o=function(e){return Re(e,Me)}(r);return{succeeded:o,message:o?"":n,type:"EMAIL"}}}),pattern:Object.freeze({__proto__:null,setErrorMessage:function(e){return $e=e},validator:function(e){if(!e.customArgs)throw new Error(Ne);var r=e.value,t=e.customArgs,n=void 0===t?null:t,o=e.message,u=void 0===o?$e:o,i=ze(n),a=Re(r,i);return{succeeded:a,message:a?"":xe(u,n),type:"PATTERN"}}}),minLength:Object.freeze({__proto__:null,setErrorMessage:function(e){return Ce=e},validator:function(e){if(!e.customArgs)throw new Error(De);var r=e.value,t=e.customArgs,n=void 0===t?null:t,o=e.message,u=void 0===o?Ce:o,i=Ie(r,Le(n,De),Ge);return{succeeded:i,message:i?"":xe(u,n),type:"MIN_LENGTH"}}}),maxLength:Object.freeze({__proto__:null,setErrorMessage:function(e){return Ue=e},validator:function(e){if(!e.customArgs)throw new Error(Be);var r=e.value,t=e.customArgs,n=void 0===t?null:t,o=e.message,u=void 0===o?Ue:o,i=Ie(r,Le(n,Be),He);return{succeeded:i,message:i?"":xe(u,n),type:"MAX_LENGTH"}}})};e.FormValidation=ke,e.Validators=Ze,e.createDefaultFormValidationResult=ue,e.createDefaultRecordValidationResult=oe,e.createDefaultValidationResult=ne,e.createFormValidation=function(e){return new ke(e)},e.parseMessageWithCustomArgs=xe,Object.defineProperty(e,"__esModule",{value:!0})})); |
{ | ||
"name": "@lemoncode/fonk", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Form schema validator library", | ||
@@ -5,0 +5,0 @@ "main": "dist/@lemoncode/fonk.cjs.js", |
@@ -18,4 +18,2 @@ # Fonk | ||
Form schema validation library. | ||
@@ -34,2 +32,4 @@ | ||
![validate-field](./content/validate-field.gif) | ||
[Live Demo (Fonk + React Final Form)](https://codesandbox.io/s/github/lemoncode/fonk/tree/master/examples/react-final-form/js/validate-field) | ||
@@ -43,11 +43,8 @@ | ||
- React | ||
- React Final form. | ||
- [React Final form](https://github.com/Lemoncode/fonk-final-form). | ||
- [Formik](https://github.com/Lemoncode/fonk-formik). | ||
Coming soon integration examples: | ||
- Vuejs. | ||
- React | ||
- React Final Forms. | ||
- Formik. | ||
- Vuejs. | ||
How to [get started](https://lemoncode.github.io/fonk-doc/getting-started) | ||
@@ -54,0 +51,0 @@ |
@@ -11,7 +11,2 @@ import { | ||
FieldValidationFunctionSyncAsync, | ||
FieldValidationSchema, | ||
InternalFieldValidationSchema, | ||
RecordValidationSchema, | ||
InternalRecordValidationSchema, | ||
InternalValidationResult, | ||
} from './model'; | ||
@@ -32,2 +27,3 @@ | ||
* Main function to create an instance of FormValidation. We could use `validateField`, `validateRecord` and/or `validateForm` to fire validations. | ||
* `updateValidationSchema`: to update validation schema after create form validation instance. | ||
* | ||
@@ -44,3 +40,3 @@ * **Arguments** | ||
interface FormValidation { | ||
export interface FormValidation { | ||
validateField: ( | ||
@@ -53,2 +49,3 @@ fieldId: string, | ||
validateForm: (values: any) => Promise<FormValidationResult>; | ||
updateValidationSchema(validationSchema: ValidationSchema): void; | ||
} | ||
@@ -98,47 +95,1 @@ | ||
): string; | ||
/** | ||
* Expose all necessary methods to create a new form-validation | ||
* (the createFormValidation method) | ||
*/ | ||
export namespace FormValidationExtended { | ||
export function validateField( | ||
fieldId: string, | ||
value: any, | ||
values: any, | ||
schema: InternalFieldValidationSchema | ||
): Promise<InternalValidationResult>; | ||
export function validateRecord( | ||
values: any, | ||
schema: InternalRecordValidationSchema | ||
): Promise<RecordValidationResult>; | ||
export function validateForm( | ||
values: any, | ||
fieldSchema: InternalFieldValidationSchema, | ||
recordSchema: InternalRecordValidationSchema | ||
): Promise<FormValidationResult>; | ||
export function mapToInternalFieldValidationSchema( | ||
fieldValidationSchema: FieldValidationSchema | ||
): InternalFieldValidationSchema; | ||
export function mapToInternalRecordValidationSchema( | ||
recordValidationSchema: RecordValidationSchema | ||
): InternalRecordValidationSchema; | ||
export class FormValidation { | ||
constructor(validationSchema: ValidationSchema); | ||
validateField: ( | ||
fieldId: string, | ||
value: any, | ||
values?: any | ||
) => Promise<ValidationResult>; | ||
validateRecord: (values: any) => Promise<RecordValidationResult>; | ||
validateForm: (values: any) => Promise<FormValidationResult>; | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
185990
4702
60