@kingshott/iodine
Advanced tools
Comparing version 8.0.0 to 8.1.0
@@ -1,2 +0,2 @@ | ||
class e{constructor(){this.locale=void 0,this.messages={after:"The date must be after: '[PARAM]'",afterOrEqual:"The date must be after or equal to: '[PARAM]'",array:"[FIELD] must be an array",before:"The date must be before: '[PARAM]'",beforeOrEqual:"The date must be before or equal to: '[PARAM]'",boolean:"[FIELD] must be true or false",date:"[FIELD] must be a date",different:"[FIELD] must be different to '[PARAM]'",endsWith:"[FIELD] must end with '[PARAM]'",email:"[FIELD] must be a valid email address",falsy:"[FIELD] must be a falsy value (false, 'false', 0 or '0')",in:"[FIELD] must be one of the following options: [PARAM]",integer:"[FIELD] must be an integer",json:"[FIELD] must be a parsable JSON object string",max:"[FIELD] must be less than or equal to [PARAM]",min:"[FIELD] must be greater than or equal to [PARAM]",maxLength:"[FIELD] must not be greater than '[PARAM]' in character length",minLength:"[FIELD] must not be less than '[PARAM]' character length",notIn:"[FIELD] must not be one of the following options: [PARAM]",numeric:"[FIELD] must be numeric",optional:"[FIELD] is optional",regexMatch:"[FIELD] must satisify the regular expression: [PARAM]",required:"[FIELD] must be present",same:"[FIELD] must be '[PARAM]'",startsWith:"[FIELD] must start with '[PARAM]'",string:"[FIELD] must be a string",truthy:"[FIELD] must be a truthy value (true, 'true', 1 or '1')",url:"[FIELD] must be a valid url",uuid:"[FIELD] must be a valid UUID"}}_compare(e,t,r,s=!1){return!!this.assertDate(e)&&!(!this.assertDate(t)&&!this.assertInteger(t))&&(t="number"==typeof t?t:t.getTime(),"less"===r&&s?e.getTime()<=t:"less"!==r||s?"more"===r&&s?e.getTime()>=t:"more"!==r||s?void 0:e.getTime()>t:e.getTime()<t)}_error(e,t){let{param:r,field:s}="object"==typeof t?t:{param:t,field:void 0};const a=e.split(":");let i=a.shift();r=r||a.join(":"),["after","afterOrEqual","before","beforeOrEqual"].includes(i)&&(r=new Date(parseInt(r)).toLocaleTimeString(this.locale,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"numeric",hour12:!1}));let n=[null,void 0,""].includes(r)?this.messages[i]:this.messages[i].replace("[PARAM]",r);return[null,void 0,""].includes(s)?n.replace("[FIELD]",this.default_field_name??"Value"):n.replace("[FIELD]",s)}_missing(){return{valid:!1,rule:"None",error:"Rules exist, but no value was provided to check"}}_prepare(e,t=[]){return t.length?"optional"===t[0]&&this.assertOptional(e)?[]:t.filter(e=>"optional"!==e).map(e=>[e,this._title(e.split(":").shift()),e.split(":").slice(1)]):[]}_title(e){return`${e[0].toUpperCase()}${e.slice(1)}`}_validate(e,t){for(let r in t=this._prepare(e,t))if(!this[`assert${t[r][1]}`].apply(this,[e,t[r][2].join(":")]))return{valid:!1,rule:t[r][0],error:this._error(t[r][0])};return{valid:!0,rule:"",error:""}}assert(e,t){if(Array.isArray(t))return this._validate(e,t);let r=Object.keys(t),s={valid:!0,fields:{}};for(let a=0;a<r.length;a++)s.fields[r[a]]=e.hasOwnProperty(r[a])?this._validate(e[r[a]],t[r[a]]):this._missing(),s.fields[r[a]].valid||(s.valid=!1);return s}assertAfter(e,t){return this._compare(e,t,"more",!1)}assertAfterOrEqual(e,t){return this._compare(e,t,"more",!0)}assertArray(e){return Array.isArray(e)}assertBefore(e,t){return this._compare(e,t,"less",!1)}assertBeforeOrEqual(e,t){return this._compare(e,t,"less",!0)}assertBoolean(e){return[!0,!1].includes(e)}assertDate(e){return e&&"[object Date]"===Object.prototype.toString.call(e)&&!isNaN(e)}assertDifferent(e,t){return e!=t}assertEndsWith(e,t){return this.assertString(e)&&e.endsWith(t)}assertEmail(e){return new RegExp("^[a-zA-Z0-9.!#$%&'+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:.[a-zA-Z0-9-]+)$").test(String(e).toLowerCase())}assertFalsy(e){return[0,"0",!1,"false"].includes(e)}assertIn(e,t){return("string"==typeof t?t.split(","):t).includes(e)}assertInteger(e){return Number.isInteger(e)&&parseInt(e).toString()===e.toString()}assertJson(e){try{return"object"==typeof JSON.parse(e)}catch(e){return!1}}assertMax(e,t){return parseFloat(e)<=t}assertMin(e,t){return parseFloat(e)>=t}assertMaxLength(e,t){return"string"==typeof e&&e.length<=t}assertMinLength(e,t){return"string"==typeof e&&e.length>=t}assertNotIn(e,t){return!this.assertIn(e,t)}assertNumeric(e){return!isNaN(parseFloat(e))&&isFinite(e)}assertOptional(e){return[null,void 0,""].includes(e)}assertRegexMatch(e,t){return new RegExp(t).test(String(e))}assertRequired(e){return!this.assertOptional(e)}assertSame(e,t){return e==t}assertStartsWith(e,t){return this.assertString(e)&&e.startsWith(t)}assertString(e){return"string"==typeof e}assertTruthy(e){return[1,"1",!0,"true"].includes(e)}assertUrl(e){return new RegExp("^(https?:\\/\\/)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*(\\?[;&a-z\\d%_.~+=-]*)?(\\#[-a-z\\d_]*)?$").test(String(e).toLowerCase())}assertUuid(e){return new RegExp("^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$").test(String(e).toLowerCase())}rule(t,r){e.prototype[`assert${this._title(t)}`]=r}setErrorMessages(e){this.messages=e}setErrorMessage(e,t){this.messages[e]=t}setLocale(e){this.locale=e}setDefaultFieldName(e){this.default_field_name=e}}"undefined"!=typeof window&&(window.Iodine=new e);export{e as default}; | ||
class e{constructor(){this.locale=void 0,this.messages={after:"The date must be after: '[PARAM]'",afterOrEqual:"The date must be after or equal to: '[PARAM]'",array:"[FIELD] must be an array",before:"The date must be before: '[PARAM]'",beforeOrEqual:"The date must be before or equal to: '[PARAM]'",boolean:"[FIELD] must be true or false",date:"[FIELD] must be a date",different:"[FIELD] must be different to '[PARAM]'",endsWith:"[FIELD] must end with '[PARAM]'",email:"[FIELD] must be a valid email address",falsy:"[FIELD] must be a falsy value (false, 'false', 0 or '0')",in:"[FIELD] must be one of the following options: [PARAM]",integer:"[FIELD] must be an integer",json:"[FIELD] must be a parsable JSON object string",max:"[FIELD] must be less than or equal to [PARAM]",min:"[FIELD] must be greater than or equal to [PARAM]",maxLength:"[FIELD] must not be greater than '[PARAM]' in character length",minLength:"[FIELD] must not be less than '[PARAM]' character length",notIn:"[FIELD] must not be one of the following options: [PARAM]",numeric:"[FIELD] must be numeric",optional:"[FIELD] is optional",regexMatch:"[FIELD] must satisify the regular expression: [PARAM]",required:"[FIELD] must be present",same:"[FIELD] must be '[PARAM]'",startsWith:"[FIELD] must start with '[PARAM]'",string:"[FIELD] must be a string",truthy:"[FIELD] must be a truthy value (true, 'true', 1 or '1')",url:"[FIELD] must be a valid url",uuid:"[FIELD] must be a valid UUID"}}_compare(e,t,r,s=!1){return!!this.assertDate(e)&&!(!this.assertDate(t)&&!this.assertInteger(t))&&(t="number"==typeof t?t:t.getTime(),"less"===r&&s?e.getTime()<=t:"less"!==r||s?"more"===r&&s?e.getTime()>=t:"more"!==r||s?void 0:e.getTime()>t:e.getTime()<t)}_error(e,t){let{param:r,field:s}="object"==typeof t?t:{param:t,field:void 0};const a=e.split(":");let i=a.shift();r=r||a.join(":"),["after","afterOrEqual","before","beforeOrEqual"].includes(i)&&(r=new Date(parseInt(r)).toLocaleTimeString(this.locale,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"numeric",hour12:!1}));let n=[null,void 0,""].includes(r)?this.messages[i]:this.messages[i].replace("[PARAM]",r);return[null,void 0,""].includes(s)?n.replace("[FIELD]",this.default_field_name??"Value"):n.replace("[FIELD]",s)}_missing(){return{valid:!1,rule:"None",error:"Rules exist, but no value was provided to check"}}_prepare(e,t=[]){return t.length?"optional"===t[0]&&this.assertOptional(e)?[]:t.filter(e=>"optional"!==e).map(e=>[e,this._title(e.split(":").shift()),e.split(":").slice(1)]):[]}_title(e){return`${e[0].toUpperCase()}${e.slice(1)}`}_validate(e,t){for(let r in t=this._prepare(e,t))if(!this[`assert${t[r][1]}`].apply(this,[e,t[r][2].join(":")]))return{valid:!1,rule:t[r][0],error:this._error(t[r][0])};return{valid:!0,rule:"",error:""}}assert(e,t){if(Array.isArray(t))return this._validate(e,t);let r=Object.keys(t),s={valid:!0,fields:{}};for(let a=0;a<r.length;a++)s.fields[r[a]]=e.hasOwnProperty(r[a])?this._validate(e[r[a]],t[r[a]]):this._missing(),s.fields[r[a]].valid||(s.valid=!1);return s}assertAfter(e,t){return this._compare(e,t,"more",!1)}assertAfterOrEqual(e,t){return this._compare(e,t,"more",!0)}assertArray(e){return Array.isArray(e)}assertBefore(e,t){return this._compare(e,t,"less",!1)}assertBeforeOrEqual(e,t){return this._compare(e,t,"less",!0)}assertBoolean(e){return[!0,!1].includes(e)}assertDate(e){return e&&"[object Date]"===Object.prototype.toString.call(e)&&!isNaN(e)}assertDifferent(e,t){return e!=t}assertEndsWith(e,t){return this.assertString(e)&&e.endsWith(t)}assertEmail(e){return new RegExp("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?").test(String(e).toLowerCase())}assertFalsy(e){return[0,"0",!1,"false"].includes(e)}assertIn(e,t){return("string"==typeof t?t.split(","):t).includes(e)}assertInteger(e){return Number.isInteger(e)&&parseInt(e).toString()===e.toString()}assertJson(e){try{return"object"==typeof JSON.parse(e)}catch(e){return!1}}assertMax(e,t){return parseFloat(e)<=t}assertMin(e,t){return parseFloat(e)>=t}assertMaxLength(e,t){return"string"==typeof e&&e.length<=t}assertMinLength(e,t){return"string"==typeof e&&e.length>=t}assertNotIn(e,t){return!this.assertIn(e,t)}assertNumeric(e){return!isNaN(parseFloat(e))&&isFinite(e)}assertOptional(e){return[null,void 0,""].includes(e)}assertRegexMatch(e,t){return new RegExp(t).test(String(e))}assertRequired(e){return!this.assertOptional(e)}assertSame(e,t){return e==t}assertStartsWith(e,t){return this.assertString(e)&&e.startsWith(t)}assertString(e){return"string"==typeof e}assertTruthy(e){return[1,"1",!0,"true"].includes(e)}assertUrl(e){return new RegExp("^(https?:\\/\\/)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*(\\?[;&a-z\\d%_.~+=-]*)?(\\#[-a-z\\d_]*)?$").test(String(e).toLowerCase())}assertUuid(e){return new RegExp("^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$").test(String(e).toLowerCase())}rule(t,r){e.prototype[`assert${this._title(t)}`]=r}setErrorMessages(e){this.messages=e}setErrorMessage(e,t){this.messages[e]=t}setLocale(e){this.locale=e}setDefaultFieldName(e){this.default_field_name=e}}"undefined"!=typeof window&&(window.Iodine=new e);export{e as default}; | ||
//# sourceMappingURL=iodine.min.esm.js.map |
@@ -1,2 +0,2 @@ | ||
class e{constructor(){this.locale=void 0,this.messages={after:"The date must be after: '[PARAM]'",afterOrEqual:"The date must be after or equal to: '[PARAM]'",array:"[FIELD] must be an array",before:"The date must be before: '[PARAM]'",beforeOrEqual:"The date must be before or equal to: '[PARAM]'",boolean:"[FIELD] must be true or false",date:"[FIELD] must be a date",different:"[FIELD] must be different to '[PARAM]'",endsWith:"[FIELD] must end with '[PARAM]'",email:"[FIELD] must be a valid email address",falsy:"[FIELD] must be a falsy value (false, 'false', 0 or '0')",in:"[FIELD] must be one of the following options: [PARAM]",integer:"[FIELD] must be an integer",json:"[FIELD] must be a parsable JSON object string",max:"[FIELD] must be less than or equal to [PARAM]",min:"[FIELD] must be greater than or equal to [PARAM]",maxLength:"[FIELD] must not be greater than '[PARAM]' in character length",minLength:"[FIELD] must not be less than '[PARAM]' character length",notIn:"[FIELD] must not be one of the following options: [PARAM]",numeric:"[FIELD] must be numeric",optional:"[FIELD] is optional",regexMatch:"[FIELD] must satisify the regular expression: [PARAM]",required:"[FIELD] must be present",same:"[FIELD] must be '[PARAM]'",startsWith:"[FIELD] must start with '[PARAM]'",string:"[FIELD] must be a string",truthy:"[FIELD] must be a truthy value (true, 'true', 1 or '1')",url:"[FIELD] must be a valid url",uuid:"[FIELD] must be a valid UUID"}}_compare(e,t,r,s=!1){return!!this.assertDate(e)&&!(!this.assertDate(t)&&!this.assertInteger(t))&&(t="number"==typeof t?t:t.getTime(),"less"===r&&s?e.getTime()<=t:"less"!==r||s?"more"===r&&s?e.getTime()>=t:"more"!==r||s?void 0:e.getTime()>t:e.getTime()<t)}_error(e,t){let{param:r,field:s}="object"==typeof t?t:{param:t,field:void 0};const a=e.split(":");let i=a.shift();r=r||a.join(":"),["after","afterOrEqual","before","beforeOrEqual"].includes(i)&&(r=new Date(parseInt(r)).toLocaleTimeString(this.locale,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"numeric",hour12:!1}));let n=[null,void 0,""].includes(r)?this.messages[i]:this.messages[i].replace("[PARAM]",r);return[null,void 0,""].includes(s)?n.replace("[FIELD]",this.default_field_name??"Value"):n.replace("[FIELD]",s)}_missing(){return{valid:!1,rule:"None",error:"Rules exist, but no value was provided to check"}}_prepare(e,t=[]){return t.length?"optional"===t[0]&&this.assertOptional(e)?[]:t.filter(e=>"optional"!==e).map(e=>[e,this._title(e.split(":").shift()),e.split(":").slice(1)]):[]}_title(e){return`${e[0].toUpperCase()}${e.slice(1)}`}_validate(e,t){for(let r in t=this._prepare(e,t))if(!this[`assert${t[r][1]}`].apply(this,[e,t[r][2].join(":")]))return{valid:!1,rule:t[r][0],error:this._error(t[r][0])};return{valid:!0,rule:"",error:""}}assert(e,t){if(Array.isArray(t))return this._validate(e,t);let r=Object.keys(t),s={valid:!0,fields:{}};for(let a=0;a<r.length;a++)s.fields[r[a]]=e.hasOwnProperty(r[a])?this._validate(e[r[a]],t[r[a]]):this._missing(),s.fields[r[a]].valid||(s.valid=!1);return s}assertAfter(e,t){return this._compare(e,t,"more",!1)}assertAfterOrEqual(e,t){return this._compare(e,t,"more",!0)}assertArray(e){return Array.isArray(e)}assertBefore(e,t){return this._compare(e,t,"less",!1)}assertBeforeOrEqual(e,t){return this._compare(e,t,"less",!0)}assertBoolean(e){return[!0,!1].includes(e)}assertDate(e){return e&&"[object Date]"===Object.prototype.toString.call(e)&&!isNaN(e)}assertDifferent(e,t){return e!=t}assertEndsWith(e,t){return this.assertString(e)&&e.endsWith(t)}assertEmail(e){return new RegExp("^[a-zA-Z0-9.!#$%&'+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:.[a-zA-Z0-9-]+)$").test(String(e).toLowerCase())}assertFalsy(e){return[0,"0",!1,"false"].includes(e)}assertIn(e,t){return("string"==typeof t?t.split(","):t).includes(e)}assertInteger(e){return Number.isInteger(e)&&parseInt(e).toString()===e.toString()}assertJson(e){try{return"object"==typeof JSON.parse(e)}catch(e){return!1}}assertMax(e,t){return parseFloat(e)<=t}assertMin(e,t){return parseFloat(e)>=t}assertMaxLength(e,t){return"string"==typeof e&&e.length<=t}assertMinLength(e,t){return"string"==typeof e&&e.length>=t}assertNotIn(e,t){return!this.assertIn(e,t)}assertNumeric(e){return!isNaN(parseFloat(e))&&isFinite(e)}assertOptional(e){return[null,void 0,""].includes(e)}assertRegexMatch(e,t){return new RegExp(t).test(String(e))}assertRequired(e){return!this.assertOptional(e)}assertSame(e,t){return e==t}assertStartsWith(e,t){return this.assertString(e)&&e.startsWith(t)}assertString(e){return"string"==typeof e}assertTruthy(e){return[1,"1",!0,"true"].includes(e)}assertUrl(e){return new RegExp("^(https?:\\/\\/)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*(\\?[;&a-z\\d%_.~+=-]*)?(\\#[-a-z\\d_]*)?$").test(String(e).toLowerCase())}assertUuid(e){return new RegExp("^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$").test(String(e).toLowerCase())}rule(t,r){e.prototype[`assert${this._title(t)}`]=r}setErrorMessages(e){this.messages=e}setErrorMessage(e,t){this.messages[e]=t}setLocale(e){this.locale=e}setDefaultFieldName(e){this.default_field_name=e}}"undefined"!=typeof window&&(window.Iodine=new e),module.exports=e; | ||
class e{constructor(){this.locale=void 0,this.messages={after:"The date must be after: '[PARAM]'",afterOrEqual:"The date must be after or equal to: '[PARAM]'",array:"[FIELD] must be an array",before:"The date must be before: '[PARAM]'",beforeOrEqual:"The date must be before or equal to: '[PARAM]'",boolean:"[FIELD] must be true or false",date:"[FIELD] must be a date",different:"[FIELD] must be different to '[PARAM]'",endsWith:"[FIELD] must end with '[PARAM]'",email:"[FIELD] must be a valid email address",falsy:"[FIELD] must be a falsy value (false, 'false', 0 or '0')",in:"[FIELD] must be one of the following options: [PARAM]",integer:"[FIELD] must be an integer",json:"[FIELD] must be a parsable JSON object string",max:"[FIELD] must be less than or equal to [PARAM]",min:"[FIELD] must be greater than or equal to [PARAM]",maxLength:"[FIELD] must not be greater than '[PARAM]' in character length",minLength:"[FIELD] must not be less than '[PARAM]' character length",notIn:"[FIELD] must not be one of the following options: [PARAM]",numeric:"[FIELD] must be numeric",optional:"[FIELD] is optional",regexMatch:"[FIELD] must satisify the regular expression: [PARAM]",required:"[FIELD] must be present",same:"[FIELD] must be '[PARAM]'",startsWith:"[FIELD] must start with '[PARAM]'",string:"[FIELD] must be a string",truthy:"[FIELD] must be a truthy value (true, 'true', 1 or '1')",url:"[FIELD] must be a valid url",uuid:"[FIELD] must be a valid UUID"}}_compare(e,t,r,s=!1){return!!this.assertDate(e)&&!(!this.assertDate(t)&&!this.assertInteger(t))&&(t="number"==typeof t?t:t.getTime(),"less"===r&&s?e.getTime()<=t:"less"!==r||s?"more"===r&&s?e.getTime()>=t:"more"!==r||s?void 0:e.getTime()>t:e.getTime()<t)}_error(e,t){let{param:r,field:s}="object"==typeof t?t:{param:t,field:void 0};const a=e.split(":");let i=a.shift();r=r||a.join(":"),["after","afterOrEqual","before","beforeOrEqual"].includes(i)&&(r=new Date(parseInt(r)).toLocaleTimeString(this.locale,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"numeric",hour12:!1}));let n=[null,void 0,""].includes(r)?this.messages[i]:this.messages[i].replace("[PARAM]",r);return[null,void 0,""].includes(s)?n.replace("[FIELD]",this.default_field_name??"Value"):n.replace("[FIELD]",s)}_missing(){return{valid:!1,rule:"None",error:"Rules exist, but no value was provided to check"}}_prepare(e,t=[]){return t.length?"optional"===t[0]&&this.assertOptional(e)?[]:t.filter(e=>"optional"!==e).map(e=>[e,this._title(e.split(":").shift()),e.split(":").slice(1)]):[]}_title(e){return`${e[0].toUpperCase()}${e.slice(1)}`}_validate(e,t){for(let r in t=this._prepare(e,t))if(!this[`assert${t[r][1]}`].apply(this,[e,t[r][2].join(":")]))return{valid:!1,rule:t[r][0],error:this._error(t[r][0])};return{valid:!0,rule:"",error:""}}assert(e,t){if(Array.isArray(t))return this._validate(e,t);let r=Object.keys(t),s={valid:!0,fields:{}};for(let a=0;a<r.length;a++)s.fields[r[a]]=e.hasOwnProperty(r[a])?this._validate(e[r[a]],t[r[a]]):this._missing(),s.fields[r[a]].valid||(s.valid=!1);return s}assertAfter(e,t){return this._compare(e,t,"more",!1)}assertAfterOrEqual(e,t){return this._compare(e,t,"more",!0)}assertArray(e){return Array.isArray(e)}assertBefore(e,t){return this._compare(e,t,"less",!1)}assertBeforeOrEqual(e,t){return this._compare(e,t,"less",!0)}assertBoolean(e){return[!0,!1].includes(e)}assertDate(e){return e&&"[object Date]"===Object.prototype.toString.call(e)&&!isNaN(e)}assertDifferent(e,t){return e!=t}assertEndsWith(e,t){return this.assertString(e)&&e.endsWith(t)}assertEmail(e){return new RegExp("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?").test(String(e).toLowerCase())}assertFalsy(e){return[0,"0",!1,"false"].includes(e)}assertIn(e,t){return("string"==typeof t?t.split(","):t).includes(e)}assertInteger(e){return Number.isInteger(e)&&parseInt(e).toString()===e.toString()}assertJson(e){try{return"object"==typeof JSON.parse(e)}catch(e){return!1}}assertMax(e,t){return parseFloat(e)<=t}assertMin(e,t){return parseFloat(e)>=t}assertMaxLength(e,t){return"string"==typeof e&&e.length<=t}assertMinLength(e,t){return"string"==typeof e&&e.length>=t}assertNotIn(e,t){return!this.assertIn(e,t)}assertNumeric(e){return!isNaN(parseFloat(e))&&isFinite(e)}assertOptional(e){return[null,void 0,""].includes(e)}assertRegexMatch(e,t){return new RegExp(t).test(String(e))}assertRequired(e){return!this.assertOptional(e)}assertSame(e,t){return e==t}assertStartsWith(e,t){return this.assertString(e)&&e.startsWith(t)}assertString(e){return"string"==typeof e}assertTruthy(e){return[1,"1",!0,"true"].includes(e)}assertUrl(e){return new RegExp("^(https?:\\/\\/)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*(\\?[;&a-z\\d%_.~+=-]*)?(\\#[-a-z\\d_]*)?$").test(String(e).toLowerCase())}assertUuid(e){return new RegExp("^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$").test(String(e).toLowerCase())}rule(t,r){e.prototype[`assert${this._title(t)}`]=r}setErrorMessages(e){this.messages=e}setErrorMessage(e,t){this.messages[e]=t}setLocale(e){this.locale=e}setDefaultFieldName(e){this.default_field_name=e}}"undefined"!=typeof window&&(window.Iodine=new e),module.exports=e; | ||
//# sourceMappingURL=iodine.min.js.map |
@@ -1,2 +0,2 @@ | ||
class e{constructor(){this.locale=void 0,this.messages={after:"The date must be after: '[PARAM]'",afterOrEqual:"The date must be after or equal to: '[PARAM]'",array:"[FIELD] must be an array",before:"The date must be before: '[PARAM]'",beforeOrEqual:"The date must be before or equal to: '[PARAM]'",boolean:"[FIELD] must be true or false",date:"[FIELD] must be a date",different:"[FIELD] must be different to '[PARAM]'",endsWith:"[FIELD] must end with '[PARAM]'",email:"[FIELD] must be a valid email address",falsy:"[FIELD] must be a falsy value (false, 'false', 0 or '0')",in:"[FIELD] must be one of the following options: [PARAM]",integer:"[FIELD] must be an integer",json:"[FIELD] must be a parsable JSON object string",max:"[FIELD] must be less than or equal to [PARAM]",min:"[FIELD] must be greater than or equal to [PARAM]",maxLength:"[FIELD] must not be greater than '[PARAM]' in character length",minLength:"[FIELD] must not be less than '[PARAM]' character length",notIn:"[FIELD] must not be one of the following options: [PARAM]",numeric:"[FIELD] must be numeric",optional:"[FIELD] is optional",regexMatch:"[FIELD] must satisify the regular expression: [PARAM]",required:"[FIELD] must be present",same:"[FIELD] must be '[PARAM]'",startsWith:"[FIELD] must start with '[PARAM]'",string:"[FIELD] must be a string",truthy:"[FIELD] must be a truthy value (true, 'true', 1 or '1')",url:"[FIELD] must be a valid url",uuid:"[FIELD] must be a valid UUID"}}_compare(e,t,r,s=!1){return!!this.assertDate(e)&&!(!this.assertDate(t)&&!this.assertInteger(t))&&(t="number"==typeof t?t:t.getTime(),"less"===r&&s?e.getTime()<=t:"less"!==r||s?"more"===r&&s?e.getTime()>=t:"more"!==r||s?void 0:e.getTime()>t:e.getTime()<t)}_error(e,t){var r;let{param:s,field:a}="object"==typeof t?t:{param:t,field:void 0};const i=e.split(":");let n=i.shift();s=s||i.join(":"),["after","afterOrEqual","before","beforeOrEqual"].includes(n)&&(s=new Date(parseInt(s)).toLocaleTimeString(this.locale,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"numeric",hour12:!1}));let l=[null,void 0,""].includes(s)?this.messages[n]:this.messages[n].replace("[PARAM]",s);return[null,void 0,""].includes(a)?l.replace("[FIELD]",null!=(r=this.default_field_name)?r:"Value"):l.replace("[FIELD]",a)}_missing(){return{valid:!1,rule:"None",error:"Rules exist, but no value was provided to check"}}_prepare(e,t=[]){return t.length?"optional"===t[0]&&this.assertOptional(e)?[]:t.filter(e=>"optional"!==e).map(e=>[e,this._title(e.split(":").shift()),e.split(":").slice(1)]):[]}_title(e){return`${e[0].toUpperCase()}${e.slice(1)}`}_validate(e,t){for(let r in t=this._prepare(e,t))if(!this[`assert${t[r][1]}`].apply(this,[e,t[r][2].join(":")]))return{valid:!1,rule:t[r][0],error:this._error(t[r][0])};return{valid:!0,rule:"",error:""}}assert(e,t){if(Array.isArray(t))return this._validate(e,t);let r=Object.keys(t),s={valid:!0,fields:{}};for(let a=0;a<r.length;a++)s.fields[r[a]]=e.hasOwnProperty(r[a])?this._validate(e[r[a]],t[r[a]]):this._missing(),s.fields[r[a]].valid||(s.valid=!1);return s}assertAfter(e,t){return this._compare(e,t,"more",!1)}assertAfterOrEqual(e,t){return this._compare(e,t,"more",!0)}assertArray(e){return Array.isArray(e)}assertBefore(e,t){return this._compare(e,t,"less",!1)}assertBeforeOrEqual(e,t){return this._compare(e,t,"less",!0)}assertBoolean(e){return[!0,!1].includes(e)}assertDate(e){return e&&"[object Date]"===Object.prototype.toString.call(e)&&!isNaN(e)}assertDifferent(e,t){return e!=t}assertEndsWith(e,t){return this.assertString(e)&&e.endsWith(t)}assertEmail(e){return new RegExp("^[a-zA-Z0-9.!#$%&'+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:.[a-zA-Z0-9-]+)$").test(String(e).toLowerCase())}assertFalsy(e){return[0,"0",!1,"false"].includes(e)}assertIn(e,t){return("string"==typeof t?t.split(","):t).includes(e)}assertInteger(e){return Number.isInteger(e)&&parseInt(e).toString()===e.toString()}assertJson(e){try{return"object"==typeof JSON.parse(e)}catch(e){return!1}}assertMax(e,t){return parseFloat(e)<=t}assertMin(e,t){return parseFloat(e)>=t}assertMaxLength(e,t){return"string"==typeof e&&e.length<=t}assertMinLength(e,t){return"string"==typeof e&&e.length>=t}assertNotIn(e,t){return!this.assertIn(e,t)}assertNumeric(e){return!isNaN(parseFloat(e))&&isFinite(e)}assertOptional(e){return[null,void 0,""].includes(e)}assertRegexMatch(e,t){return new RegExp(t).test(String(e))}assertRequired(e){return!this.assertOptional(e)}assertSame(e,t){return e==t}assertStartsWith(e,t){return this.assertString(e)&&e.startsWith(t)}assertString(e){return"string"==typeof e}assertTruthy(e){return[1,"1",!0,"true"].includes(e)}assertUrl(e){return new RegExp("^(https?:\\/\\/)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*(\\?[;&a-z\\d%_.~+=-]*)?(\\#[-a-z\\d_]*)?$").test(String(e).toLowerCase())}assertUuid(e){return new RegExp("^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$").test(String(e).toLowerCase())}rule(t,r){e.prototype[`assert${this._title(t)}`]=r}setErrorMessages(e){this.messages=e}setErrorMessage(e,t){this.messages[e]=t}setLocale(e){this.locale=e}setDefaultFieldName(e){this.default_field_name=e}}"undefined"!=typeof window&&(window.Iodine=new e);export{e as default}; | ||
class e{constructor(){this.locale=void 0,this.messages={after:"The date must be after: '[PARAM]'",afterOrEqual:"The date must be after or equal to: '[PARAM]'",array:"[FIELD] must be an array",before:"The date must be before: '[PARAM]'",beforeOrEqual:"The date must be before or equal to: '[PARAM]'",boolean:"[FIELD] must be true or false",date:"[FIELD] must be a date",different:"[FIELD] must be different to '[PARAM]'",endsWith:"[FIELD] must end with '[PARAM]'",email:"[FIELD] must be a valid email address",falsy:"[FIELD] must be a falsy value (false, 'false', 0 or '0')",in:"[FIELD] must be one of the following options: [PARAM]",integer:"[FIELD] must be an integer",json:"[FIELD] must be a parsable JSON object string",max:"[FIELD] must be less than or equal to [PARAM]",min:"[FIELD] must be greater than or equal to [PARAM]",maxLength:"[FIELD] must not be greater than '[PARAM]' in character length",minLength:"[FIELD] must not be less than '[PARAM]' character length",notIn:"[FIELD] must not be one of the following options: [PARAM]",numeric:"[FIELD] must be numeric",optional:"[FIELD] is optional",regexMatch:"[FIELD] must satisify the regular expression: [PARAM]",required:"[FIELD] must be present",same:"[FIELD] must be '[PARAM]'",startsWith:"[FIELD] must start with '[PARAM]'",string:"[FIELD] must be a string",truthy:"[FIELD] must be a truthy value (true, 'true', 1 or '1')",url:"[FIELD] must be a valid url",uuid:"[FIELD] must be a valid UUID"}}_compare(e,t,r,s=!1){return!!this.assertDate(e)&&!(!this.assertDate(t)&&!this.assertInteger(t))&&(t="number"==typeof t?t:t.getTime(),"less"===r&&s?e.getTime()<=t:"less"!==r||s?"more"===r&&s?e.getTime()>=t:"more"!==r||s?void 0:e.getTime()>t:e.getTime()<t)}_error(e,t){var r;let{param:s,field:a}="object"==typeof t?t:{param:t,field:void 0};const i=e.split(":");let n=i.shift();s=s||i.join(":"),["after","afterOrEqual","before","beforeOrEqual"].includes(n)&&(s=new Date(parseInt(s)).toLocaleTimeString(this.locale,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"numeric",hour12:!1}));let l=[null,void 0,""].includes(s)?this.messages[n]:this.messages[n].replace("[PARAM]",s);return[null,void 0,""].includes(a)?l.replace("[FIELD]",null!=(r=this.default_field_name)?r:"Value"):l.replace("[FIELD]",a)}_missing(){return{valid:!1,rule:"None",error:"Rules exist, but no value was provided to check"}}_prepare(e,t=[]){return t.length?"optional"===t[0]&&this.assertOptional(e)?[]:t.filter(e=>"optional"!==e).map(e=>[e,this._title(e.split(":").shift()),e.split(":").slice(1)]):[]}_title(e){return`${e[0].toUpperCase()}${e.slice(1)}`}_validate(e,t){for(let r in t=this._prepare(e,t))if(!this[`assert${t[r][1]}`].apply(this,[e,t[r][2].join(":")]))return{valid:!1,rule:t[r][0],error:this._error(t[r][0])};return{valid:!0,rule:"",error:""}}assert(e,t){if(Array.isArray(t))return this._validate(e,t);let r=Object.keys(t),s={valid:!0,fields:{}};for(let a=0;a<r.length;a++)s.fields[r[a]]=e.hasOwnProperty(r[a])?this._validate(e[r[a]],t[r[a]]):this._missing(),s.fields[r[a]].valid||(s.valid=!1);return s}assertAfter(e,t){return this._compare(e,t,"more",!1)}assertAfterOrEqual(e,t){return this._compare(e,t,"more",!0)}assertArray(e){return Array.isArray(e)}assertBefore(e,t){return this._compare(e,t,"less",!1)}assertBeforeOrEqual(e,t){return this._compare(e,t,"less",!0)}assertBoolean(e){return[!0,!1].includes(e)}assertDate(e){return e&&"[object Date]"===Object.prototype.toString.call(e)&&!isNaN(e)}assertDifferent(e,t){return e!=t}assertEndsWith(e,t){return this.assertString(e)&&e.endsWith(t)}assertEmail(e){return new RegExp("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?").test(String(e).toLowerCase())}assertFalsy(e){return[0,"0",!1,"false"].includes(e)}assertIn(e,t){return("string"==typeof t?t.split(","):t).includes(e)}assertInteger(e){return Number.isInteger(e)&&parseInt(e).toString()===e.toString()}assertJson(e){try{return"object"==typeof JSON.parse(e)}catch(e){return!1}}assertMax(e,t){return parseFloat(e)<=t}assertMin(e,t){return parseFloat(e)>=t}assertMaxLength(e,t){return"string"==typeof e&&e.length<=t}assertMinLength(e,t){return"string"==typeof e&&e.length>=t}assertNotIn(e,t){return!this.assertIn(e,t)}assertNumeric(e){return!isNaN(parseFloat(e))&&isFinite(e)}assertOptional(e){return[null,void 0,""].includes(e)}assertRegexMatch(e,t){return new RegExp(t).test(String(e))}assertRequired(e){return!this.assertOptional(e)}assertSame(e,t){return e==t}assertStartsWith(e,t){return this.assertString(e)&&e.startsWith(t)}assertString(e){return"string"==typeof e}assertTruthy(e){return[1,"1",!0,"true"].includes(e)}assertUrl(e){return new RegExp("^(https?:\\/\\/)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*(\\?[;&a-z\\d%_.~+=-]*)?(\\#[-a-z\\d_]*)?$").test(String(e).toLowerCase())}assertUuid(e){return new RegExp("^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$").test(String(e).toLowerCase())}rule(t,r){e.prototype[`assert${this._title(t)}`]=r}setErrorMessages(e){this.messages=e}setErrorMessage(e,t){this.messages[e]=t}setLocale(e){this.locale=e}setDefaultFieldName(e){this.default_field_name=e}}"undefined"!=typeof window&&(window.Iodine=new e);export{e as default}; | ||
//# sourceMappingURL=iodine.min.modern.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e||self).iodine=t()}(this,function(){class e{constructor(){this.locale=void 0,this.messages={after:"The date must be after: '[PARAM]'",afterOrEqual:"The date must be after or equal to: '[PARAM]'",array:"[FIELD] must be an array",before:"The date must be before: '[PARAM]'",beforeOrEqual:"The date must be before or equal to: '[PARAM]'",boolean:"[FIELD] must be true or false",date:"[FIELD] must be a date",different:"[FIELD] must be different to '[PARAM]'",endsWith:"[FIELD] must end with '[PARAM]'",email:"[FIELD] must be a valid email address",falsy:"[FIELD] must be a falsy value (false, 'false', 0 or '0')",in:"[FIELD] must be one of the following options: [PARAM]",integer:"[FIELD] must be an integer",json:"[FIELD] must be a parsable JSON object string",max:"[FIELD] must be less than or equal to [PARAM]",min:"[FIELD] must be greater than or equal to [PARAM]",maxLength:"[FIELD] must not be greater than '[PARAM]' in character length",minLength:"[FIELD] must not be less than '[PARAM]' character length",notIn:"[FIELD] must not be one of the following options: [PARAM]",numeric:"[FIELD] must be numeric",optional:"[FIELD] is optional",regexMatch:"[FIELD] must satisify the regular expression: [PARAM]",required:"[FIELD] must be present",same:"[FIELD] must be '[PARAM]'",startsWith:"[FIELD] must start with '[PARAM]'",string:"[FIELD] must be a string",truthy:"[FIELD] must be a truthy value (true, 'true', 1 or '1')",url:"[FIELD] must be a valid url",uuid:"[FIELD] must be a valid UUID"}}_compare(e,t,r,s=!1){return!!this.assertDate(e)&&!(!this.assertDate(t)&&!this.assertInteger(t))&&(t="number"==typeof t?t:t.getTime(),"less"===r&&s?e.getTime()<=t:"less"!==r||s?"more"===r&&s?e.getTime()>=t:"more"!==r||s?void 0:e.getTime()>t:e.getTime()<t)}_error(e,t){let{param:r,field:s}="object"==typeof t?t:{param:t,field:void 0};const a=e.split(":");let i=a.shift();r=r||a.join(":"),["after","afterOrEqual","before","beforeOrEqual"].includes(i)&&(r=new Date(parseInt(r)).toLocaleTimeString(this.locale,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"numeric",hour12:!1}));let n=[null,void 0,""].includes(r)?this.messages[i]:this.messages[i].replace("[PARAM]",r);return[null,void 0,""].includes(s)?n.replace("[FIELD]",this.default_field_name??"Value"):n.replace("[FIELD]",s)}_missing(){return{valid:!1,rule:"None",error:"Rules exist, but no value was provided to check"}}_prepare(e,t=[]){return t.length?"optional"===t[0]&&this.assertOptional(e)?[]:t.filter(e=>"optional"!==e).map(e=>[e,this._title(e.split(":").shift()),e.split(":").slice(1)]):[]}_title(e){return`${e[0].toUpperCase()}${e.slice(1)}`}_validate(e,t){for(let r in t=this._prepare(e,t))if(!this[`assert${t[r][1]}`].apply(this,[e,t[r][2].join(":")]))return{valid:!1,rule:t[r][0],error:this._error(t[r][0])};return{valid:!0,rule:"",error:""}}assert(e,t){if(Array.isArray(t))return this._validate(e,t);let r=Object.keys(t),s={valid:!0,fields:{}};for(let a=0;a<r.length;a++)s.fields[r[a]]=e.hasOwnProperty(r[a])?this._validate(e[r[a]],t[r[a]]):this._missing(),s.fields[r[a]].valid||(s.valid=!1);return s}assertAfter(e,t){return this._compare(e,t,"more",!1)}assertAfterOrEqual(e,t){return this._compare(e,t,"more",!0)}assertArray(e){return Array.isArray(e)}assertBefore(e,t){return this._compare(e,t,"less",!1)}assertBeforeOrEqual(e,t){return this._compare(e,t,"less",!0)}assertBoolean(e){return[!0,!1].includes(e)}assertDate(e){return e&&"[object Date]"===Object.prototype.toString.call(e)&&!isNaN(e)}assertDifferent(e,t){return e!=t}assertEndsWith(e,t){return this.assertString(e)&&e.endsWith(t)}assertEmail(e){return new RegExp("^[a-zA-Z0-9.!#$%&'+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:.[a-zA-Z0-9-]+)$").test(String(e).toLowerCase())}assertFalsy(e){return[0,"0",!1,"false"].includes(e)}assertIn(e,t){return("string"==typeof t?t.split(","):t).includes(e)}assertInteger(e){return Number.isInteger(e)&&parseInt(e).toString()===e.toString()}assertJson(e){try{return"object"==typeof JSON.parse(e)}catch(e){return!1}}assertMax(e,t){return parseFloat(e)<=t}assertMin(e,t){return parseFloat(e)>=t}assertMaxLength(e,t){return"string"==typeof e&&e.length<=t}assertMinLength(e,t){return"string"==typeof e&&e.length>=t}assertNotIn(e,t){return!this.assertIn(e,t)}assertNumeric(e){return!isNaN(parseFloat(e))&&isFinite(e)}assertOptional(e){return[null,void 0,""].includes(e)}assertRegexMatch(e,t){return new RegExp(t).test(String(e))}assertRequired(e){return!this.assertOptional(e)}assertSame(e,t){return e==t}assertStartsWith(e,t){return this.assertString(e)&&e.startsWith(t)}assertString(e){return"string"==typeof e}assertTruthy(e){return[1,"1",!0,"true"].includes(e)}assertUrl(e){return new RegExp("^(https?:\\/\\/)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*(\\?[;&a-z\\d%_.~+=-]*)?(\\#[-a-z\\d_]*)?$").test(String(e).toLowerCase())}assertUuid(e){return new RegExp("^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$").test(String(e).toLowerCase())}rule(t,r){e.prototype[`assert${this._title(t)}`]=r}setErrorMessages(e){this.messages=e}setErrorMessage(e,t){this.messages[e]=t}setLocale(e){this.locale=e}setDefaultFieldName(e){this.default_field_name=e}}return"undefined"!=typeof window&&(window.Iodine=new e),e}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e||self).iodine=t()}(this,function(){class e{constructor(){this.locale=void 0,this.messages={after:"The date must be after: '[PARAM]'",afterOrEqual:"The date must be after or equal to: '[PARAM]'",array:"[FIELD] must be an array",before:"The date must be before: '[PARAM]'",beforeOrEqual:"The date must be before or equal to: '[PARAM]'",boolean:"[FIELD] must be true or false",date:"[FIELD] must be a date",different:"[FIELD] must be different to '[PARAM]'",endsWith:"[FIELD] must end with '[PARAM]'",email:"[FIELD] must be a valid email address",falsy:"[FIELD] must be a falsy value (false, 'false', 0 or '0')",in:"[FIELD] must be one of the following options: [PARAM]",integer:"[FIELD] must be an integer",json:"[FIELD] must be a parsable JSON object string",max:"[FIELD] must be less than or equal to [PARAM]",min:"[FIELD] must be greater than or equal to [PARAM]",maxLength:"[FIELD] must not be greater than '[PARAM]' in character length",minLength:"[FIELD] must not be less than '[PARAM]' character length",notIn:"[FIELD] must not be one of the following options: [PARAM]",numeric:"[FIELD] must be numeric",optional:"[FIELD] is optional",regexMatch:"[FIELD] must satisify the regular expression: [PARAM]",required:"[FIELD] must be present",same:"[FIELD] must be '[PARAM]'",startsWith:"[FIELD] must start with '[PARAM]'",string:"[FIELD] must be a string",truthy:"[FIELD] must be a truthy value (true, 'true', 1 or '1')",url:"[FIELD] must be a valid url",uuid:"[FIELD] must be a valid UUID"}}_compare(e,t,r,s=!1){return!!this.assertDate(e)&&!(!this.assertDate(t)&&!this.assertInteger(t))&&(t="number"==typeof t?t:t.getTime(),"less"===r&&s?e.getTime()<=t:"less"!==r||s?"more"===r&&s?e.getTime()>=t:"more"!==r||s?void 0:e.getTime()>t:e.getTime()<t)}_error(e,t){let{param:r,field:s}="object"==typeof t?t:{param:t,field:void 0};const a=e.split(":");let i=a.shift();r=r||a.join(":"),["after","afterOrEqual","before","beforeOrEqual"].includes(i)&&(r=new Date(parseInt(r)).toLocaleTimeString(this.locale,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"numeric",hour12:!1}));let n=[null,void 0,""].includes(r)?this.messages[i]:this.messages[i].replace("[PARAM]",r);return[null,void 0,""].includes(s)?n.replace("[FIELD]",this.default_field_name??"Value"):n.replace("[FIELD]",s)}_missing(){return{valid:!1,rule:"None",error:"Rules exist, but no value was provided to check"}}_prepare(e,t=[]){return t.length?"optional"===t[0]&&this.assertOptional(e)?[]:t.filter(e=>"optional"!==e).map(e=>[e,this._title(e.split(":").shift()),e.split(":").slice(1)]):[]}_title(e){return`${e[0].toUpperCase()}${e.slice(1)}`}_validate(e,t){for(let r in t=this._prepare(e,t))if(!this[`assert${t[r][1]}`].apply(this,[e,t[r][2].join(":")]))return{valid:!1,rule:t[r][0],error:this._error(t[r][0])};return{valid:!0,rule:"",error:""}}assert(e,t){if(Array.isArray(t))return this._validate(e,t);let r=Object.keys(t),s={valid:!0,fields:{}};for(let a=0;a<r.length;a++)s.fields[r[a]]=e.hasOwnProperty(r[a])?this._validate(e[r[a]],t[r[a]]):this._missing(),s.fields[r[a]].valid||(s.valid=!1);return s}assertAfter(e,t){return this._compare(e,t,"more",!1)}assertAfterOrEqual(e,t){return this._compare(e,t,"more",!0)}assertArray(e){return Array.isArray(e)}assertBefore(e,t){return this._compare(e,t,"less",!1)}assertBeforeOrEqual(e,t){return this._compare(e,t,"less",!0)}assertBoolean(e){return[!0,!1].includes(e)}assertDate(e){return e&&"[object Date]"===Object.prototype.toString.call(e)&&!isNaN(e)}assertDifferent(e,t){return e!=t}assertEndsWith(e,t){return this.assertString(e)&&e.endsWith(t)}assertEmail(e){return new RegExp("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?").test(String(e).toLowerCase())}assertFalsy(e){return[0,"0",!1,"false"].includes(e)}assertIn(e,t){return("string"==typeof t?t.split(","):t).includes(e)}assertInteger(e){return Number.isInteger(e)&&parseInt(e).toString()===e.toString()}assertJson(e){try{return"object"==typeof JSON.parse(e)}catch(e){return!1}}assertMax(e,t){return parseFloat(e)<=t}assertMin(e,t){return parseFloat(e)>=t}assertMaxLength(e,t){return"string"==typeof e&&e.length<=t}assertMinLength(e,t){return"string"==typeof e&&e.length>=t}assertNotIn(e,t){return!this.assertIn(e,t)}assertNumeric(e){return!isNaN(parseFloat(e))&&isFinite(e)}assertOptional(e){return[null,void 0,""].includes(e)}assertRegexMatch(e,t){return new RegExp(t).test(String(e))}assertRequired(e){return!this.assertOptional(e)}assertSame(e,t){return e==t}assertStartsWith(e,t){return this.assertString(e)&&e.startsWith(t)}assertString(e){return"string"==typeof e}assertTruthy(e){return[1,"1",!0,"true"].includes(e)}assertUrl(e){return new RegExp("^(https?:\\/\\/)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*(\\?[;&a-z\\d%_.~+=-]*)?(\\#[-a-z\\d_]*)?$").test(String(e).toLowerCase())}assertUuid(e){return new RegExp("^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$").test(String(e).toLowerCase())}rule(t,r){e.prototype[`assert${this._title(t)}`]=r}setErrorMessages(e){this.messages=e}setErrorMessage(e,t){this.messages[e]=t}setLocale(e){this.locale=e}setDefaultFieldName(e){this.default_field_name=e}}return"undefined"!=typeof window&&(window.Iodine=new e),e}); | ||
//# sourceMappingURL=iodine.min.umd.js.map |
{ | ||
"name": "@kingshott/iodine", | ||
"version": "8.0.0", | ||
"version": "8.1.0", | ||
"description": "A micro client-side validation library", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -8,5 +8,4 @@ <!-- Screenshot --> | ||
<p align="center"> | ||
<img src="resources/build.svg" alt="Build"> | ||
<img src="resources/version.svg" alt="Version"> | ||
<img src="resources/license.svg" alt="License"> | ||
<img src="https://img.shields.io/npm/v/@kingshott/iodine.svg" alt="Latest Release" /> | ||
<img src="https://img.shields.io/npm/l/@kingshott/iodine.svg" alt="License" /> | ||
</p> | ||
@@ -27,3 +26,3 @@ | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/@kingshott/iodine@8.0.0/dist/iodine.min.umd.js" defer></script> | ||
<script src="https://cdn.jsdelivr.net/npm/@kingshott/iodine@8.1.0/dist/iodine.min.umd.js" defer></script> | ||
``` | ||
@@ -37,2 +36,13 @@ | ||
## Promo | ||
I made [Lumeno](https://lumeno.dev) to help you centralize your IT résumé, project portfolio and blog content. It aids in building a following, allows you to discover other creatives, and gets you invited to relevant jobs that match your personal requirements, such as minimum salary, availability, location, commute distance, and much more... [sign up for free!](https://lumeno.dev) | ||
<!-- Screenshot --> | ||
<p align="center"> | ||
<a target="_blank" href="https://lumeno.dev"> | ||
<img src="resources/banner.png" alt="Lumeno" style="max-height: 170px"> | ||
</a> | ||
</p> | ||
## Usage | ||
@@ -39,0 +49,0 @@ |
@@ -278,3 +278,5 @@ /* | ||
{ | ||
return new RegExp("^[a-zA-Z0-9.!#$%&'+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:.[a-zA-Z0-9-]+)$").test(String(value).toLowerCase()); | ||
let regex = "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"; | ||
return new RegExp(regex).test(String(value).toLowerCase()); | ||
} | ||
@@ -281,0 +283,0 @@ |
@@ -152,2 +152,4 @@ /** | ||
expect(window.Iodine.assertEmail('m@i.com')).toBe(true); | ||
expect(window.Iodine.assertEmail('m@i.de')).toBe(true); | ||
expect(window.Iodine.assertEmail('m@i.co.uk')).toBe(true); | ||
expect(window.Iodine.assertEmail('😃@i.com')).toBe(false); | ||
@@ -154,0 +156,0 @@ expect(window.Iodine.assertEmail('')).toBe(false); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
382690
0
100
1148
320
0
18