From 158b3b5e017e832997feff9c1b67478a27518e4f Mon Sep 17 00:00:00 2001 From: Matt Kingshott <51963402+mattkingshott@users.noreply.github.com> Date: Sat, 4 Dec 2021 10:37:30 +0000 Subject: [PATCH] added support for server environments --- dist/iodine.min.esm.js | 2 +- dist/iodine.min.esm.js.map | 2 +- dist/iodine.min.js | 2 +- dist/iodine.min.js.map | 2 +- dist/iodine.min.modern.js | 2 +- dist/iodine.min.modern.js.map | 2 +- dist/iodine.min.umd.js | 2 +- dist/iodine.min.umd.js.map | 2 +- package.json | 18 +++++++++--------- resources/version.svg | 4 ++-- src/iodine.js | 3 ++- tests/test.js | 5 +++++ 12 files changed, 26 insertions(+), 20 deletions(-) diff --git a/dist/iodine.min.esm.js b/dist/iodine.min.esm.js index 86380f9..83b6f74 100644 --- a/dist/iodine.min.esm.js +++ b/dist/iodine.min.esm.js @@ -1,2 +1,2 @@ -function e(r,s,i){if(!r.s){if(i instanceof t){if(!i.s)return void(i.o=e.bind(null,r,s));1&s&&(s=i.s),i=i.v}if(i&&i.then)return void i.then(e.bind(null,r,s),e.bind(null,r,2));r.s=s,r.v=i;const n=r.o;n&&n(r)}}const t=function(){function t(){}return t.prototype.then=function(r,s){const i=new t,n=this.s;if(n){const t=1&n?r:s;if(t){try{e(i,1,t(this.v))}catch(t){e(i,2,t)}return i}return this}return this.o=function(t){try{const n=t.v;1&t.s?e(i,1,r?r(n):n):s?e(i,1,s(n)):e(i,2,n)}catch(t){e(i,2,t)}},i},t}();class r{constructor(){this.locale=void 0,this.messages=this._defaultMessages(),this.defaultFieldName="Value"}_dateCompare(e,t,r,s=!1){return!!this.isDate(e)&&!(!this.isDate(t)&&!this.isInteger(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()"optional"!==e).map(e=>[e,this._titleCase(e.split(":").shift()),e.split(":").slice(1)]):[]}_titleCase(e){return`${e[0].toUpperCase()}${e.slice(1)}`}addRule(e,t){r.prototype[`is${this._titleCase(e)}`]=t}asyncIs(r,s=[]){try{let i;const n=this,a=function(a,o,u){var l=[];for(var h in a)l.push(h);return function(r,s,i){var n,a,o=-1;return function u(l){try{for(;++o=t}isMaxLength(e,t){return"string"==typeof e&&e.length<=t}isMinLength(e,t){return"string"==typeof e&&e.length>=t}isNotIn(e,t){return!this.isIn(e,t)}isNumeric(e){return!isNaN(parseFloat(e))&&isFinite(e)}isOptional(e){return[null,void 0,""].includes(e)}isRegexMatch(e,t){return new RegExp(t).test(String(e))}isRequired(e){return!this.isOptional(e)}isSame(e,t){return e==t}isStartingWith(e,t){return this.isString(e)&&e.startsWith(t)}isString(e){return"string"==typeof e}isTruthy(e){return[1,"1",!0,"true"].includes(e)}isUrl(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())}isUuid(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())}is(e,t=[]){for(let r in t=this._prepare(e,t))if(!this[`is${t[r][1]}`].apply(this,[e,t[r][2].join(":")]))return t[r][0];return!0}isValid(e,t=[]){return!0===this.is(e,t)}setErrorMessages(e){this.messages=e}setErrorMessage(e,t){this.messages[e]=t}setLocale(e){this.locale=e}setDefaultFieldName(e){this.defaultFieldName=e}}window.Iodine=new r;export{r as Iodine}; +function e(r,s,i){if(!r.s){if(i instanceof t){if(!i.s)return void(i.o=e.bind(null,r,s));1&s&&(s=i.s),i=i.v}if(i&&i.then)return void i.then(e.bind(null,r,s),e.bind(null,r,2));r.s=s,r.v=i;const n=r.o;n&&n(r)}}const t=/*#__PURE__*/function(){function t(){}return t.prototype.then=function(r,s){const i=new t,n=this.s;if(n){const t=1&n?r:s;if(t){try{e(i,1,t(this.v))}catch(t){e(i,2,t)}return i}return this}return this.o=function(t){try{const n=t.v;1&t.s?e(i,1,r?r(n):n):s?e(i,1,s(n)):e(i,2,n)}catch(t){e(i,2,t)}},i},t}();class r{constructor(){this.locale=void 0,this.messages=this._defaultMessages(),this.defaultFieldName="Value"}_dateCompare(e,t,r,s=!1){return!!this.isDate(e)&&!(!this.isDate(t)&&!this.isInteger(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()"optional"!==e).map(e=>[e,this._titleCase(e.split(":").shift()),e.split(":").slice(1)]):[]}_titleCase(e){return`${e[0].toUpperCase()}${e.slice(1)}`}addRule(e,t){r.prototype[`is${this._titleCase(e)}`]=t}asyncIs(r,s=[]){try{let i;const n=this,a=function(a,o,u){var l=[];for(var h in a)l.push(h);return function(r,s,i){var n,a,o=-1;return function u(l){try{for(;++o=t}isMaxLength(e,t){return"string"==typeof e&&e.length<=t}isMinLength(e,t){return"string"==typeof e&&e.length>=t}isNotIn(e,t){return!this.isIn(e,t)}isNumeric(e){return!isNaN(parseFloat(e))&&isFinite(e)}isOptional(e){return[null,void 0,""].includes(e)}isRegexMatch(e,t){return new RegExp(t).test(String(e))}isRequired(e){return!this.isOptional(e)}isSame(e,t){return e==t}isStartingWith(e,t){return this.isString(e)&&e.startsWith(t)}isString(e){return"string"==typeof e}isTruthy(e){return[1,"1",!0,"true"].includes(e)}isUrl(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())}isUuid(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())}is(e,t=[]){for(let r in t=this._prepare(e,t))if(!this[`is${t[r][1]}`].apply(this,[e,t[r][2].join(":")]))return t[r][0];return!0}isValid(e,t=[]){return!0===this.is(e,t)}setErrorMessages(e){this.messages=e}setErrorMessage(e,t){this.messages[e]=t}setLocale(e){this.locale=e}setDefaultFieldName(e){this.defaultFieldName=e}}"undefined"!=typeof window&&(window.Iodine=new r);export{r as Iodine}; //# sourceMappingURL=iodine.min.esm.js.map diff --git a/dist/iodine.min.esm.js.map b/dist/iodine.min.esm.js.map index d36d65f..a6ebb25 100644 --- a/dist/iodine.min.esm.js.map +++ b/dist/iodine.min.esm.js.map @@ -1 +1 @@ -{"version":3,"file":"iodine.min.esm.js","sources":["../src/iodine.js"],"sourcesContent":["/*\n|--------------------------------------------------------------------------\n| Iodine - JavaScript Library\n|--------------------------------------------------------------------------\n|\n| This library contains a collection of useful validation rules that can\n| be used to quickly verify whether items meet certain conditions.\n|\n*/\nexport class Iodine {\n /**\n * Constructor.\n *\n */\n constructor() {\n this.locale = undefined;\n\n this.messages = this._defaultMessages();\n\n this.defaultFieldName = 'Value';\n }\n\n /**\n * @internal.\n *\n */\n _dateCompare(first, second, type, equals = false) {\n if (!this.isDate(first)) return false;\n\n if (!this.isDate(second) && !this.isInteger(second)) return false;\n\n second = typeof second === 'number' ? second : second.getTime();\n\n if (type === 'less' && equals) return first.getTime() <= second;\n if (type === 'less' && !equals) return first.getTime() < second;\n if (type === 'more' && equals) return first.getTime() >= second;\n if (type === 'more' && !equals) return first.getTime() > second;\n }\n\n /**\n * @internal.\n *\n */\n _defaultMessages() {\n return {\n after : `The date must be after: '[PARAM]'`,\n afterOrEqual : `The date must be after or equal to: '[PARAM]'`,\n array : `[FIELD] must be an array`,\n before : `The date must be before: '[PARAM]'`,\n beforeOrEqual : `The date must be before or equal to: '[PARAM]'`,\n boolean : `[FIELD] must be true or false`,\n date : `[FIELD] must be a date`,\n different : `[FIELD] must be different to '[PARAM]'`,\n endingWith : `[FIELD] must end with '[PARAM]'`,\n email : `[FIELD] must be a valid email address`,\n falsy : `[FIELD] must be a falsy value (false, 'false', 0 or '0')`,\n in : `[FIELD] must be one of the following options: [PARAM]`,\n integer : `[FIELD] must be an integer`,\n json : `[FIELD] must be a parsable JSON object string`,\n max : `[FIELD] must be less than or equal to [PARAM]`,\n min : `[FIELD] must be greater than or equal to [PARAM]`,\n maxLength : `[FIELD] must not be greater than '[PARAM]' in character length`,\n minLength : `[FIELD] must not be less than '[PARAM]' character length`,\n notIn : `[FIELD] must not be one of the following options: [PARAM]`,\n numeric : `[FIELD] must be numeric`,\n optional : `[FIELD] is optional`,\n regexMatch : `[FIELD] must satisify the regular expression: [PARAM]`,\n required : `[FIELD] must be present`,\n same : `[FIELD] must be '[PARAM]'`,\n startingWith : `[FIELD] must start with '[PARAM]'`,\n string : `[FIELD] must be a string`,\n truthy : `[FIELD] must be a truthy value (true, 'true', 1 or '1')`,\n url : `[FIELD] must be a valid url`,\n uuid : `[FIELD] must be a valid UUID`,\n };\n }\n\n /**\n * @internal.\n *\n */\n _prepare(value, rules = [])\n {\n if (!rules.length) return [];\n\n if (rules[0] === 'optional' && this.isOptional(value)) return [];\n\n return rules.filter(rule => rule !== 'optional')\n .map(rule => [rule, this._titleCase(rule.split(':').shift()), rule.split(':').slice(1)]);\n }\n\n /**\n * @internal.\n *\n */\n _titleCase(value)\n {\n return `${value[0].toUpperCase()}${value.slice(1)}`;\n }\n\n /**\n * Attach a custom validation rule to the library.\n *\n */\n addRule(name, closure) {\n Iodine.prototype[`is${this._titleCase(name)}`] = closure;\n }\n\n /**\n * Determine whether the given value meets the given synchronous or asynchronous rules.\n *\n */\n async asyncIs(value, rules = []) {\n for (let index in rules = this._prepare(value, rules)) {\n if (!await this[`is${rules[index][1]}`].apply(this, [value, rules[index][2].join(':')])) {\n return await rules[index][0];\n }\n }\n\n return true;\n }\n\n /**\n * Determine whether the given value meets the given rules.\n *\n */\n async asyncIsValid(value, rules = []) {\n return await this.asyncIs(value, rules) === true;\n }\n\n /**\n * Retrieve an error message for the given rule.\n *\n */\n getErrorMessage(rule, args = undefined) {\n let { param, field } = typeof args === 'object' ? args : { param: args, field: undefined };\n\n const chunks = rule.split(':');\n\n let key = chunks.shift();\n\n param = param || chunks.join(':');\n\n if (['after', 'afterOrEqual', 'before', 'beforeOrEqual'].includes(key)) {\n param = new Date(parseInt(param)).toLocaleTimeString(this.locale, {\n year : 'numeric',\n month : 'short',\n day : 'numeric',\n hour : '2-digit',\n minute : 'numeric',\n hour12 : false,\n });\n }\n\n let message = [null, undefined, ''].includes(param)\n ? this.messages[key]\n : this.messages[key].replace('[PARAM]', param);\n\n return [null, undefined, ''].includes(field)\n ? message.replace('[FIELD]', this.defaultFieldName)\n : message.replace('[FIELD]', field);\n }\n\n /**\n * Determine if the given date is after another given date.\n *\n */\n isAfter(value, after) {\n return this._dateCompare(value, after, 'more', false);\n }\n\n /**\n * Determine if the given date is after or equal to another given date.\n *\n */\n isAfterOrEqual(value, after) {\n return this._dateCompare(value, after, 'more', true);\n }\n\n /**\n * Determine if the given value is an array.\n *\n */\n isArray(value) {\n return Array.isArray(value);\n }\n\n /**\n * Determine if the given date is before another given date.\n *\n */\n isBefore(value, before) {\n return this._dateCompare(value, before, 'less', false);\n }\n\n /**\n * Determine if the given date is before or equal to another given date.\n *\n */\n isBeforeOrEqual(value, before) {\n return this._dateCompare(value, before, 'less', true);\n }\n\n /**\n * Determine if the given value is a boolean.\n *\n */\n isBoolean(value) {\n return [true, false].includes(value);\n }\n\n /**\n * Determine if the given value is a date object.\n *\n */\n isDate(value) {\n return (value && Object.prototype.toString.call(value) === '[object Date]' && !isNaN(value));\n }\n\n /**\n * Determine if the given value is different to another given value.\n *\n */\n isDifferent(value, different) {\n return value != different;\n }\n\n /**\n * Determine if the given value ends with another given value.\n *\n */\n isEndingWith(value, sub) {\n return this.isString(value) && value.endsWith(sub);\n }\n\n /**\n * Determine if the given value is a valid email address.\n *\n */\n isEmail(value) {\n return new RegExp(\"^\\\\S+@\\\\S+[\\\\.][0-9a-z]+$\").test(String(value).toLowerCase());\n }\n\n /**\n * Determine if the given value is falsy.\n *\n */\n isFalsy(value) {\n return [0, '0', false, 'false'].includes(value);\n }\n\n /**\n * Determine if the given value is within the given array of options.\n *\n */\n isIn(value, options) {\n return (typeof options === 'string' ? options.split(',') : options).includes(value);\n }\n\n /**\n * Determine if the given value is an integer.\n *\n */\n isInteger(value) {\n return Number.isInteger(value) && parseInt(value).toString() === value.toString();\n }\n\n /**\n * Determine if the given value is a JSON string.\n *\n */\n isJson(value) {\n try {\n return typeof JSON.parse(value) === 'object';\n } catch (e) {\n return false;\n }\n }\n\n /**\n * Determine if the given number is less than or equal to the maximum limit.\n *\n */\n isMax(value, limit) {\n return parseFloat(value) <= limit;\n }\n\n /**\n * Determine if the given number is greater than or equal to the minimum limit.\n *\n */\n isMin(value, limit) {\n return parseFloat(value) >= limit;\n }\n\n /**\n * Determine if the given value string length is less than or equal to the maximum limit.\n *\n */\n isMaxLength(value, limit) {\n return typeof value === 'string' ? value.length <= limit : false;\n }\n\n /**\n * Determine if the given value string length is greater than or equal to the minimum limit.\n *\n */\n isMinLength(value, limit) {\n return typeof value === 'string' ? value.length >= limit : false;\n }\n\n /**\n * Determine if the given value is not within the given array of options.\n *\n */\n isNotIn(value, options) {\n return !this.isIn(value, options);\n }\n\n /**\n * Determine if the given value is numeric (an integer or a float).\n *\n */\n isNumeric(value) {\n return !isNaN(parseFloat(value)) && isFinite(value);\n }\n\n /**\n * Determine if the given value is optional.\n *\n */\n isOptional(value) {\n return [null, undefined, ''].includes(value);\n }\n\n /**\n * Determine if the given value satisifies the given regular expression.\n *\n */\n isRegexMatch(value, expression) {\n return new RegExp(expression).test(String(value));\n }\n\n /**\n * Determine if the given value is present.\n *\n */\n isRequired(value) {\n return !this.isOptional(value);\n }\n\n /**\n * Determine if the given value is the same as another given value.\n *\n */\n isSame(value, same) {\n return value == same;\n }\n\n /**\n * Determine if the given value starts with another given value.\n *\n */\n isStartingWith(value, sub) {\n return this.isString(value) && value.startsWith(sub);\n }\n\n /**\n * Determine if the given value is a string.\n *\n */\n isString(value) {\n return typeof value === 'string';\n }\n\n /**\n * Determine if the given value is truthy.\n *\n */\n isTruthy(value) {\n return [1, '1', true, 'true'].includes(value);\n }\n\n /**\n * Determine if the given value is a valid URL.\n *\n */\n isUrl(value) {\n let regex = \"^(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_]*)?$\";\n\n return new RegExp(regex).test(String(value).toLowerCase());\n }\n\n /**\n * Determine if the given value is a valid UUID.\n *\n */\n isUuid(value) {\n let regex = \"^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$\";\n\n return new RegExp(regex).test(String(value).toLowerCase());\n }\n\n /**\n * Determine whether the given value meets the given rules.\n *\n */\n is(value, rules = []) {\n for (let index in rules = this._prepare(value, rules)) {\n if (!this[`is${rules[index][1]}`].apply(this, [value, rules[index][2].join(':')])) {\n return rules[index][0];\n }\n }\n\n return true;\n }\n\n /**\n * Determine whether the given value meets the given rules.\n *\n */\n isValid(value, rules = []) {\n return this.is(value, rules) === true;\n }\n\n /**\n * Replace the default error messages with a new set.\n *\n */\n setErrorMessages(messages) {\n this.messages = messages;\n }\n\n /**\n * Add or replace an error message.\n *\n */\n setErrorMessage(key, message) {\n this.messages[key] = message;\n }\n\n /**\n * Replace the default locale with a new value.\n *\n */\n setLocale(locale) {\n this.locale = locale;\n }\n\n /**\n * Replace the default field name with a new value.\n */\n setDefaultFieldName(fieldName) {\n this.defaultFieldName = fieldName;\n }\n}\n\n/**\n * Create an instance of the library.\n *\n */\nwindow.Iodine = new Iodine();\n"],"names":["pact","state","value","s","o","_settle","bind","v","then","observer","_Pact","prototype","onFulfilled","onRejected","result","this","callback","e","_this","Iodine","constructor","locale","undefined","messages","_defaultMessages","defaultFieldName","_dateCompare","first","second","type","equals","isDate","isInteger","getTime","after","afterOrEqual","array","before","beforeOrEqual","boolean","date","different","endingWith","email","falsy","in","integer","json","max","min","maxLength","minLength","notIn","numeric","optional","regexMatch","required","same","startingWith","string","truthy","url","uuid","_prepare","rules","length","isOptional","filter","rule","map","_titleCase","split","shift","slice","toUpperCase","addRule","name","closure","asyncIs","target","body","check","keys","key","push","reject","i","_cycle","thenable","index","apply","join","asyncIsValid","getErrorMessage","args","param","field","chunks","includes","Date","parseInt","toLocaleTimeString","year","month","day","hour","minute","hour12","message","replace","isAfter","isAfterOrEqual","isArray","Array","isBefore","isBeforeOrEqual","isBoolean","Object","toString","call","isNaN","isDifferent","isEndingWith","sub","isString","endsWith","isEmail","RegExp","test","String","toLowerCase","isFalsy","isIn","options","Number","isJson","JSON","parse","isMax","limit","parseFloat","isMin","isMaxLength","isMinLength","isNotIn","isNumeric","isFinite","isRegexMatch","expression","isRequired","isSame","isStartingWith","startsWith","isTruthy","isUrl","isUuid","is","isValid","setErrorMessages","setErrorMessage","setLocale","setDefaultFieldName","fieldName","window"],"mappings":"AAuCO,WAAiBA,EAAMC,EAAOC,GACpC,IAAKF,EAAKG,EAAG,CACZ,GAAID,eAAwB,CAC3B,IAAIA,EAAMC,EAOT,YADAD,EAAME,EAAIC,EAAQC,KAAK,KAAMN,EAAMC,IALvB,EAARA,IACHA,EAAQC,EAAMC,GAEfD,EAAQA,EAAMK,EAMhB,GAAIL,GAASA,EAAMM,KAElB,YADAN,EAAMM,KAAKH,EAAQC,KAAK,KAAMN,EAAMC,GAAQI,EAAQC,KAAK,KAAMN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------------------------------------------\n| Iodine - JavaScript Library\n|--------------------------------------------------------------------------\n|\n| This library contains a collection of useful validation rules that can\n| be used to quickly verify whether items meet certain conditions.\n|\n*/\nexport class Iodine {\n /**\n * Constructor.\n *\n */\n constructor() {\n this.locale = undefined;\n\n this.messages = this._defaultMessages();\n\n this.defaultFieldName = 'Value';\n }\n\n /**\n * @internal.\n *\n */\n _dateCompare(first, second, type, equals = false) {\n if (!this.isDate(first)) return false;\n\n if (!this.isDate(second) && !this.isInteger(second)) return false;\n\n second = typeof second === 'number' ? second : second.getTime();\n\n if (type === 'less' && equals) return first.getTime() <= second;\n if (type === 'less' && !equals) return first.getTime() < second;\n if (type === 'more' && equals) return first.getTime() >= second;\n if (type === 'more' && !equals) return first.getTime() > second;\n }\n\n /**\n * @internal.\n *\n */\n _defaultMessages() {\n return {\n after : `The date must be after: '[PARAM]'`,\n afterOrEqual : `The date must be after or equal to: '[PARAM]'`,\n array : `[FIELD] must be an array`,\n before : `The date must be before: '[PARAM]'`,\n beforeOrEqual : `The date must be before or equal to: '[PARAM]'`,\n boolean : `[FIELD] must be true or false`,\n date : `[FIELD] must be a date`,\n different : `[FIELD] must be different to '[PARAM]'`,\n endingWith : `[FIELD] must end with '[PARAM]'`,\n email : `[FIELD] must be a valid email address`,\n falsy : `[FIELD] must be a falsy value (false, 'false', 0 or '0')`,\n in : `[FIELD] must be one of the following options: [PARAM]`,\n integer : `[FIELD] must be an integer`,\n json : `[FIELD] must be a parsable JSON object string`,\n max : `[FIELD] must be less than or equal to [PARAM]`,\n min : `[FIELD] must be greater than or equal to [PARAM]`,\n maxLength : `[FIELD] must not be greater than '[PARAM]' in character length`,\n minLength : `[FIELD] must not be less than '[PARAM]' character length`,\n notIn : `[FIELD] must not be one of the following options: [PARAM]`,\n numeric : `[FIELD] must be numeric`,\n optional : `[FIELD] is optional`,\n regexMatch : `[FIELD] must satisify the regular expression: [PARAM]`,\n required : `[FIELD] must be present`,\n same : `[FIELD] must be '[PARAM]'`,\n startingWith : `[FIELD] must start with '[PARAM]'`,\n string : `[FIELD] must be a string`,\n truthy : `[FIELD] must be a truthy value (true, 'true', 1 or '1')`,\n url : `[FIELD] must be a valid url`,\n uuid : `[FIELD] must be a valid UUID`,\n };\n }\n\n /**\n * @internal.\n *\n */\n _prepare(value, rules = []) {\n if (!rules.length) return [];\n\n if (rules[0] === 'optional' && this.isOptional(value)) return [];\n\n return rules.filter(rule => rule !== 'optional')\n .map(rule => [rule, this._titleCase(rule.split(':').shift()), rule.split(':').slice(1)]);\n }\n\n /**\n * @internal.\n *\n */\n _titleCase(value) {\n return `${value[0].toUpperCase()}${value.slice(1)}`;\n }\n\n /**\n * Attach a custom validation rule to the library.\n *\n */\n addRule(name, closure) {\n Iodine.prototype[`is${this._titleCase(name)}`] = closure;\n }\n\n /**\n * Determine whether the given value meets the given synchronous or asynchronous rules.\n *\n */\n async asyncIs(value, rules = []) {\n for (let index in rules = this._prepare(value, rules)) {\n if (!await this[`is${rules[index][1]}`].apply(this, [value, rules[index][2].join(':')])) {\n return await rules[index][0];\n }\n }\n\n return true;\n }\n\n /**\n * Determine whether the given value meets the given rules.\n *\n */\n async asyncIsValid(value, rules = []) {\n return await this.asyncIs(value, rules) === true;\n }\n\n /**\n * Retrieve an error message for the given rule.\n *\n */\n getErrorMessage(rule, args = undefined) {\n let { param, field } = typeof args === 'object' ? args : { param: args, field: undefined };\n\n const chunks = rule.split(':');\n\n let key = chunks.shift();\n\n param = param || chunks.join(':');\n\n if (['after', 'afterOrEqual', 'before', 'beforeOrEqual'].includes(key)) {\n param = new Date(parseInt(param)).toLocaleTimeString(this.locale, {\n year : 'numeric',\n month : 'short',\n day : 'numeric',\n hour : '2-digit',\n minute : 'numeric',\n hour12 : false,\n });\n }\n\n let message = [null, undefined, ''].includes(param)\n ? this.messages[key]\n : this.messages[key].replace('[PARAM]', param);\n\n return [null, undefined, ''].includes(field)\n ? message.replace('[FIELD]', this.defaultFieldName)\n : message.replace('[FIELD]', field);\n }\n\n /**\n * Determine if the given date is after another given date.\n *\n */\n isAfter(value, after) {\n return this._dateCompare(value, after, 'more', false);\n }\n\n /**\n * Determine if the given date is after or equal to another given date.\n *\n */\n isAfterOrEqual(value, after) {\n return this._dateCompare(value, after, 'more', true);\n }\n\n /**\n * Determine if the given value is an array.\n *\n */\n isArray(value) {\n return Array.isArray(value);\n }\n\n /**\n * Determine if the given date is before another given date.\n *\n */\n isBefore(value, before) {\n return this._dateCompare(value, before, 'less', false);\n }\n\n /**\n * Determine if the given date is before or equal to another given date.\n *\n */\n isBeforeOrEqual(value, before) {\n return this._dateCompare(value, before, 'less', true);\n }\n\n /**\n * Determine if the given value is a boolean.\n *\n */\n isBoolean(value) {\n return [true, false].includes(value);\n }\n\n /**\n * Determine if the given value is a date object.\n *\n */\n isDate(value) {\n return (value && Object.prototype.toString.call(value) === '[object Date]' && !isNaN(value));\n }\n\n /**\n * Determine if the given value is different to another given value.\n *\n */\n isDifferent(value, different) {\n return value != different;\n }\n\n /**\n * Determine if the given value ends with another given value.\n *\n */\n isEndingWith(value, sub) {\n return this.isString(value) && value.endsWith(sub);\n }\n\n /**\n * Determine if the given value is a valid email address.\n *\n */\n isEmail(value) {\n return new RegExp(\"^\\\\S+@\\\\S+[\\\\.][0-9a-z]+$\").test(String(value).toLowerCase());\n }\n\n /**\n * Determine if the given value is falsy.\n *\n */\n isFalsy(value) {\n return [0, '0', false, 'false'].includes(value);\n }\n\n /**\n * Determine if the given value is within the given array of options.\n *\n */\n isIn(value, options) {\n return (typeof options === 'string' ? options.split(',') : options).includes(value);\n }\n\n /**\n * Determine if the given value is an integer.\n *\n */\n isInteger(value) {\n return Number.isInteger(value) && parseInt(value).toString() === value.toString();\n }\n\n /**\n * Determine if the given value is a JSON string.\n *\n */\n isJson(value) {\n try {\n return typeof JSON.parse(value) === 'object';\n } catch (e) {\n return false;\n }\n }\n\n /**\n * Determine if the given number is less than or equal to the maximum limit.\n *\n */\n isMax(value, limit) {\n return parseFloat(value) <= limit;\n }\n\n /**\n * Determine if the given number is greater than or equal to the minimum limit.\n *\n */\n isMin(value, limit) {\n return parseFloat(value) >= limit;\n }\n\n /**\n * Determine if the given value string length is less than or equal to the maximum limit.\n *\n */\n isMaxLength(value, limit) {\n return typeof value === 'string' ? value.length <= limit : false;\n }\n\n /**\n * Determine if the given value string length is greater than or equal to the minimum limit.\n *\n */\n isMinLength(value, limit) {\n return typeof value === 'string' ? value.length >= limit : false;\n }\n\n /**\n * Determine if the given value is not within the given array of options.\n *\n */\n isNotIn(value, options) {\n return !this.isIn(value, options);\n }\n\n /**\n * Determine if the given value is numeric (an integer or a float).\n *\n */\n isNumeric(value) {\n return !isNaN(parseFloat(value)) && isFinite(value);\n }\n\n /**\n * Determine if the given value is optional.\n *\n */\n isOptional(value) {\n return [null, undefined, ''].includes(value);\n }\n\n /**\n * Determine if the given value satisifies the given regular expression.\n *\n */\n isRegexMatch(value, expression) {\n return new RegExp(expression).test(String(value));\n }\n\n /**\n * Determine if the given value is present.\n *\n */\n isRequired(value) {\n return !this.isOptional(value);\n }\n\n /**\n * Determine if the given value is the same as another given value.\n *\n */\n isSame(value, same) {\n return value == same;\n }\n\n /**\n * Determine if the given value starts with another given value.\n *\n */\n isStartingWith(value, sub) {\n return this.isString(value) && value.startsWith(sub);\n }\n\n /**\n * Determine if the given value is a string.\n *\n */\n isString(value) {\n return typeof value === 'string';\n }\n\n /**\n * Determine if the given value is truthy.\n *\n */\n isTruthy(value) {\n return [1, '1', true, 'true'].includes(value);\n }\n\n /**\n * Determine if the given value is a valid URL.\n *\n */\n isUrl(value) {\n let regex = \"^(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_]*)?$\";\n\n return new RegExp(regex).test(String(value).toLowerCase());\n }\n\n /**\n * Determine if the given value is a valid UUID.\n *\n */\n isUuid(value) {\n let regex = \"^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$\";\n\n return new RegExp(regex).test(String(value).toLowerCase());\n }\n\n /**\n * Determine whether the given value meets the given rules.\n *\n */\n is(value, rules = []) {\n for (let index in rules = this._prepare(value, rules)) {\n if (!this[`is${rules[index][1]}`].apply(this, [value, rules[index][2].join(':')])) {\n return rules[index][0];\n }\n }\n\n return true;\n }\n\n /**\n * Determine whether the given value meets the given rules.\n *\n */\n isValid(value, rules = []) {\n return this.is(value, rules) === true;\n }\n\n /**\n * Replace the default error messages with a new set.\n *\n */\n setErrorMessages(messages) {\n this.messages = messages;\n }\n\n /**\n * Add or replace an error message.\n *\n */\n setErrorMessage(key, message) {\n this.messages[key] = message;\n }\n\n /**\n * Replace the default locale with a new value.\n *\n */\n setLocale(locale) {\n this.locale = locale;\n }\n\n /**\n * Replace the default field name with a new value.\n *\n */\n setDefaultFieldName(fieldName) {\n this.defaultFieldName = fieldName;\n }\n}\n\n/**\n * Create an instance of the library.\n *\n */\nif(typeof window !== 'undefined') {\n window.Iodine = new Iodine();\n}\n"],"names":["pact","state","value","s","o","_settle","bind","v","then","observer","_Pact","prototype","onFulfilled","onRejected","result","this","callback","e","_this","Iodine","constructor","locale","undefined","messages","_defaultMessages","defaultFieldName","_dateCompare","first","second","type","equals","isDate","isInteger","getTime","after","afterOrEqual","array","before","beforeOrEqual","boolean","date","different","endingWith","email","falsy","in","integer","json","max","min","maxLength","minLength","notIn","numeric","optional","regexMatch","required","same","startingWith","string","truthy","url","uuid","_prepare","rules","length","isOptional","filter","rule","map","_titleCase","split","shift","slice","toUpperCase","addRule","name","closure","asyncIs","target","body","check","keys","key","push","reject","i","_cycle","thenable","index","apply","join","asyncIsValid","getErrorMessage","args","param","field","chunks","includes","Date","parseInt","toLocaleTimeString","year","month","day","hour","minute","hour12","message","replace","isAfter","isAfterOrEqual","isArray","Array","isBefore","isBeforeOrEqual","isBoolean","Object","toString","call","isNaN","isDifferent","isEndingWith","sub","isString","endsWith","isEmail","RegExp","test","String","toLowerCase","isFalsy","isIn","options","Number","isJson","JSON","parse","isMax","limit","parseFloat","isMin","isMaxLength","isMinLength","isNotIn","isNumeric","isFinite","isRegexMatch","expression","isRequired","isSame","isStartingWith","startsWith","isTruthy","isUrl","isUuid","is","isValid","setErrorMessages","setErrorMessage","setLocale","setDefaultFieldName","fieldName","window"],"mappings":"AAuCO,WAAiBA,EAAMC,EAAOC,GACpC,IAAKF,EAAKG,EAAG,CACZ,GAAID,eAAwB,CAC3B,IAAIA,EAAMC,EAOT,YADAD,EAAME,EAAIC,EAAQC,KAAK,KAAMN,EAAMC,IALvB,EAARA,IACHA,EAAQC,EAAMC,GAEfD,EAAQA,EAAMK,EAMhB,GAAIL,GAASA,EAAMM,KAElB,YADAN,EAAMM,KAAKH,EAAQC,KAAK,KAAMN,EAAMC,GAAQI,EAAQC,KAAK,KAAMN,EAAM,IAGtEA,EAAKG,EAAIF,EACTD,EAAKO,EAAIL,EACT,MAAMO,EAAWT,EAAKI,EAClBK,GACHA,EAAST,IA3DL,qBAA4B,WAClC,cAiCA,OAhCAU,EAAMC,UAAUH,KAAO,SAASI,EAAaC,GAC5C,MAAMC,EAAS,MACTb,EAAQc,KAAKZ,EACnB,GAAIF,EAAO,CACV,MAAMe,EAAmB,EAARf,EAAYW,EAAcC,EAC3C,GAAIG,EAAU,CACb,IACCX,EAAQS,EAAQ,EAAGE,EAASD,KAAKR,IAChC,MAAOU,GACRZ,EAAQS,EAAQ,EAAGG,GAEpB,OAAOH,EAEP,YAiBF,OAdAC,KAAKX,EAAI,SAASc,GACjB,IACC,MAAMhB,EAAQgB,EAAMX,EACN,EAAVW,EAAMf,EACTE,EAAQS,EAAQ,EAAGF,EAAcA,EAAYV,GAASA,GAC5CW,EACVR,EAAQS,EAAQ,EAAGD,EAAWX,IA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W6H,OAFC,6EAEaC,KAAKC,OAAO/H,GAAOgI,eAO9C0B,GAAG1J,EAAO8D,EAAQ,IAChB,IAAK,IAAIyB,KAASzB,EAAQjD,KAAKgD,SAAS7D,EAAO8D,GAC7C,IAAKjD,KAAM,KAAIiD,EAAMyB,GAAO,MAAMC,MAAM3E,KAAM,CAACb,EAAO8D,EAAMyB,GAAO,GAAGE,KAAK,OACzE,OAAO3B,EAAMyB,GAAO,GAIxB,SAOFoE,QAAQ3J,EAAO8D,EAAQ,IACrB,OAAiC,SAArB4F,GAAG1J,EAAO8D,GAOxB8F,iBAAiBvI,GACfR,KAAKQ,SAAWA,EAOlBwI,gBAAgB5E,EAAKyB,GACnB7F,KAAKQ,SAAS4D,GAAOyB,EAOvBoD,UAAU3I,GACRN,KAAKM,OAASA,EAOhB4I,oBAAoBC,GAClBnJ,KAAKU,iBAAmByI,GAQP,oBAAXC,SACRA,OAAOhJ,OAAS,IAAIA"} \ No newline at end of file diff --git a/dist/iodine.min.js b/dist/iodine.min.js index 3ac588b..1b13f82 100644 --- a/dist/iodine.min.js +++ b/dist/iodine.min.js @@ -1,2 +1,2 @@ -function e(r,s,i){if(!r.s){if(i instanceof t){if(!i.s)return void(i.o=e.bind(null,r,s));1&s&&(s=i.s),i=i.v}if(i&&i.then)return void i.then(e.bind(null,r,s),e.bind(null,r,2));r.s=s,r.v=i;const n=r.o;n&&n(r)}}const t=function(){function t(){}return t.prototype.then=function(r,s){const i=new t,n=this.s;if(n){const t=1&n?r:s;if(t){try{e(i,1,t(this.v))}catch(t){e(i,2,t)}return i}return this}return this.o=function(t){try{const n=t.v;1&t.s?e(i,1,r?r(n):n):s?e(i,1,s(n)):e(i,2,n)}catch(t){e(i,2,t)}},i},t}();class r{constructor(){this.locale=void 0,this.messages=this._defaultMessages(),this.defaultFieldName="Value"}_dateCompare(e,t,r,s=!1){return!!this.isDate(e)&&!(!this.isDate(t)&&!this.isInteger(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()"optional"!==e).map(e=>[e,this._titleCase(e.split(":").shift()),e.split(":").slice(1)]):[]}_titleCase(e){return`${e[0].toUpperCase()}${e.slice(1)}`}addRule(e,t){r.prototype[`is${this._titleCase(e)}`]=t}asyncIs(r,s=[]){try{let i;const n=this,a=function(a,o,u){var l=[];for(var h in a)l.push(h);return function(r,s,i){var n,a,o=-1;return function u(l){try{for(;++o=t}isMaxLength(e,t){return"string"==typeof e&&e.length<=t}isMinLength(e,t){return"string"==typeof e&&e.length>=t}isNotIn(e,t){return!this.isIn(e,t)}isNumeric(e){return!isNaN(parseFloat(e))&&isFinite(e)}isOptional(e){return[null,void 0,""].includes(e)}isRegexMatch(e,t){return new RegExp(t).test(String(e))}isRequired(e){return!this.isOptional(e)}isSame(e,t){return e==t}isStartingWith(e,t){return this.isString(e)&&e.startsWith(t)}isString(e){return"string"==typeof e}isTruthy(e){return[1,"1",!0,"true"].includes(e)}isUrl(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())}isUuid(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())}is(e,t=[]){for(let r in t=this._prepare(e,t))if(!this[`is${t[r][1]}`].apply(this,[e,t[r][2].join(":")]))return t[r][0];return!0}isValid(e,t=[]){return!0===this.is(e,t)}setErrorMessages(e){this.messages=e}setErrorMessage(e,t){this.messages[e]=t}setLocale(e){this.locale=e}setDefaultFieldName(e){this.defaultFieldName=e}}window.Iodine=new r,exports.Iodine=r; +function e(r,s,i){if(!r.s){if(i instanceof t){if(!i.s)return void(i.o=e.bind(null,r,s));1&s&&(s=i.s),i=i.v}if(i&&i.then)return void i.then(e.bind(null,r,s),e.bind(null,r,2));r.s=s,r.v=i;const n=r.o;n&&n(r)}}const t=/*#__PURE__*/function(){function t(){}return t.prototype.then=function(r,s){const i=new t,n=this.s;if(n){const t=1&n?r:s;if(t){try{e(i,1,t(this.v))}catch(t){e(i,2,t)}return i}return this}return this.o=function(t){try{const n=t.v;1&t.s?e(i,1,r?r(n):n):s?e(i,1,s(n)):e(i,2,n)}catch(t){e(i,2,t)}},i},t}();class r{constructor(){this.locale=void 0,this.messages=this._defaultMessages(),this.defaultFieldName="Value"}_dateCompare(e,t,r,s=!1){return!!this.isDate(e)&&!(!this.isDate(t)&&!this.isInteger(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()"optional"!==e).map(e=>[e,this._titleCase(e.split(":").shift()),e.split(":").slice(1)]):[]}_titleCase(e){return`${e[0].toUpperCase()}${e.slice(1)}`}addRule(e,t){r.prototype[`is${this._titleCase(e)}`]=t}asyncIs(r,s=[]){try{let i;const n=this,a=function(a,o,u){var l=[];for(var h in a)l.push(h);return function(r,s,i){var n,a,o=-1;return function u(l){try{for(;++o=t}isMaxLength(e,t){return"string"==typeof e&&e.length<=t}isMinLength(e,t){return"string"==typeof e&&e.length>=t}isNotIn(e,t){return!this.isIn(e,t)}isNumeric(e){return!isNaN(parseFloat(e))&&isFinite(e)}isOptional(e){return[null,void 0,""].includes(e)}isRegexMatch(e,t){return new RegExp(t).test(String(e))}isRequired(e){return!this.isOptional(e)}isSame(e,t){return e==t}isStartingWith(e,t){return this.isString(e)&&e.startsWith(t)}isString(e){return"string"==typeof e}isTruthy(e){return[1,"1",!0,"true"].includes(e)}isUrl(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())}isUuid(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())}is(e,t=[]){for(let r in t=this._prepare(e,t))if(!this[`is${t[r][1]}`].apply(this,[e,t[r][2].join(":")]))return t[r][0];return!0}isValid(e,t=[]){return!0===this.is(e,t)}setErrorMessages(e){this.messages=e}setErrorMessage(e,t){this.messages[e]=t}setLocale(e){this.locale=e}setDefaultFieldName(e){this.defaultFieldName=e}}"undefined"!=typeof window&&(window.Iodine=new r),exports.Iodine=r; //# sourceMappingURL=iodine.min.js.map diff --git a/dist/iodine.min.js.map b/dist/iodine.min.js.map index 8782b4e..7e2e2cb 100644 --- a/dist/iodine.min.js.map +++ b/dist/iodine.min.js.map @@ -1 +1 @@ -{"version":3,"file":"iodine.min.js","sources":["../src/iodine.js"],"sourcesContent":["/*\n|--------------------------------------------------------------------------\n| Iodine - JavaScript Library\n|--------------------------------------------------------------------------\n|\n| This library contains a collection of useful validation rules that can\n| be used to quickly verify whether items meet certain conditions.\n|\n*/\nexport class Iodine {\n /**\n * Constructor.\n *\n */\n constructor() {\n this.locale = undefined;\n\n this.messages = this._defaultMessages();\n\n this.defaultFieldName = 'Value';\n }\n\n /**\n * @internal.\n *\n */\n _dateCompare(first, second, type, equals = false) {\n if (!this.isDate(first)) return false;\n\n if (!this.isDate(second) && !this.isInteger(second)) return false;\n\n second = typeof second === 'number' ? second : second.getTime();\n\n if (type === 'less' && equals) return first.getTime() <= second;\n if (type === 'less' && !equals) return first.getTime() < second;\n if (type === 'more' && equals) return first.getTime() >= second;\n if (type === 'more' && !equals) return first.getTime() > second;\n }\n\n /**\n * @internal.\n *\n */\n _defaultMessages() {\n return {\n after : `The date must be after: '[PARAM]'`,\n afterOrEqual : `The date must be after or equal to: '[PARAM]'`,\n array : `[FIELD] must be an array`,\n before : `The date must be before: '[PARAM]'`,\n beforeOrEqual : `The date must be before or equal to: '[PARAM]'`,\n boolean : `[FIELD] must be true or false`,\n date : `[FIELD] must be a date`,\n different : `[FIELD] must be different to '[PARAM]'`,\n endingWith : `[FIELD] must end with '[PARAM]'`,\n email : `[FIELD] must be a valid email address`,\n falsy : `[FIELD] must be a falsy value (false, 'false', 0 or '0')`,\n in : `[FIELD] must be one of the following options: [PARAM]`,\n integer : `[FIELD] must be an integer`,\n json : `[FIELD] must be a parsable JSON object string`,\n max : `[FIELD] must be less than or equal to [PARAM]`,\n min : `[FIELD] must be greater than or equal to [PARAM]`,\n maxLength : `[FIELD] must not be greater than '[PARAM]' in character length`,\n minLength : `[FIELD] must not be less than '[PARAM]' character length`,\n notIn : `[FIELD] must not be one of the following options: [PARAM]`,\n numeric : `[FIELD] must be numeric`,\n optional : `[FIELD] is optional`,\n regexMatch : `[FIELD] must satisify the regular expression: [PARAM]`,\n required : `[FIELD] must be present`,\n same : `[FIELD] must be '[PARAM]'`,\n startingWith : `[FIELD] must start with '[PARAM]'`,\n string : `[FIELD] must be a string`,\n truthy : `[FIELD] must be a truthy value (true, 'true', 1 or '1')`,\n url : `[FIELD] must be a valid url`,\n uuid : `[FIELD] must be a valid UUID`,\n };\n }\n\n /**\n * @internal.\n *\n */\n _prepare(value, rules = [])\n {\n if (!rules.length) return [];\n\n if (rules[0] === 'optional' && this.isOptional(value)) return [];\n\n return rules.filter(rule => rule !== 'optional')\n .map(rule => [rule, this._titleCase(rule.split(':').shift()), rule.split(':').slice(1)]);\n }\n\n /**\n * @internal.\n *\n */\n _titleCase(value)\n {\n return `${value[0].toUpperCase()}${value.slice(1)}`;\n }\n\n /**\n * Attach a custom validation rule to the library.\n *\n */\n addRule(name, closure) {\n Iodine.prototype[`is${this._titleCase(name)}`] = closure;\n }\n\n /**\n * Determine whether the given value meets the given synchronous or asynchronous rules.\n *\n */\n async asyncIs(value, rules = []) {\n for (let index in rules = this._prepare(value, rules)) {\n if (!await this[`is${rules[index][1]}`].apply(this, [value, rules[index][2].join(':')])) {\n return await rules[index][0];\n }\n }\n\n return true;\n }\n\n /**\n * Determine whether the given value meets the given rules.\n *\n */\n async asyncIsValid(value, rules = []) {\n return await this.asyncIs(value, rules) === true;\n }\n\n /**\n * Retrieve an error message for the given rule.\n *\n */\n getErrorMessage(rule, args = undefined) {\n let { param, field } = typeof args === 'object' ? args : { param: args, field: undefined };\n\n const chunks = rule.split(':');\n\n let key = chunks.shift();\n\n param = param || chunks.join(':');\n\n if (['after', 'afterOrEqual', 'before', 'beforeOrEqual'].includes(key)) {\n param = new Date(parseInt(param)).toLocaleTimeString(this.locale, {\n year : 'numeric',\n month : 'short',\n day : 'numeric',\n hour : '2-digit',\n minute : 'numeric',\n hour12 : false,\n });\n }\n\n let message = [null, undefined, ''].includes(param)\n ? this.messages[key]\n : this.messages[key].replace('[PARAM]', param);\n\n return [null, undefined, ''].includes(field)\n ? message.replace('[FIELD]', this.defaultFieldName)\n : message.replace('[FIELD]', field);\n }\n\n /**\n * Determine if the given date is after another given date.\n *\n */\n isAfter(value, after) {\n return this._dateCompare(value, after, 'more', false);\n }\n\n /**\n * Determine if the given date is after or equal to another given date.\n *\n */\n isAfterOrEqual(value, after) {\n return this._dateCompare(value, after, 'more', true);\n }\n\n /**\n * Determine if the given value is an array.\n *\n */\n isArray(value) {\n return Array.isArray(value);\n }\n\n /**\n * Determine if the given date is before another given date.\n *\n */\n isBefore(value, before) {\n return this._dateCompare(value, before, 'less', false);\n }\n\n /**\n * Determine if the given date is before or equal to another given date.\n *\n */\n isBeforeOrEqual(value, before) {\n return this._dateCompare(value, before, 'less', true);\n }\n\n /**\n * Determine if the given value is a boolean.\n *\n */\n isBoolean(value) {\n return [true, false].includes(value);\n }\n\n /**\n * Determine if the given value is a date object.\n *\n */\n isDate(value) {\n return (value && Object.prototype.toString.call(value) === '[object Date]' && !isNaN(value));\n }\n\n /**\n * Determine if the given value is different to another given value.\n *\n */\n isDifferent(value, different) {\n return value != different;\n }\n\n /**\n * Determine if the given value ends with another given value.\n *\n */\n isEndingWith(value, sub) {\n return this.isString(value) && value.endsWith(sub);\n }\n\n /**\n * Determine if the given value is a valid email address.\n *\n */\n isEmail(value) {\n return new RegExp(\"^\\\\S+@\\\\S+[\\\\.][0-9a-z]+$\").test(String(value).toLowerCase());\n }\n\n /**\n * Determine if the given value is falsy.\n *\n */\n isFalsy(value) {\n return [0, '0', false, 'false'].includes(value);\n }\n\n /**\n * Determine if the given value is within the given array of options.\n *\n */\n isIn(value, options) {\n return (typeof options === 'string' ? options.split(',') : options).includes(value);\n }\n\n /**\n * Determine if the given value is an integer.\n *\n */\n isInteger(value) {\n return Number.isInteger(value) && parseInt(value).toString() === value.toString();\n }\n\n /**\n * Determine if the given value is a JSON string.\n *\n */\n isJson(value) {\n try {\n return typeof JSON.parse(value) === 'object';\n } catch (e) {\n return false;\n }\n }\n\n /**\n * Determine if the given number is less than or equal to the maximum limit.\n *\n */\n isMax(value, limit) {\n return parseFloat(value) <= limit;\n }\n\n /**\n * Determine if the given number is greater than or equal to the minimum limit.\n *\n */\n isMin(value, limit) {\n return parseFloat(value) >= limit;\n }\n\n /**\n * Determine if the given value string length is less than or equal to the maximum limit.\n *\n */\n isMaxLength(value, limit) {\n return typeof value === 'string' ? value.length <= limit : false;\n }\n\n /**\n * Determine if the given value string length is greater than or equal to the minimum limit.\n *\n */\n isMinLength(value, limit) {\n return typeof value === 'string' ? value.length >= limit : false;\n }\n\n /**\n * Determine if the given value is not within the given array of options.\n *\n */\n isNotIn(value, options) {\n return !this.isIn(value, options);\n }\n\n /**\n * Determine if the given value is numeric (an integer or a float).\n *\n */\n isNumeric(value) {\n return !isNaN(parseFloat(value)) && isFinite(value);\n }\n\n /**\n * Determine if the given value is optional.\n *\n */\n isOptional(value) {\n return [null, undefined, ''].includes(value);\n }\n\n /**\n * Determine if the given value satisifies the given regular expression.\n *\n */\n isRegexMatch(value, expression) {\n return new RegExp(expression).test(String(value));\n }\n\n /**\n * Determine if the given value is present.\n *\n */\n isRequired(value) {\n return !this.isOptional(value);\n }\n\n /**\n * Determine if the given value is the same as another given value.\n *\n */\n isSame(value, same) {\n return value == same;\n }\n\n /**\n * Determine if the given value starts with another given value.\n *\n */\n isStartingWith(value, sub) {\n return this.isString(value) && value.startsWith(sub);\n }\n\n /**\n * Determine if the given value is a string.\n *\n */\n isString(value) {\n return typeof value === 'string';\n }\n\n /**\n * Determine if the given value is truthy.\n *\n */\n isTruthy(value) {\n return [1, '1', true, 'true'].includes(value);\n }\n\n /**\n * Determine if the given value is a valid URL.\n *\n */\n isUrl(value) {\n let regex = \"^(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_]*)?$\";\n\n return new RegExp(regex).test(String(value).toLowerCase());\n }\n\n /**\n * Determine if the given value is a valid UUID.\n *\n */\n isUuid(value) {\n let regex = \"^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$\";\n\n return new RegExp(regex).test(String(value).toLowerCase());\n }\n\n /**\n * Determine whether the given value meets the given rules.\n *\n */\n is(value, rules = []) {\n for (let index in rules = this._prepare(value, rules)) {\n if (!this[`is${rules[index][1]}`].apply(this, [value, rules[index][2].join(':')])) {\n return rules[index][0];\n }\n }\n\n return true;\n }\n\n /**\n * Determine whether the given value meets the given rules.\n *\n */\n isValid(value, rules = []) {\n return this.is(value, rules) === true;\n }\n\n /**\n * Replace the default error messages with a new set.\n *\n */\n setErrorMessages(messages) {\n this.messages = messages;\n }\n\n /**\n * Add or replace an error message.\n *\n */\n setErrorMessage(key, message) {\n this.messages[key] = message;\n }\n\n /**\n * Replace the default locale with a new value.\n *\n */\n setLocale(locale) {\n this.locale = locale;\n }\n\n /**\n * Replace the default field name with a new value.\n */\n setDefaultFieldName(fieldName) {\n this.defaultFieldName = fieldName;\n }\n}\n\n/**\n * Create an instance of the library.\n *\n */\nwindow.Iodine = new Iodine();\n"],"names":["pact","state","value","s","o","_settle","bind","v","then","observer","_Pact","prototype","onFulfilled","onRejected","result","this","callback","e","_this","Iodine","constructor","locale","undefined","messages","_defaultMessages","defaultFieldName","_dateCompare","first","second","type","equals","isDate","isInteger","getTime","after","afterOrEqual","array","before","beforeOrEqual","boolean","date","different","endingWith","email","falsy","in","integer","json","max","min","maxLength","minLength","notIn","numeric","optional","regexMatch","required","same","startingWith","string","truthy","url","uuid","_prepare","rules","length","isOptional","filter","rule","map","_titleCase","split","shift","slice","toUpperCase","addRule","name","closure","asyncIs","target","body","check","keys","key","push","reject","i","_cycle","thenable","index","apply","join","asyncIsValid","getErrorMessage","args","param","field","chunks","includes","Date","parseInt","toLocaleTimeString","year","month","day","hour","minute","hour12","message","replace","isAfter","isAfterOrEqual","isArray","Array","isBefore","isBeforeOrEqual","isBoolean","Object","toString","call","isNaN","isDifferent","isEndingWith","sub","isString","endsWith","isEmail","RegExp","test","String","toLowerCase","isFalsy","isIn","options","Number","isJson","JSON","parse","isMax","limit","parseFloat","isMin","isMaxLength","isMinLength","isNotIn","isNumeric","isFinite","isRegexMatch","expression","isRequired","isSame","isStartingWith","startsWith","isTruthy","isUrl","isUuid","is","isValid","setErrorMessages","setErrorMessage","setLocale","setDefaultFieldName","fieldName","window"],"mappings":"AAuCO,WAAiBA,EAAMC,EAAOC,GACpC,IAAKF,EAAKG,EAAG,CACZ,GAAID,eAAwB,CAC3B,IAAIA,EAAMC,EAOT,YADAD,EAAME,EAAIC,EAAQC,KAAK,KAAMN,EAAMC,IALvB,EAARA,IACHA,EAAQC,EA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BnJ,KAAKU,iBAAmByI,GAQ5BC,OAAOhJ,OAAS,IAAIA"} \ No newline at end of file +{"version":3,"file":"iodine.min.js","sources":["../src/iodine.js"],"sourcesContent":["/*\n|--------------------------------------------------------------------------\n| Iodine - JavaScript Library\n|--------------------------------------------------------------------------\n|\n| This library contains a collection of useful validation rules that can\n| be used to quickly verify whether items meet certain conditions.\n|\n*/\nexport class Iodine {\n /**\n * Constructor.\n *\n */\n constructor() {\n this.locale = undefined;\n\n this.messages = this._defaultMessages();\n\n this.defaultFieldName = 'Value';\n }\n\n /**\n * @internal.\n *\n */\n _dateCompare(first, second, type, equals = false) {\n if (!this.isDate(first)) return false;\n\n if (!this.isDate(second) && !this.isInteger(second)) return false;\n\n second = typeof second === 'number' ? second : second.getTime();\n\n if (type === 'less' && equals) return first.getTime() <= second;\n if (type === 'less' && !equals) return first.getTime() < second;\n if (type === 'more' && equals) return first.getTime() >= second;\n if (type === 'more' && !equals) return first.getTime() > second;\n }\n\n /**\n * @internal.\n *\n */\n _defaultMessages() {\n return {\n after : `The date must be after: '[PARAM]'`,\n afterOrEqual : `The date must be after or equal to: '[PARAM]'`,\n array : `[FIELD] must be an array`,\n before : `The date must be before: '[PARAM]'`,\n beforeOrEqual : `The date must be before or equal to: '[PARAM]'`,\n boolean : `[FIELD] must be true or false`,\n date : `[FIELD] must be a date`,\n different : `[FIELD] must be different to '[PARAM]'`,\n endingWith : `[FIELD] must end with '[PARAM]'`,\n email : `[FIELD] must be a valid email address`,\n falsy : `[FIELD] must be a falsy value (false, 'false', 0 or '0')`,\n in : `[FIELD] must be one of the following options: [PARAM]`,\n integer : `[FIELD] must be an integer`,\n json : `[FIELD] must be a parsable JSON object string`,\n max : `[FIELD] must be less than or equal to [PARAM]`,\n min : `[FIELD] must be greater than or equal to [PARAM]`,\n maxLength : `[FIELD] must not be greater than '[PARAM]' in character length`,\n minLength : `[FIELD] must not be less than '[PARAM]' character length`,\n notIn : `[FIELD] must not be one of the following options: [PARAM]`,\n numeric : `[FIELD] must be numeric`,\n optional : `[FIELD] is optional`,\n regexMatch : `[FIELD] must satisify the regular expression: [PARAM]`,\n required : `[FIELD] must be present`,\n same : `[FIELD] must be '[PARAM]'`,\n startingWith : `[FIELD] must start with '[PARAM]'`,\n string : `[FIELD] must be a string`,\n truthy : `[FIELD] must be a truthy value (true, 'true', 1 or '1')`,\n url : `[FIELD] must be a valid url`,\n uuid : `[FIELD] must be a valid UUID`,\n };\n }\n\n /**\n * @internal.\n *\n */\n _prepare(value, rules = []) {\n if (!rules.length) return [];\n\n if (rules[0] === 'optional' && this.isOptional(value)) return [];\n\n return rules.filter(rule => rule !== 'optional')\n .map(rule => [rule, this._titleCase(rule.split(':').shift()), rule.split(':').slice(1)]);\n }\n\n /**\n * @internal.\n *\n */\n _titleCase(value) {\n return `${value[0].toUpperCase()}${value.slice(1)}`;\n }\n\n /**\n * Attach a custom validation rule to the library.\n *\n */\n addRule(name, closure) {\n Iodine.prototype[`is${this._titleCase(name)}`] = closure;\n }\n\n /**\n * Determine whether the given value meets the given synchronous or asynchronous rules.\n *\n */\n async asyncIs(value, rules = []) {\n for (let index in rules = this._prepare(value, rules)) {\n if (!await this[`is${rules[index][1]}`].apply(this, [value, rules[index][2].join(':')])) {\n return await rules[index][0];\n }\n }\n\n return true;\n }\n\n /**\n * Determine whether the given value meets the given rules.\n *\n */\n async asyncIsValid(value, rules = []) {\n return await this.asyncIs(value, rules) === true;\n }\n\n /**\n * Retrieve an error message for the given rule.\n *\n */\n getErrorMessage(rule, args = undefined) {\n let { param, field } = typeof args === 'object' ? args : { param: args, field: undefined };\n\n const chunks = rule.split(':');\n\n let key = chunks.shift();\n\n param = param || chunks.join(':');\n\n if (['after', 'afterOrEqual', 'before', 'beforeOrEqual'].includes(key)) {\n param = new Date(parseInt(param)).toLocaleTimeString(this.locale, {\n year : 'numeric',\n month : 'short',\n day : 'numeric',\n hour : '2-digit',\n minute : 'numeric',\n hour12 : false,\n });\n }\n\n let message = [null, undefined, ''].includes(param)\n ? this.messages[key]\n : this.messages[key].replace('[PARAM]', param);\n\n return [null, undefined, ''].includes(field)\n ? message.replace('[FIELD]', this.defaultFieldName)\n : message.replace('[FIELD]', field);\n }\n\n /**\n * Determine if the given date is after another given date.\n *\n */\n isAfter(value, after) {\n return this._dateCompare(value, after, 'more', false);\n }\n\n /**\n * Determine if the given date is after or equal to another given date.\n *\n */\n isAfterOrEqual(value, after) {\n return this._dateCompare(value, after, 'more', true);\n }\n\n /**\n * Determine if the given value is an array.\n *\n */\n isArray(value) {\n return Array.isArray(value);\n }\n\n /**\n * Determine if the given date is before another given date.\n *\n */\n isBefore(value, before) {\n return this._dateCompare(value, before, 'less', false);\n }\n\n /**\n * Determine if the given date is before or equal to another given date.\n *\n */\n isBeforeOrEqual(value, before) {\n return this._dateCompare(value, before, 'less', true);\n }\n\n /**\n * Determine if the given value is a boolean.\n *\n */\n isBoolean(value) {\n return [true, false].includes(value);\n }\n\n /**\n * Determine if the given value is a date object.\n *\n */\n isDate(value) {\n return (value && Object.prototype.toString.call(value) === '[object Date]' && !isNaN(value));\n }\n\n /**\n * Determine if the given value is different to another given value.\n *\n */\n isDifferent(value, different) {\n return value != different;\n }\n\n /**\n * Determine if the given value ends with another given value.\n *\n */\n isEndingWith(value, sub) {\n return this.isString(value) && value.endsWith(sub);\n }\n\n /**\n * Determine if the given value is a valid email address.\n *\n */\n isEmail(value) {\n return new RegExp(\"^\\\\S+@\\\\S+[\\\\.][0-9a-z]+$\").test(String(value).toLowerCase());\n }\n\n /**\n * Determine if the given value is falsy.\n *\n */\n isFalsy(value) {\n return [0, '0', false, 'false'].includes(value);\n }\n\n /**\n * Determine if the given value is within the given array of options.\n *\n */\n isIn(value, options) {\n return (typeof options === 'string' ? options.split(',') : options).includes(value);\n }\n\n /**\n * Determine if the given value is an integer.\n *\n */\n isInteger(value) {\n return Number.isInteger(value) && parseInt(value).toString() === value.toString();\n }\n\n /**\n * Determine if the given value is a JSON string.\n *\n */\n isJson(value) {\n try {\n return typeof JSON.parse(value) === 'object';\n } catch (e) {\n return false;\n }\n }\n\n /**\n * Determine if the given number is less than or equal to the maximum limit.\n *\n */\n isMax(value, limit) {\n return parseFloat(value) <= limit;\n }\n\n /**\n * Determine if the given number is greater than or equal to the minimum limit.\n *\n */\n isMin(value, limit) {\n return parseFloat(value) >= limit;\n }\n\n /**\n * Determine if the given value string length is less than or equal to the maximum limit.\n *\n */\n isMaxLength(value, limit) {\n return typeof value === 'string' ? value.length <= limit : false;\n }\n\n /**\n * Determine if the given value string length is greater than or equal to the minimum limit.\n *\n */\n isMinLength(value, limit) {\n return typeof value === 'string' ? value.length >= limit : false;\n }\n\n /**\n * Determine if the given value is not within the given array of options.\n *\n */\n isNotIn(value, options) {\n return !this.isIn(value, options);\n }\n\n /**\n * Determine if the given value is numeric (an integer or a float).\n *\n */\n isNumeric(value) {\n return !isNaN(parseFloat(value)) && isFinite(value);\n }\n\n /**\n * Determine if the given value is optional.\n *\n */\n isOptional(value) {\n return [null, undefined, ''].includes(value);\n }\n\n /**\n * Determine if the given value satisifies the given regular expression.\n *\n */\n isRegexMatch(value, expression) {\n return new RegExp(expression).test(String(value));\n }\n\n /**\n * Determine if the given value is present.\n *\n */\n isRequired(value) {\n return !this.isOptional(value);\n }\n\n /**\n * Determine if the given value is the same as another given value.\n *\n */\n isSame(value, same) {\n return value == same;\n }\n\n /**\n * Determine if the given value starts with another given value.\n *\n */\n isStartingWith(value, sub) {\n return this.isString(value) && value.startsWith(sub);\n }\n\n /**\n * Determine if the given value is a string.\n *\n */\n isString(value) {\n return typeof value === 'string';\n }\n\n /**\n * Determine if the given value is truthy.\n *\n */\n isTruthy(value) {\n return [1, '1', true, 'true'].includes(value);\n }\n\n /**\n * Determine if the given value is a valid URL.\n *\n */\n isUrl(value) {\n let regex = \"^(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_]*)?$\";\n\n return new RegExp(regex).test(String(value).toLowerCase());\n }\n\n /**\n * Determine if the given value is a valid UUID.\n *\n */\n isUuid(value) {\n let regex = \"^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$\";\n\n return new RegExp(regex).test(String(value).toLowerCase());\n }\n\n /**\n * Determine whether the given value meets the given rules.\n *\n */\n is(value, rules = []) {\n for (let index in rules = this._prepare(value, rules)) {\n if (!this[`is${rules[index][1]}`].apply(this, [value, rules[index][2].join(':')])) {\n return rules[index][0];\n }\n }\n\n return true;\n }\n\n /**\n * Determine whether the given value meets the given rules.\n *\n */\n isValid(value, rules = []) {\n return this.is(value, rules) === true;\n }\n\n /**\n * Replace the default error messages with a new set.\n *\n */\n setErrorMessages(messages) {\n this.messages = messages;\n }\n\n /**\n * Add or replace an error message.\n *\n */\n setErrorMessage(key, message) {\n this.messages[key] = message;\n }\n\n /**\n * Replace the default locale with a new value.\n *\n */\n setLocale(locale) {\n this.locale = locale;\n }\n\n /**\n * Replace the default field name with a new value.\n *\n */\n setDefaultFieldName(fieldName) {\n this.defaultFieldName = fieldName;\n }\n}\n\n/**\n * Create an instance of the library.\n *\n */\nif(typeof window !== 'undefined') {\n window.Iodine = new Iodine();\n}\n"],"names":["pact","state","value","s","o","_settle","bind","v","then","observer","_Pact","prototype","onFulfilled","onRejected","result","this","callback","e","_this","Iodine","constructor","locale","undefined","messages","_defaultMessages","defaultFieldName","_dateCompare","first","second","type","equals","isDate","isInteger","getTime","after","afterOrEqual","array","before","beforeOrEqual","boolean","date","different","endingWith","email","falsy","in","integer","json","max","min","maxLength","minLength","notIn","numeric","optional","regexMatch","required","same","startingWith","string","truthy","url","uuid","_prepare","rules","length","isOptional","filter","rule","map","_titleCase","split","shift","slice","toUpperCase","addRule","name","closure","asyncIs","target","body","check","keys","key","push","reject","i","_cycle","thenable","index","apply","join","asyncIsValid","getErrorMessage","args","param","field","chunks","includes","Date","parseInt","toLocaleTimeString","year","month","day","hour","minute","hour12","message","replace","isAfter","isAfterOrEqual","isArray","Array","isBefore","isBeforeOrEqual","isBoolean","Object","toString","call","isNaN","isDifferent","isEndingWith","sub","isString","endsWith","isEmail","RegExp","test","String","toLowerCase","isFalsy","isIn","options","Number","isJson","JSON","parse","isMax","limit","parseFloat","isMin","isMaxLength","isMinLength","isNotIn","isNumeric","isFinite","isRegexMatch","expression","isRequired","isSame","isStartingWith","startsWith","isTruthy","isUrl","isUuid","is","isValid","setErrorMessages","setErrorMessage","setLocale","setDefaultFieldName","fieldName","window"],"mappings":"AAuCO,WAAiBA,EAAMC,EAAOC,GACpC,IAAKF,EAAKG,EAAG,CACZ,GAAID,eAAwB,CAC3B,IAAIA,EAAMC,EAOT,YADAD,EAAME,EAAIC,EAAQC,KAAK,KAAMN,EAAMC,IALvB,EAARA,IACHA,EAAQC,EAAMC,GAEfD,EAAQA,EAAMK,EAMhB,GAAIL,GAASA,EAAMM,KAElB,YADAN,EAAMM,KAAKH,EAAQC,KAAK,KAAMN,EAAMC,GAAQI,EAAQC,KAAK,KAAMN,EAAM,IAGtEA,EAAKG,EAAIF,EACTD,EAAKO,EAAIL,EACT,MAAMO,EAAWT,EAAKI,EAClBK,GACHA,EAAST,IA3DL,qBAA4B,WAClC,cAiCA,OAhCAU,EAAMC,UAAUH,KAAO,SAASI,EAAaC,GAC5C,MAAMC,EAAS,MACTb,EAAQc,KAAKZ,EACnB,GAAIF,EAAO,CACV,MAAMe,EAAmB,EAARf,EAAYW,EAAcC,EAC3C,GAAIG,EAAU,CACb,IACCX,EAAQS,EAAQ,EAAGE,EAASD,KAAKR,IAChC,MAAOU,GACRZ,EAAQS,EAAQ,EAAGG,GAEpB,OAAOH,EAEP,YAiBF,OAdAC,KAAKX,EAAI,SAASc,GACjB,IACC,MAAMh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KAAK,EAAM,QAAQgG,SAAShG,GAOzCwJ,MAAMxJ,GAGJ,WAAW6H,OAFC,yKAEaC,KAAKC,OAAO/H,GAAOgI,eAO9CyB,OAAOzJ,GAGL,WAAW6H,OAFC,6EAEaC,KAAKC,OAAO/H,GAAOgI,eAO9C0B,GAAG1J,EAAO8D,EAAQ,IAChB,IAAK,IAAIyB,KAASzB,EAAQjD,KAAKgD,SAAS7D,EAAO8D,GAC7C,IAAKjD,KAAM,KAAIiD,EAAMyB,GAAO,MAAMC,MAAM3E,KAAM,CAACb,EAAO8D,EAAMyB,GAAO,GAAGE,KAAK,OACzE,OAAO3B,EAAMyB,GAAO,GAIxB,SAOFoE,QAAQ3J,EAAO8D,EAAQ,IACrB,OAAiC,SAArB4F,GAAG1J,EAAO8D,GAOxB8F,iBAAiBvI,GACfR,KAAKQ,SAAWA,EAOlBwI,gBAAgB5E,EAAKyB,GACnB7F,KAAKQ,SAAS4D,GAAOyB,EAOvBoD,UAAU3I,GACRN,KAAKM,OAASA,EAOhB4I,oBAAoBC,GAClBnJ,KAAKU,iBAAmByI,GAQP,oBAAXC,SACRA,OAAOhJ,OAAS,IAAIA"} \ No newline at end of file diff --git a/dist/iodine.min.modern.js b/dist/iodine.min.modern.js index cf71c26..41cc332 100644 --- a/dist/iodine.min.modern.js +++ b/dist/iodine.min.modern.js @@ -1,2 +1,2 @@ -class e{constructor(){this.locale=void 0,this.messages=this._defaultMessages(),this.defaultFieldName="Value"}_dateCompare(e,t,r,s=!1){return!!this.isDate(e)&&!(!this.isDate(t)&&!this.isInteger(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()"optional"!==e).map(e=>[e,this._titleCase(e.split(":").shift()),e.split(":").slice(1)]):[]}_titleCase(e){return`${e[0].toUpperCase()}${e.slice(1)}`}addRule(t,r){e.prototype[`is${this._titleCase(t)}`]=r}async asyncIs(e,t=[]){for(let r in t=this._prepare(e,t))if(!await this[`is${t[r][1]}`].apply(this,[e,t[r][2].join(":")]))return await t[r][0];return!0}async asyncIsValid(e,t=[]){return!0===await this.asyncIs(e,t)}getErrorMessage(e,t){let{param:r,field:s}="object"==typeof t?t:{param:t,field:void 0};const i=e.split(":");let a=i.shift();r=r||i.join(":"),["after","afterOrEqual","before","beforeOrEqual"].includes(a)&&(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[a]:this.messages[a].replace("[PARAM]",r);return[null,void 0,""].includes(s)?n.replace("[FIELD]",this.defaultFieldName):n.replace("[FIELD]",s)}isAfter(e,t){return this._dateCompare(e,t,"more",!1)}isAfterOrEqual(e,t){return this._dateCompare(e,t,"more",!0)}isArray(e){return Array.isArray(e)}isBefore(e,t){return this._dateCompare(e,t,"less",!1)}isBeforeOrEqual(e,t){return this._dateCompare(e,t,"less",!0)}isBoolean(e){return[!0,!1].includes(e)}isDate(e){return e&&"[object Date]"===Object.prototype.toString.call(e)&&!isNaN(e)}isDifferent(e,t){return e!=t}isEndingWith(e,t){return this.isString(e)&&e.endsWith(t)}isEmail(e){return new RegExp("^\\S+@\\S+[\\.][0-9a-z]+$").test(String(e).toLowerCase())}isFalsy(e){return[0,"0",!1,"false"].includes(e)}isIn(e,t){return("string"==typeof t?t.split(","):t).includes(e)}isInteger(e){return Number.isInteger(e)&&parseInt(e).toString()===e.toString()}isJson(e){try{return"object"==typeof JSON.parse(e)}catch(e){return!1}}isMax(e,t){return parseFloat(e)<=t}isMin(e,t){return parseFloat(e)>=t}isMaxLength(e,t){return"string"==typeof e&&e.length<=t}isMinLength(e,t){return"string"==typeof e&&e.length>=t}isNotIn(e,t){return!this.isIn(e,t)}isNumeric(e){return!isNaN(parseFloat(e))&&isFinite(e)}isOptional(e){return[null,void 0,""].includes(e)}isRegexMatch(e,t){return new RegExp(t).test(String(e))}isRequired(e){return!this.isOptional(e)}isSame(e,t){return e==t}isStartingWith(e,t){return this.isString(e)&&e.startsWith(t)}isString(e){return"string"==typeof e}isTruthy(e){return[1,"1",!0,"true"].includes(e)}isUrl(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())}isUuid(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())}is(e,t=[]){for(let r in t=this._prepare(e,t))if(!this[`is${t[r][1]}`].apply(this,[e,t[r][2].join(":")]))return t[r][0];return!0}isValid(e,t=[]){return!0===this.is(e,t)}setErrorMessages(e){this.messages=e}setErrorMessage(e,t){this.messages[e]=t}setLocale(e){this.locale=e}setDefaultFieldName(e){this.defaultFieldName=e}}window.Iodine=new e;export{e as Iodine}; +class e{constructor(){this.locale=void 0,this.messages=this._defaultMessages(),this.defaultFieldName="Value"}_dateCompare(e,t,r,s=!1){return!!this.isDate(e)&&!(!this.isDate(t)&&!this.isInteger(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()"optional"!==e).map(e=>[e,this._titleCase(e.split(":").shift()),e.split(":").slice(1)]):[]}_titleCase(e){return`${e[0].toUpperCase()}${e.slice(1)}`}addRule(t,r){e.prototype[`is${this._titleCase(t)}`]=r}async asyncIs(e,t=[]){for(let r in t=this._prepare(e,t))if(!await this[`is${t[r][1]}`].apply(this,[e,t[r][2].join(":")]))return await t[r][0];return!0}async asyncIsValid(e,t=[]){return!0===await this.asyncIs(e,t)}getErrorMessage(e,t){let{param:r,field:s}="object"==typeof t?t:{param:t,field:void 0};const i=e.split(":");let a=i.shift();r=r||i.join(":"),["after","afterOrEqual","before","beforeOrEqual"].includes(a)&&(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[a]:this.messages[a].replace("[PARAM]",r);return[null,void 0,""].includes(s)?n.replace("[FIELD]",this.defaultFieldName):n.replace("[FIELD]",s)}isAfter(e,t){return this._dateCompare(e,t,"more",!1)}isAfterOrEqual(e,t){return this._dateCompare(e,t,"more",!0)}isArray(e){return Array.isArray(e)}isBefore(e,t){return this._dateCompare(e,t,"less",!1)}isBeforeOrEqual(e,t){return this._dateCompare(e,t,"less",!0)}isBoolean(e){return[!0,!1].includes(e)}isDate(e){return e&&"[object Date]"===Object.prototype.toString.call(e)&&!isNaN(e)}isDifferent(e,t){return e!=t}isEndingWith(e,t){return this.isString(e)&&e.endsWith(t)}isEmail(e){return new RegExp("^\\S+@\\S+[\\.][0-9a-z]+$").test(String(e).toLowerCase())}isFalsy(e){return[0,"0",!1,"false"].includes(e)}isIn(e,t){return("string"==typeof t?t.split(","):t).includes(e)}isInteger(e){return Number.isInteger(e)&&parseInt(e).toString()===e.toString()}isJson(e){try{return"object"==typeof JSON.parse(e)}catch(e){return!1}}isMax(e,t){return parseFloat(e)<=t}isMin(e,t){return parseFloat(e)>=t}isMaxLength(e,t){return"string"==typeof e&&e.length<=t}isMinLength(e,t){return"string"==typeof e&&e.length>=t}isNotIn(e,t){return!this.isIn(e,t)}isNumeric(e){return!isNaN(parseFloat(e))&&isFinite(e)}isOptional(e){return[null,void 0,""].includes(e)}isRegexMatch(e,t){return new RegExp(t).test(String(e))}isRequired(e){return!this.isOptional(e)}isSame(e,t){return e==t}isStartingWith(e,t){return this.isString(e)&&e.startsWith(t)}isString(e){return"string"==typeof e}isTruthy(e){return[1,"1",!0,"true"].includes(e)}isUrl(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())}isUuid(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())}is(e,t=[]){for(let r in t=this._prepare(e,t))if(!this[`is${t[r][1]}`].apply(this,[e,t[r][2].join(":")]))return t[r][0];return!0}isValid(e,t=[]){return!0===this.is(e,t)}setErrorMessages(e){this.messages=e}setErrorMessage(e,t){this.messages[e]=t}setLocale(e){this.locale=e}setDefaultFieldName(e){this.defaultFieldName=e}}"undefined"!=typeof window&&(window.Iodine=new e);export{e as Iodine}; //# sourceMappingURL=iodine.min.modern.js.map diff --git a/dist/iodine.min.modern.js.map b/dist/iodine.min.modern.js.map index 1d249ec..9daf0af 100644 --- a/dist/iodine.min.modern.js.map +++ b/dist/iodine.min.modern.js.map @@ -1 +1 @@ -{"version":3,"file":"iodine.min.modern.js","sources":["../src/iodine.js"],"sourcesContent":["/*\n|--------------------------------------------------------------------------\n| Iodine - JavaScript Library\n|--------------------------------------------------------------------------\n|\n| This library contains a collection of useful validation rules that can\n| be used to quickly verify whether items meet certain conditions.\n|\n*/\nexport class Iodine {\n /**\n * Constructor.\n *\n */\n constructor() {\n this.locale = undefined;\n\n this.messages = this._defaultMessages();\n\n this.defaultFieldName = 'Value';\n }\n\n /**\n * @internal.\n *\n */\n _dateCompare(first, second, type, equals = false) {\n if (!this.isDate(first)) return false;\n\n if (!this.isDate(second) && !this.isInteger(second)) return false;\n\n second = typeof second === 'number' ? second : second.getTime();\n\n if (type === 'less' && equals) return first.getTime() <= second;\n if (type === 'less' && !equals) return first.getTime() < second;\n if (type === 'more' && equals) return first.getTime() >= second;\n if (type === 'more' && !equals) return first.getTime() > second;\n }\n\n /**\n * @internal.\n *\n */\n _defaultMessages() {\n return {\n after : `The date must be after: '[PARAM]'`,\n afterOrEqual : `The date must be after or equal to: '[PARAM]'`,\n array : `[FIELD] must be an array`,\n before : `The date must be before: '[PARAM]'`,\n beforeOrEqual : `The date must be before or equal to: '[PARAM]'`,\n boolean : `[FIELD] must be true or false`,\n date : `[FIELD] must be a date`,\n different : `[FIELD] must be different to '[PARAM]'`,\n endingWith : `[FIELD] must end with '[PARAM]'`,\n email : `[FIELD] must be a valid email address`,\n falsy : `[FIELD] must be a falsy value (false, 'false', 0 or '0')`,\n in : `[FIELD] must be one of the following options: [PARAM]`,\n integer : `[FIELD] must be an integer`,\n json : `[FIELD] must be a parsable JSON object string`,\n max : `[FIELD] must be less than or equal to [PARAM]`,\n min : `[FIELD] must be greater than or equal to [PARAM]`,\n maxLength : `[FIELD] must not be greater than '[PARAM]' in character length`,\n minLength : `[FIELD] must not be less than '[PARAM]' character length`,\n notIn : `[FIELD] must not be one of the following options: [PARAM]`,\n numeric : `[FIELD] must be numeric`,\n optional : `[FIELD] is optional`,\n regexMatch : `[FIELD] must satisify the regular expression: [PARAM]`,\n required : `[FIELD] must be present`,\n same : `[FIELD] must be '[PARAM]'`,\n startingWith : `[FIELD] must start with '[PARAM]'`,\n string : `[FIELD] must be a string`,\n truthy : `[FIELD] must be a truthy value (true, 'true', 1 or '1')`,\n url : `[FIELD] must be a valid url`,\n uuid : `[FIELD] must be a valid UUID`,\n };\n }\n\n /**\n * @internal.\n *\n */\n _prepare(value, rules = [])\n {\n if (!rules.length) return [];\n\n if (rules[0] === 'optional' && this.isOptional(value)) return [];\n\n return rules.filter(rule => rule !== 'optional')\n .map(rule => [rule, this._titleCase(rule.split(':').shift()), rule.split(':').slice(1)]);\n }\n\n /**\n * @internal.\n *\n */\n _titleCase(value)\n {\n return `${value[0].toUpperCase()}${value.slice(1)}`;\n }\n\n /**\n * Attach a custom validation rule to the library.\n *\n */\n addRule(name, closure) {\n Iodine.prototype[`is${this._titleCase(name)}`] = closure;\n }\n\n /**\n * Determine whether the given value meets the given synchronous or asynchronous rules.\n *\n */\n async asyncIs(value, rules = []) {\n for (let index in rules = this._prepare(value, rules)) {\n if (!await this[`is${rules[index][1]}`].apply(this, [value, rules[index][2].join(':')])) {\n return await rules[index][0];\n }\n }\n\n return true;\n }\n\n /**\n * Determine whether the given value meets the given rules.\n *\n */\n async asyncIsValid(value, rules = []) {\n return await this.asyncIs(value, rules) === true;\n }\n\n /**\n * Retrieve an error message for the given rule.\n *\n */\n getErrorMessage(rule, args = undefined) {\n let { param, field } = typeof args === 'object' ? args : { param: args, field: undefined };\n\n const chunks = rule.split(':');\n\n let key = chunks.shift();\n\n param = param || chunks.join(':');\n\n if (['after', 'afterOrEqual', 'before', 'beforeOrEqual'].includes(key)) {\n param = new Date(parseInt(param)).toLocaleTimeString(this.locale, {\n year : 'numeric',\n month : 'short',\n day : 'numeric',\n hour : '2-digit',\n minute : 'numeric',\n hour12 : false,\n });\n }\n\n let message = [null, undefined, ''].includes(param)\n ? this.messages[key]\n : this.messages[key].replace('[PARAM]', param);\n\n return [null, undefined, ''].includes(field)\n ? message.replace('[FIELD]', this.defaultFieldName)\n : message.replace('[FIELD]', field);\n }\n\n /**\n * Determine if the given date is after another given date.\n *\n */\n isAfter(value, after) {\n return this._dateCompare(value, after, 'more', false);\n }\n\n /**\n * Determine if the given date is after or equal to another given date.\n *\n */\n isAfterOrEqual(value, after) {\n return this._dateCompare(value, after, 'more', true);\n }\n\n /**\n * Determine if the given value is an array.\n *\n */\n isArray(value) {\n return Array.isArray(value);\n }\n\n /**\n * Determine if the given date is before another given date.\n *\n */\n isBefore(value, before) {\n return this._dateCompare(value, before, 'less', false);\n }\n\n /**\n * Determine if the given date is before or equal to another given date.\n *\n */\n isBeforeOrEqual(value, before) {\n return this._dateCompare(value, before, 'less', true);\n }\n\n /**\n * Determine if the given value is a boolean.\n *\n */\n isBoolean(value) {\n return [true, false].includes(value);\n }\n\n /**\n * Determine if the given value is a date object.\n *\n */\n isDate(value) {\n return (value && Object.prototype.toString.call(value) === '[object Date]' && !isNaN(value));\n }\n\n /**\n * Determine if the given value is different to another given value.\n *\n */\n isDifferent(value, different) {\n return value != different;\n }\n\n /**\n * Determine if the given value ends with another given value.\n *\n */\n isEndingWith(value, sub) {\n return this.isString(value) && value.endsWith(sub);\n }\n\n /**\n * Determine if the given value is a valid email address.\n *\n */\n isEmail(value) {\n return new RegExp(\"^\\\\S+@\\\\S+[\\\\.][0-9a-z]+$\").test(String(value).toLowerCase());\n }\n\n /**\n * Determine if the given value is falsy.\n *\n */\n isFalsy(value) {\n return [0, '0', false, 'false'].includes(value);\n }\n\n /**\n * Determine if the given value is within the given array of options.\n *\n */\n isIn(value, options) {\n return (typeof options === 'string' ? options.split(',') : options).includes(value);\n }\n\n /**\n * Determine if the given value is an integer.\n *\n */\n isInteger(value) {\n return Number.isInteger(value) && parseInt(value).toString() === value.toString();\n }\n\n /**\n * Determine if the given value is a JSON string.\n *\n */\n isJson(value) {\n try {\n return typeof JSON.parse(value) === 'object';\n } catch (e) {\n return false;\n }\n }\n\n /**\n * Determine if the given number is less than or equal to the maximum limit.\n *\n */\n isMax(value, limit) {\n return parseFloat(value) <= limit;\n }\n\n /**\n * Determine if the given number is greater than or equal to the minimum limit.\n *\n */\n isMin(value, limit) {\n return parseFloat(value) >= limit;\n }\n\n /**\n * Determine if the given value string length is less than or equal to the maximum limit.\n *\n */\n isMaxLength(value, limit) {\n return typeof value === 'string' ? value.length <= limit : false;\n }\n\n /**\n * Determine if the given value string length is greater than or equal to the minimum limit.\n *\n */\n isMinLength(value, limit) {\n return typeof value === 'string' ? value.length >= limit : false;\n }\n\n /**\n * Determine if the given value is not within the given array of options.\n *\n */\n isNotIn(value, options) {\n return !this.isIn(value, options);\n }\n\n /**\n * Determine if the given value is numeric (an integer or a float).\n *\n */\n isNumeric(value) {\n return !isNaN(parseFloat(value)) && isFinite(value);\n }\n\n /**\n * Determine if the given value is optional.\n *\n */\n isOptional(value) {\n return [null, undefined, ''].includes(value);\n }\n\n /**\n * Determine if the given value satisifies the given regular expression.\n *\n */\n isRegexMatch(value, expression) {\n return new RegExp(expression).test(String(value));\n }\n\n /**\n * Determine if the given value is present.\n *\n */\n isRequired(value) {\n return !this.isOptional(value);\n }\n\n /**\n * Determine if the given value is the same as another given value.\n *\n */\n isSame(value, same) {\n return value == same;\n }\n\n /**\n * Determine if the given value starts with another given value.\n *\n */\n isStartingWith(value, sub) {\n return this.isString(value) && value.startsWith(sub);\n }\n\n /**\n * Determine if the given value is a string.\n *\n */\n isString(value) {\n return typeof value === 'string';\n }\n\n /**\n * Determine if the given value is truthy.\n *\n */\n isTruthy(value) {\n return [1, '1', true, 'true'].includes(value);\n }\n\n /**\n * Determine if the given value is a valid URL.\n *\n */\n isUrl(value) {\n let regex = \"^(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_]*)?$\";\n\n return new RegExp(regex).test(String(value).toLowerCase());\n }\n\n /**\n * Determine if the given value is a valid UUID.\n *\n */\n isUuid(value) {\n let regex = \"^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$\";\n\n return new RegExp(regex).test(String(value).toLowerCase());\n }\n\n /**\n * Determine whether the given value meets the given rules.\n *\n */\n is(value, rules = []) {\n for (let index in rules = this._prepare(value, rules)) {\n if (!this[`is${rules[index][1]}`].apply(this, [value, rules[index][2].join(':')])) {\n return rules[index][0];\n }\n }\n\n return true;\n }\n\n /**\n * Determine whether the given value meets the given rules.\n *\n */\n isValid(value, rules = []) {\n return this.is(value, rules) === true;\n }\n\n /**\n * Replace the default error messages with a new set.\n *\n */\n setErrorMessages(messages) {\n this.messages = messages;\n }\n\n /**\n * Add or replace an error message.\n *\n */\n setErrorMessage(key, message) {\n this.messages[key] = message;\n }\n\n /**\n * Replace the default locale with a new value.\n *\n */\n setLocale(locale) {\n this.locale = locale;\n }\n\n /**\n * Replace the default field name with a new value.\n */\n setDefaultFieldName(fieldName) {\n this.defaultFieldName = fieldName;\n }\n}\n\n/**\n * Create an instance of the library.\n *\n */\nwindow.Iodine = new Iodine();\n"],"names":["Iodine","constructor","this","locale","undefined","messages","_defaultMessages","defaultFieldName","_dateCompare","first","second","type","equals","isDate","isInteger","getTime","after","afterOrEqual","array","before","beforeOrEqual","boolean","date","different","endingWith","email","falsy","in","integer","json","max","min","maxLength","minLength","notIn","numeric","optional","regexMatch","required","same","startingWith","string","truthy","url","uuid","_prepare","value","rules","length","isOptional","filter","rule","map","_titleCase","split","shift","slice","toUpperCase","addRule","name","closure","prototype","[object Object]","index","apply","join","asyncIs","getErrorMessage","args","param","field","chunks","key","includes","Date","parseInt","toLocaleTimeString","year","month","day","hour","minute","hour12","message","replace","isAfter","isAfterOrEqual","isArray","Array","isBefore","isBeforeOrEqual","isBoolean","Object","toString","call","isNaN","isDifferent","isEndingWith","sub","isString","endsWith","isEmail","RegExp","test","String","toLowerCase","isFalsy","isIn","options","Number","isJson","JSON","parse","e","isMax","limit","parseFloat","isMin","isMaxLength","isMinLength","isNotIn","isNumeric","isFinite","isRegexMatch","expression","isRequired","isSame","isStartingWith","startsWith","isTruthy","isUrl","isUuid","is","isValid","setErrorMessages","setErrorMessage","setLocale","setDefaultFieldName","fieldName","window"],"mappings":"MASaA,EAKXC,cACEC,KAAKC,YAASC,EAEdF,KAAKG,SAAWH,KAAKI,mBAErBJ,KAAKK,iBAAmB,QAO1BC,aAAaC,EAAOC,EAAQC,EAAMC,GAAS,GACzC,QAAKV,KAAKW,OAAOJ,OAEZP,KAAKW,OAAOH,KAAYR,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B,YAAYC,SAASrD,IAAUA,EAAMkF,WAAW9B,GAOlDC,SAASrD,GACP,MAAwB,iBAAVA,EAOhBmF,SAASnF,GACP,MAAO,CAAC,EAAG,KAAK,EAAM,QAAQ2B,SAAS3B,GAOzCoF,MAAMpF,GAGJ,WAAWwD,OAFC,yKAEaC,KAAKC,OAAO1D,GAAO2D,eAO9C0B,OAAOrF,GAGL,WAAWwD,OAFC,6EAEaC,KAAKC,OAAO1D,GAAO2D,eAO9C2B,GAAGtF,EAAOC,EAAQ,IAChB,IAAK,IAAIgB,KAAShB,EAAQ7C,KAAK2C,SAASC,EAAOC,GAC7C,IAAK7C,KAAM,KAAI6C,EAAMgB,GAAO,MAAMC,MAAM9D,KAAM,CAAC4C,EAAOC,EAAMgB,GAAO,GAAGE,KAAK,OACzE,OAAOlB,EAAMgB,GAAO,GAIxB,SAOFsE,QAAQvF,EAAOC,EAAQ,IACrB,OAAiC,SAArBqF,GAAGtF,EAAOC,GAOxBuF,iBAAiBjI,GACfH,KAAKG,SAAWA,EAOlBkI,gBAAgB/D,EAAKW,GACnBjF,KAAKG,SAASmE,GAAOW,EAOvBqD,UAAUrI,GACRD,KAAKC,OAASA,EAMhBsI,oBAAoBC,GAClBxI,KAAKK,iBAAmBmI,GAQ5BC,OAAO3I,OAAS,IAAIA"} \ No newline at end of file +{"version":3,"file":"iodine.min.modern.js","sources":["../src/iodine.js"],"sourcesContent":["/*\n|--------------------------------------------------------------------------\n| Iodine - JavaScript Library\n|--------------------------------------------------------------------------\n|\n| This library contains a collection of useful validation rules that can\n| be used to quickly verify whether items meet certain conditions.\n|\n*/\nexport class Iodine {\n /**\n * Constructor.\n *\n */\n constructor() {\n this.locale = undefined;\n\n this.messages = this._defaultMessages();\n\n this.defaultFieldName = 'Value';\n }\n\n /**\n * @internal.\n *\n */\n _dateCompare(first, second, type, equals = false) {\n if (!this.isDate(first)) return false;\n\n if (!this.isDate(second) && !this.isInteger(second)) return false;\n\n second = typeof second === 'number' ? second : second.getTime();\n\n if (type === 'less' && equals) return first.getTime() <= second;\n if (type === 'less' && !equals) return first.getTime() < second;\n if (type === 'more' && equals) return first.getTime() >= second;\n if (type === 'more' && !equals) return first.getTime() > second;\n }\n\n /**\n * @internal.\n *\n */\n _defaultMessages() {\n return {\n after : `The date must be after: '[PARAM]'`,\n afterOrEqual : `The date must be after or equal to: '[PARAM]'`,\n array : `[FIELD] must be an array`,\n before : `The date must be before: '[PARAM]'`,\n beforeOrEqual : `The date must be before or equal to: '[PARAM]'`,\n boolean : `[FIELD] must be true or false`,\n date : `[FIELD] must be a date`,\n different : `[FIELD] must be different to '[PARAM]'`,\n endingWith : `[FIELD] must end with '[PARAM]'`,\n email : `[FIELD] must be a valid email address`,\n falsy : `[FIELD] must be a falsy value (false, 'false', 0 or '0')`,\n in : `[FIELD] must be one of the following options: [PARAM]`,\n integer : `[FIELD] must be an integer`,\n json : `[FIELD] must be a parsable JSON object string`,\n max : `[FIELD] must be less than or equal to [PARAM]`,\n min : `[FIELD] must be greater than or equal to [PARAM]`,\n maxLength : `[FIELD] must not be greater than '[PARAM]' in character length`,\n minLength : `[FIELD] must not be less than '[PARAM]' character length`,\n notIn : `[FIELD] must not be one of the following options: [PARAM]`,\n numeric : `[FIELD] must be numeric`,\n optional : `[FIELD] is optional`,\n regexMatch : `[FIELD] must satisify the regular expression: [PARAM]`,\n required : `[FIELD] must be present`,\n same : `[FIELD] must be '[PARAM]'`,\n startingWith : `[FIELD] must start with '[PARAM]'`,\n string : `[FIELD] must be a string`,\n truthy : `[FIELD] must be a truthy value (true, 'true', 1 or '1')`,\n url : `[FIELD] must be a valid url`,\n uuid : `[FIELD] must be a valid UUID`,\n };\n }\n\n /**\n * @internal.\n *\n */\n _prepare(value, rules = []) {\n if (!rules.length) return [];\n\n if (rules[0] === 'optional' && this.isOptional(value)) return [];\n\n return rules.filter(rule => rule !== 'optional')\n .map(rule => [rule, this._titleCase(rule.split(':').shift()), rule.split(':').slice(1)]);\n }\n\n /**\n * @internal.\n *\n */\n _titleCase(value) {\n return `${value[0].toUpperCase()}${value.slice(1)}`;\n }\n\n /**\n * Attach a custom validation rule to the library.\n *\n */\n addRule(name, closure) {\n Iodine.prototype[`is${this._titleCase(name)}`] = closure;\n }\n\n /**\n * Determine whether the given value meets the given synchronous or asynchronous rules.\n *\n */\n async asyncIs(value, rules = []) {\n for (let index in rules = this._prepare(value, rules)) {\n if (!await this[`is${rules[index][1]}`].apply(this, [value, rules[index][2].join(':')])) {\n return await rules[index][0];\n }\n }\n\n return true;\n }\n\n /**\n * Determine whether the given value meets the given rules.\n *\n */\n async asyncIsValid(value, rules = []) {\n return await this.asyncIs(value, rules) === true;\n }\n\n /**\n * Retrieve an error message for the given rule.\n *\n */\n getErrorMessage(rule, args = undefined) {\n let { param, field } = typeof args === 'object' ? args : { param: args, field: undefined };\n\n const chunks = rule.split(':');\n\n let key = chunks.shift();\n\n param = param || chunks.join(':');\n\n if (['after', 'afterOrEqual', 'before', 'beforeOrEqual'].includes(key)) {\n param = new Date(parseInt(param)).toLocaleTimeString(this.locale, {\n year : 'numeric',\n month : 'short',\n day : 'numeric',\n hour : '2-digit',\n minute : 'numeric',\n hour12 : false,\n });\n }\n\n let message = [null, undefined, ''].includes(param)\n ? this.messages[key]\n : this.messages[key].replace('[PARAM]', param);\n\n return [null, undefined, ''].includes(field)\n ? message.replace('[FIELD]', this.defaultFieldName)\n : message.replace('[FIELD]', field);\n }\n\n /**\n * Determine if the given date is after another given date.\n *\n */\n isAfter(value, after) {\n return this._dateCompare(value, after, 'more', false);\n }\n\n /**\n * Determine if the given date is after or equal to another given date.\n *\n */\n isAfterOrEqual(value, after) {\n return this._dateCompare(value, after, 'more', true);\n }\n\n /**\n * Determine if the given value is an array.\n *\n */\n isArray(value) {\n return Array.isArray(value);\n }\n\n /**\n * Determine if the given date is before another given date.\n *\n */\n isBefore(value, before) {\n return this._dateCompare(value, before, 'less', false);\n }\n\n /**\n * Determine if the given date is before or equal to another given date.\n *\n */\n isBeforeOrEqual(value, before) {\n return this._dateCompare(value, before, 'less', true);\n }\n\n /**\n * Determine if the given value is a boolean.\n *\n */\n isBoolean(value) {\n return [true, false].includes(value);\n }\n\n /**\n * Determine if the given value is a date object.\n *\n */\n isDate(value) {\n return (value && Object.prototype.toString.call(value) === '[object Date]' && !isNaN(value));\n }\n\n /**\n * Determine if the given value is different to another given value.\n *\n */\n isDifferent(value, different) {\n return value != different;\n }\n\n /**\n * Determine if the given value ends with another given value.\n *\n */\n isEndingWith(value, sub) {\n return this.isString(value) && value.endsWith(sub);\n }\n\n /**\n * Determine if the given value is a valid email address.\n *\n */\n isEmail(value) {\n return new RegExp(\"^\\\\S+@\\\\S+[\\\\.][0-9a-z]+$\").test(String(value).toLowerCase());\n }\n\n /**\n * Determine if the given value is falsy.\n *\n */\n isFalsy(value) {\n return [0, '0', false, 'false'].includes(value);\n }\n\n /**\n * Determine if the given value is within the given array of options.\n *\n */\n isIn(value, options) {\n return (typeof options === 'string' ? options.split(',') : options).includes(value);\n }\n\n /**\n * Determine if the given value is an integer.\n *\n */\n isInteger(value) {\n return Number.isInteger(value) && parseInt(value).toString() === value.toString();\n }\n\n /**\n * Determine if the given value is a JSON string.\n *\n */\n isJson(value) {\n try {\n return typeof JSON.parse(value) === 'object';\n } catch (e) {\n return false;\n }\n }\n\n /**\n * Determine if the given number is less than or equal to the maximum limit.\n *\n */\n isMax(value, limit) {\n return parseFloat(value) <= limit;\n }\n\n /**\n * Determine if the given number is greater than or equal to the minimum limit.\n *\n */\n isMin(value, limit) {\n return parseFloat(value) >= limit;\n }\n\n /**\n * Determine if the given value string length is less than or equal to the maximum limit.\n *\n */\n isMaxLength(value, limit) {\n return typeof value === 'string' ? value.length <= limit : false;\n }\n\n /**\n * Determine if the given value string length is greater than or equal to the minimum limit.\n *\n */\n isMinLength(value, limit) {\n return typeof value === 'string' ? value.length >= limit : false;\n }\n\n /**\n * Determine if the given value is not within the given array of options.\n *\n */\n isNotIn(value, options) {\n return !this.isIn(value, options);\n }\n\n /**\n * Determine if the given value is numeric (an integer or a float).\n *\n */\n isNumeric(value) {\n return !isNaN(parseFloat(value)) && isFinite(value);\n }\n\n /**\n * Determine if the given value is optional.\n *\n */\n isOptional(value) {\n return [null, undefined, ''].includes(value);\n }\n\n /**\n * Determine if the given value satisifies the given regular expression.\n *\n */\n isRegexMatch(value, expression) {\n return new RegExp(expression).test(String(value));\n }\n\n /**\n * Determine if the given value is present.\n *\n */\n isRequired(value) {\n return !this.isOptional(value);\n }\n\n /**\n * Determine if the given value is the same as another given value.\n *\n */\n isSame(value, same) {\n return value == same;\n }\n\n /**\n * Determine if the given value starts with another given value.\n *\n */\n isStartingWith(value, sub) {\n return this.isString(value) && value.startsWith(sub);\n }\n\n /**\n * Determine if the given value is a string.\n *\n */\n isString(value) {\n return typeof value === 'string';\n }\n\n /**\n * Determine if the given value is truthy.\n *\n */\n isTruthy(value) {\n return [1, '1', true, 'true'].includes(value);\n }\n\n /**\n * Determine if the given value is a valid URL.\n *\n */\n isUrl(value) {\n let regex = \"^(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_]*)?$\";\n\n return new RegExp(regex).test(String(value).toLowerCase());\n }\n\n /**\n * Determine if the given value is a valid UUID.\n *\n */\n isUuid(value) {\n let regex = \"^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$\";\n\n return new RegExp(regex).test(String(value).toLowerCase());\n }\n\n /**\n * Determine whether the given value meets the given rules.\n *\n */\n is(value, rules = []) {\n for (let index in rules = this._prepare(value, rules)) {\n if (!this[`is${rules[index][1]}`].apply(this, [value, rules[index][2].join(':')])) {\n return rules[index][0];\n }\n }\n\n return true;\n }\n\n /**\n * Determine whether the given value meets the given rules.\n *\n */\n isValid(value, rules = []) {\n return this.is(value, rules) === true;\n }\n\n /**\n * Replace the default error messages with a new set.\n *\n */\n setErrorMessages(messages) {\n this.messages = messages;\n }\n\n /**\n * Add or replace an error message.\n *\n */\n setErrorMessage(key, message) {\n this.messages[key] = message;\n }\n\n /**\n * Replace the default locale with a new value.\n *\n */\n setLocale(locale) {\n this.locale = locale;\n }\n\n /**\n * Replace the default field name with a new value.\n *\n */\n setDefaultFieldName(fieldName) {\n this.defaultFieldName = fieldName;\n }\n}\n\n/**\n * Create an instance of the library.\n *\n */\nif(typeof window !== 'undefined') {\n window.Iodine = new Iodine();\n}\n"],"names":["Iodine","constructor","this","locale","undefined","messages","_defaultMessages","defaultFieldName","_dateCompare","first","second","type","equals","isDate","isInteger","getTime","after","afterOrEqual","array","before","beforeOrEqual","boolean","date","different","endingWith","email","falsy","in","integer","json","max","min","maxLength","minLength","notIn","numeric","optional","regexMatch","required","same","startingWith","string","truthy","url","uuid","_prepare","value","rules","length","isOptional","filter","rule","map","_titleCase","split","shift","slice","toUpperCase","addRule","name","closure","prototype","async","index","apply","join","asyncIs","getErrorMessage","args","param","field","chunks","key","includes","Date","parseInt","toLocaleTimeString","year","month","day","hour","minute","hour12","message","replace","isAfter","isAfterOrEqual","isArray","Array","isBefore","isBeforeOrEqual","isBoolean","Object","toString","call","isNaN","isDifferent","isEndingWith","sub","isString","endsWith","isEmail","RegExp","test","String","toLowerCase","isFalsy","isIn","options","Number","isJson","JSON","parse","e","isMax","limit","parseFloat","isMin","isMaxLength","isMinLength","isNotIn","isNumeric","isFinite","isRegexMatch","expression","isRequired","isSame","isStartingWith","startsWith","isTruthy","isUrl","isUuid","is","isValid","setErrorMessages","setErrorMessage","setLocale","setDefaultFieldName","fieldName","window"],"mappings":"MASaA,EAKXC,cACEC,KAAKC,YAASC,EAEdF,KAAKG,SAAWH,KAAKI,mBAErBJ,KAAKK,iBAAmB,QAO1BC,aAA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AAK+C,WAAWH,GAO1BgF,OAAOhF,EAAOP,GACZ,OAAOO,GAASP,EAOlBwF,eAAejF,EAAOoD,GACpB,YAAYC,SAASrD,IAAUA,EAAMkF,WAAW9B,GAOlDC,SAASrD,GACP,MAAwB,iBAAVA,EAOhBmF,SAASnF,GACP,MAAO,CAAC,EAAG,KAAK,EAAM,QAAQ2B,SAAS3B,GAOzCoF,MAAMpF,GAGJ,WAAWwD,OAFC,yKAEaC,KAAKC,OAAO1D,GAAO2D,eAO9C0B,OAAOrF,GAGL,WAAWwD,OAFC,6EAEaC,KAAKC,OAAO1D,GAAO2D,eAO9C2B,GAAGtF,EAAOC,EAAQ,IAChB,IAAK,IAAIgB,KAAShB,EAAQ7C,KAAK2C,SAASC,EAAOC,GAC7C,IAAK7C,KAAM,KAAI6C,EAAMgB,GAAO,MAAMC,MAAM9D,KAAM,CAAC4C,EAAOC,EAAMgB,GAAO,GAAGE,KAAK,OACzE,OAAOlB,EAAMgB,GAAO,GAIxB,SAOFsE,QAAQvF,EAAOC,EAAQ,IACrB,OAAiC,SAArBqF,GAAGtF,EAAOC,GAOxBuF,iBAAiBjI,GACfH,KAAKG,SAAWA,EAOlBkI,gBAAgB/D,EAAKW,GACnBjF,KAAKG,SAASmE,GAAOW,EAOvBqD,UAAUrI,GACRD,KAAKC,OAASA,EAOhBsI,oBAAoBC,GAClBxI,KAAKK,iBAAmBmI,GAQP,oBAAXC,SACRA,OAAO3I,OAAS,IAAIA"} \ No newline at end of file diff --git a/dist/iodine.min.umd.js b/dist/iodine.min.umd.js index 48454d2..c3391f2 100644 --- a/dist/iodine.min.umd.js +++ b/dist/iodine.min.umd.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e||self).iodine={})}(this,function(e){function t(e,s,i){if(!e.s){if(i instanceof r){if(!i.s)return void(i.o=t.bind(null,e,s));1&s&&(s=i.s),i=i.v}if(i&&i.then)return void i.then(t.bind(null,e,s),t.bind(null,e,2));e.s=s,e.v=i;const n=e.o;n&&n(e)}}const r=function(){function e(){}return e.prototype.then=function(r,s){const i=new e,n=this.s;if(n){const e=1&n?r:s;if(e){try{t(i,1,e(this.v))}catch(e){t(i,2,e)}return i}return this}return this.o=function(e){try{const n=e.v;1&e.s?t(i,1,r?r(n):n):s?t(i,1,s(n)):t(i,2,n)}catch(e){t(i,2,e)}},i},e}();class s{constructor(){this.locale=void 0,this.messages=this._defaultMessages(),this.defaultFieldName="Value"}_dateCompare(e,t,r,s=!1){return!!this.isDate(e)&&!(!this.isDate(t)&&!this.isInteger(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()"optional"!==e).map(e=>[e,this._titleCase(e.split(":").shift()),e.split(":").slice(1)]):[]}_titleCase(e){return`${e[0].toUpperCase()}${e.slice(1)}`}addRule(e,t){s.prototype[`is${this._titleCase(e)}`]=t}asyncIs(e,s=[]){try{let i;const n=this,a=function(a,o,u){var l=[];for(var f in a)l.push(f);return function(e,s,i){var n,a,o=-1;return function u(l){try{for(;++o=t}isMaxLength(e,t){return"string"==typeof e&&e.length<=t}isMinLength(e,t){return"string"==typeof e&&e.length>=t}isNotIn(e,t){return!this.isIn(e,t)}isNumeric(e){return!isNaN(parseFloat(e))&&isFinite(e)}isOptional(e){return[null,void 0,""].includes(e)}isRegexMatch(e,t){return new RegExp(t).test(String(e))}isRequired(e){return!this.isOptional(e)}isSame(e,t){return e==t}isStartingWith(e,t){return this.isString(e)&&e.startsWith(t)}isString(e){return"string"==typeof e}isTruthy(e){return[1,"1",!0,"true"].includes(e)}isUrl(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())}isUuid(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())}is(e,t=[]){for(let r in t=this._prepare(e,t))if(!this[`is${t[r][1]}`].apply(this,[e,t[r][2].join(":")]))return t[r][0];return!0}isValid(e,t=[]){return!0===this.is(e,t)}setErrorMessages(e){this.messages=e}setErrorMessage(e,t){this.messages[e]=t}setLocale(e){this.locale=e}setDefaultFieldName(e){this.defaultFieldName=e}}window.Iodine=new s,e.Iodine=s}); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e||self).iodine={})}(this,function(e){function t(e,s,i){if(!e.s){if(i instanceof r){if(!i.s)return void(i.o=t.bind(null,e,s));1&s&&(s=i.s),i=i.v}if(i&&i.then)return void i.then(t.bind(null,e,s),t.bind(null,e,2));e.s=s,e.v=i;const n=e.o;n&&n(e)}}const r=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(r,s){const i=new e,n=this.s;if(n){const e=1&n?r:s;if(e){try{t(i,1,e(this.v))}catch(e){t(i,2,e)}return i}return this}return this.o=function(e){try{const n=e.v;1&e.s?t(i,1,r?r(n):n):s?t(i,1,s(n)):t(i,2,n)}catch(e){t(i,2,e)}},i},e}();class s{constructor(){this.locale=void 0,this.messages=this._defaultMessages(),this.defaultFieldName="Value"}_dateCompare(e,t,r,s=!1){return!!this.isDate(e)&&!(!this.isDate(t)&&!this.isInteger(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()"optional"!==e).map(e=>[e,this._titleCase(e.split(":").shift()),e.split(":").slice(1)]):[]}_titleCase(e){return`${e[0].toUpperCase()}${e.slice(1)}`}addRule(e,t){s.prototype[`is${this._titleCase(e)}`]=t}asyncIs(e,s=[]){try{let i;const n=this,a=function(a,o,u){var l=[];for(var f in a)l.push(f);return function(e,s,i){var n,a,o=-1;return function u(l){try{for(;++o=t}isMaxLength(e,t){return"string"==typeof e&&e.length<=t}isMinLength(e,t){return"string"==typeof e&&e.length>=t}isNotIn(e,t){return!this.isIn(e,t)}isNumeric(e){return!isNaN(parseFloat(e))&&isFinite(e)}isOptional(e){return[null,void 0,""].includes(e)}isRegexMatch(e,t){return new RegExp(t).test(String(e))}isRequired(e){return!this.isOptional(e)}isSame(e,t){return e==t}isStartingWith(e,t){return this.isString(e)&&e.startsWith(t)}isString(e){return"string"==typeof e}isTruthy(e){return[1,"1",!0,"true"].includes(e)}isUrl(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())}isUuid(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())}is(e,t=[]){for(let r in t=this._prepare(e,t))if(!this[`is${t[r][1]}`].apply(this,[e,t[r][2].join(":")]))return t[r][0];return!0}isValid(e,t=[]){return!0===this.is(e,t)}setErrorMessages(e){this.messages=e}setErrorMessage(e,t){this.messages[e]=t}setLocale(e){this.locale=e}setDefaultFieldName(e){this.defaultFieldName=e}}"undefined"!=typeof window&&(window.Iodine=new s),e.Iodine=s}); //# sourceMappingURL=iodine.min.umd.js.map diff --git a/dist/iodine.min.umd.js.map b/dist/iodine.min.umd.js.map index 682c84e..4261b56 100644 --- a/dist/iodine.min.umd.js.map +++ b/dist/iodine.min.umd.js.map @@ -1 +1 @@ -{"version":3,"file":"iodine.min.umd.js","sources":["../src/iodine.js"],"sourcesContent":["/*\n|--------------------------------------------------------------------------\n| Iodine - JavaScript Library\n|--------------------------------------------------------------------------\n|\n| This library contains a collection of useful validation rules that can\n| be used to quickly verify whether items meet certain conditions.\n|\n*/\nexport class Iodine {\n /**\n * Constructor.\n *\n */\n constructor() {\n this.locale = undefined;\n\n this.messages = this._defaultMessages();\n\n this.defaultFieldName = 'Value';\n }\n\n /**\n * @internal.\n *\n */\n _dateCompare(first, second, type, equals = false) {\n if (!this.isDate(first)) return false;\n\n if (!this.isDate(second) && !this.isInteger(second)) return false;\n\n second = typeof second === 'number' ? second : second.getTime();\n\n if (type === 'less' && equals) return first.getTime() <= second;\n if (type === 'less' && !equals) return first.getTime() < second;\n if (type === 'more' && equals) return first.getTime() >= second;\n if (type === 'more' && !equals) return first.getTime() > second;\n }\n\n /**\n * @internal.\n *\n */\n _defaultMessages() {\n return {\n after : `The date must be after: '[PARAM]'`,\n afterOrEqual : `The date must be after or equal to: '[PARAM]'`,\n array : `[FIELD] must be an array`,\n before : `The date must be before: '[PARAM]'`,\n beforeOrEqual : `The date must be before or equal to: '[PARAM]'`,\n boolean : `[FIELD] must be true or false`,\n date : `[FIELD] must be a date`,\n different : `[FIELD] must be different to '[PARAM]'`,\n endingWith : `[FIELD] must end with '[PARAM]'`,\n email : `[FIELD] must be a valid email address`,\n falsy : `[FIELD] must be a falsy value (false, 'false', 0 or '0')`,\n in : `[FIELD] must be one of the following options: [PARAM]`,\n integer : `[FIELD] must be an integer`,\n json : `[FIELD] must be a parsable JSON object string`,\n max : `[FIELD] must be less than or equal to [PARAM]`,\n min : `[FIELD] must be greater than or equal to [PARAM]`,\n maxLength : `[FIELD] must not be greater than '[PARAM]' in character length`,\n minLength : `[FIELD] must not be less than '[PARAM]' character length`,\n notIn : `[FIELD] must not be one of the following options: [PARAM]`,\n numeric : `[FIELD] must be numeric`,\n optional : `[FIELD] is optional`,\n regexMatch : `[FIELD] must satisify the regular expression: [PARAM]`,\n required : `[FIELD] must be present`,\n same : `[FIELD] must be '[PARAM]'`,\n startingWith : `[FIELD] must start with '[PARAM]'`,\n string : `[FIELD] must be a string`,\n truthy : `[FIELD] must be a truthy value (true, 'true', 1 or '1')`,\n url : `[FIELD] must be a valid url`,\n uuid : `[FIELD] must be a valid UUID`,\n };\n }\n\n /**\n * @internal.\n *\n */\n _prepare(value, rules = [])\n {\n if (!rules.length) return [];\n\n if (rules[0] === 'optional' && this.isOptional(value)) return [];\n\n return rules.filter(rule => rule !== 'optional')\n .map(rule => [rule, this._titleCase(rule.split(':').shift()), rule.split(':').slice(1)]);\n }\n\n /**\n * @internal.\n *\n */\n _titleCase(value)\n {\n return `${value[0].toUpperCase()}${value.slice(1)}`;\n }\n\n /**\n * Attach a custom validation rule to the library.\n *\n */\n addRule(name, closure) {\n Iodine.prototype[`is${this._titleCase(name)}`] = closure;\n }\n\n /**\n * Determine whether the given value meets the given synchronous or asynchronous rules.\n *\n */\n async asyncIs(value, rules = []) {\n for (let index in rules = this._prepare(value, rules)) {\n if (!await this[`is${rules[index][1]}`].apply(this, [value, rules[index][2].join(':')])) {\n return await rules[index][0];\n }\n }\n\n return true;\n }\n\n /**\n * Determine whether the given value meets the given rules.\n *\n */\n async asyncIsValid(value, rules = []) {\n return await this.asyncIs(value, rules) === true;\n }\n\n /**\n * Retrieve an error message for the given rule.\n *\n */\n getErrorMessage(rule, args = undefined) {\n let { param, field } = typeof args === 'object' ? args : { param: args, field: undefined };\n\n const chunks = rule.split(':');\n\n let key = chunks.shift();\n\n param = param || chunks.join(':');\n\n if (['after', 'afterOrEqual', 'before', 'beforeOrEqual'].includes(key)) {\n param = new Date(parseInt(param)).toLocaleTimeString(this.locale, {\n year : 'numeric',\n month : 'short',\n day : 'numeric',\n hour : '2-digit',\n minute : 'numeric',\n hour12 : false,\n });\n }\n\n let message = [null, undefined, ''].includes(param)\n ? this.messages[key]\n : this.messages[key].replace('[PARAM]', param);\n\n return [null, undefined, ''].includes(field)\n ? message.replace('[FIELD]', this.defaultFieldName)\n : message.replace('[FIELD]', field);\n }\n\n /**\n * Determine if the given date is after another given date.\n *\n */\n isAfter(value, after) {\n return this._dateCompare(value, after, 'more', false);\n }\n\n /**\n * Determine if the given date is after or equal to another given date.\n *\n */\n isAfterOrEqual(value, after) {\n return this._dateCompare(value, after, 'more', true);\n }\n\n /**\n * Determine if the given value is an array.\n *\n */\n isArray(value) {\n return Array.isArray(value);\n }\n\n /**\n * Determine if the given date is before another given date.\n *\n */\n isBefore(value, before) {\n return this._dateCompare(value, before, 'less', false);\n }\n\n /**\n * Determine if the given date is before or equal to another given date.\n *\n */\n isBeforeOrEqual(value, before) {\n return this._dateCompare(value, before, 'less', true);\n }\n\n /**\n * Determine if the given value is a boolean.\n *\n */\n isBoolean(value) {\n return [true, false].includes(value);\n }\n\n /**\n * Determine if the given value is a date object.\n *\n */\n isDate(value) {\n return (value && Object.prototype.toString.call(value) === '[object Date]' && !isNaN(value));\n }\n\n /**\n * Determine if the given value is different to another given value.\n *\n */\n isDifferent(value, different) {\n return value != different;\n }\n\n /**\n * Determine if the given value ends with another given value.\n *\n */\n isEndingWith(value, sub) {\n return this.isString(value) && value.endsWith(sub);\n }\n\n /**\n * Determine if the given value is a valid email address.\n *\n */\n isEmail(value) {\n return new RegExp(\"^\\\\S+@\\\\S+[\\\\.][0-9a-z]+$\").test(String(value).toLowerCase());\n }\n\n /**\n * Determine if the given value is falsy.\n *\n */\n isFalsy(value) {\n return [0, '0', false, 'false'].includes(value);\n }\n\n /**\n * Determine if the given value is within the given array of options.\n *\n */\n isIn(value, options) {\n return (typeof options === 'string' ? options.split(',') : options).includes(value);\n }\n\n /**\n * Determine if the given value is an integer.\n *\n */\n isInteger(value) {\n return Number.isInteger(value) && parseInt(value).toString() === value.toString();\n }\n\n /**\n * Determine if the given value is a JSON string.\n *\n */\n isJson(value) {\n try {\n return typeof JSON.parse(value) === 'object';\n } catch (e) {\n return false;\n }\n }\n\n /**\n * Determine if the given number is less than or equal to the maximum limit.\n *\n */\n isMax(value, limit) {\n return parseFloat(value) <= limit;\n }\n\n /**\n * Determine if the given number is greater than or equal to the minimum limit.\n *\n */\n isMin(value, limit) {\n return parseFloat(value) >= limit;\n }\n\n /**\n * Determine if the given value string length is less than or equal to the maximum limit.\n *\n */\n isMaxLength(value, limit) {\n return typeof value === 'string' ? value.length <= limit : false;\n }\n\n /**\n * Determine if the given value string length is greater than or equal to the minimum limit.\n *\n */\n isMinLength(value, limit) {\n return typeof value === 'string' ? value.length >= limit : false;\n }\n\n /**\n * Determine if the given value is not within the given array of options.\n *\n */\n isNotIn(value, options) {\n return !this.isIn(value, options);\n }\n\n /**\n * Determine if the given value is numeric (an integer or a float).\n *\n */\n isNumeric(value) {\n return !isNaN(parseFloat(value)) && isFinite(value);\n }\n\n /**\n * Determine if the given value is optional.\n *\n */\n isOptional(value) {\n return [null, undefined, ''].includes(value);\n }\n\n /**\n * Determine if the given value satisifies the given regular expression.\n *\n */\n isRegexMatch(value, expression) {\n return new RegExp(expression).test(String(value));\n }\n\n /**\n * Determine if the given value is present.\n *\n */\n isRequired(value) {\n return !this.isOptional(value);\n }\n\n /**\n * Determine if the given value is the same as another given value.\n *\n */\n isSame(value, same) {\n return value == same;\n }\n\n /**\n * Determine if the given value starts with another given value.\n *\n */\n isStartingWith(value, sub) {\n return this.isString(value) && value.startsWith(sub);\n }\n\n /**\n * Determine if the given value is a string.\n *\n */\n isString(value) {\n return typeof value === 'string';\n }\n\n /**\n * Determine if the given value is truthy.\n *\n */\n isTruthy(value) {\n return [1, '1', true, 'true'].includes(value);\n }\n\n /**\n * Determine if the given value is a valid URL.\n *\n */\n isUrl(value) {\n let regex = \"^(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_]*)?$\";\n\n return new RegExp(regex).test(String(value).toLowerCase());\n }\n\n /**\n * Determine if the given value is a valid UUID.\n *\n */\n isUuid(value) {\n let regex = \"^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$\";\n\n return new RegExp(regex).test(String(value).toLowerCase());\n }\n\n /**\n * Determine whether the given value meets the given rules.\n *\n */\n is(value, rules = []) {\n for (let index in rules = this._prepare(value, rules)) {\n if (!this[`is${rules[index][1]}`].apply(this, [value, rules[index][2].join(':')])) {\n return rules[index][0];\n }\n }\n\n return true;\n }\n\n /**\n * Determine whether the given value meets the given rules.\n *\n */\n isValid(value, rules = []) {\n return this.is(value, rules) === true;\n }\n\n /**\n * Replace the default error messages with a new set.\n *\n */\n setErrorMessages(messages) {\n this.messages = messages;\n }\n\n /**\n * Add or replace an error message.\n *\n */\n setErrorMessage(key, message) {\n this.messages[key] = message;\n }\n\n /**\n * Replace the default locale with a new value.\n *\n */\n setLocale(locale) {\n this.locale = locale;\n }\n\n /**\n * Replace the default field name with a new value.\n */\n setDefaultFieldName(fieldName) {\n this.defaultFieldName = fieldName;\n }\n}\n\n/**\n * Create an instance of the library.\n *\n */\nwindow.Iodine = new Iodine();\n"],"names":["pact","state","value","s","o","_settle","bind","v","then","observer","_Pact","prototype","onFulfilled","onRejected","result","this","callback","e","_this","Iodine","constructor","locale","undefined","messages","_defaultMessages","defaultFieldName","_dateCompare","first","second","type","equals","isDate","isInteger","getTime","after","afterOrEqual","array","before","beforeOrEqual","boolean","date","different","endingWith","email","falsy","in","integer","json","max","min","maxLength","minLength","notIn","numeric","optional","regexMatch","required","same","startingWith","string","truthy","url","uuid","_prepare","rules","length","isOptional","filter","rule","map","_titleCase","split","shift","slice","toUpperCase","addRule","name","closure","asyncIs","target","body","check","keys","key","push","reject","i","_cycle","thenable","index","apply","join","asyncIsValid","getErrorMessage","args","param","field","chunks","includes","Date","parseInt","toLocaleTimeString","year","month","day","hour","minute","hour12","message","replace","isAfter","isAfterOrEqual","isArray","Array","isBefore","isBeforeOrEqual","isBoolean","Object","toString","call","isNaN","isDifferent","isEndingWith","sub","isString","endsWith","isEmail","RegExp","test","String","toLowerCase","isFalsy","isIn","options","Number","isJson","JSON","parse","isMax","limit","parseFloat","isMin","isMaxLength","isMinLength","isNotIn","isNumeric","isFinite","isRegexMatch","expression","isRequired","isSame","isStartingWith","startsWith","isTruthy","isUrl","isUuid","is","isValid","setErrorMessages","setErrorMessage","setLocale","setDefaultFieldName","fieldName","window"],"mappings":"gOAuCO,WAAiBA,EAAMC,EAAOC,GACpC,IAAKF,EAAKG,EAAG,CACZ,GAAID,eAAwB,CAC3B,IAAIA,EAAMC,EAOT,YADAD,EAAME,EAAIC,EAAQC,KAAK,KAAMN,EAAMC,IALvB,EAARA,IACHA,EAAQC,EAAMC,GAEfD,EAAQA,EAAMK,EAMhB,GAAIL,GAASA,EAAMM,KAElB,YADAN,EAAMM,KAAKH,EAAQC,KAAK,KAAMN,EAAMC,GAAQI,EAAQC,KAAK,KAAMN,EAAM,IAGtEA,EAAKG,EAAIF,EACTD,EAAKO,EAAIL,EACT,MAAMO,EAAWT,EAAKI,EAClBK,GACHA,EAAST,IA3DL,QAA4B,WAClC,cAiCA,OAhCAU,EAAMC,UAAUH,KAAO,SAASI,EAAaC,GAC5C,MAAMC,EAAS,MACTb,EAAQc,KAAKZ,EACnB,GAAIF,EAAO,CACV,MAAMe,EAAmB,EAARf,EAAYW,EAAcC,EAC3C,GAAIG,EAAU,CACb,IACCX,EAAQS,EAAQ,EAAGE,EAASD,KAAKR,IAChC,MAAOU,GACRZ,EAAQS,EAAQ,EAAGG,GAEpB,OAAOH,EAEP,YAiBF,OAdAC,KAAKX,EAAI,SAASc,GACjB,IACC,MAAMhB,EAAQgB,EAAMX,EACN,EAAVW,EAAMf,EACTE,EAAQS,EAAQ,EAAGF,EAAcA,EAAYV,GAASA,GAC5CW,EACVR,EAAQS,EAA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,OAAOzJ,GAGL,WAAW6H,OAFC,6EAEaC,KAAKC,OAAO/H,GAAOgI,eAO9C0B,GAAG1J,EAAO8D,EAAQ,IAChB,IAAK,IAAIyB,KAASzB,EAAQjD,KAAKgD,SAAS7D,EAAO8D,GAC7C,IAAKjD,KAAM,KAAIiD,EAAMyB,GAAO,MAAMC,MAAM3E,KAAM,CAACb,EAAO8D,EAAMyB,GAAO,GAAGE,KAAK,OACzE,OAAO3B,EAAMyB,GAAO,GAIxB,SAOFoE,QAAQ3J,EAAO8D,EAAQ,IACrB,OAAiC,SAArB4F,GAAG1J,EAAO8D,GAOxB8F,iBAAiBvI,GACfR,KAAKQ,SAAWA,EAOlBwI,gBAAgB5E,EAAKyB,GACnB7F,KAAKQ,SAAS4D,GAAOyB,EAOvBoD,UAAU3I,GACRN,KAAKM,OAASA,EAMhB4I,oBAAoBC,GAClBnJ,KAAKU,iBAAmByI,GAQ5BC,OAAOhJ,OAAS,IAAIA"} \ No newline at end of file +{"version":3,"file":"iodine.min.umd.js","sources":["../src/iodine.js"],"sourcesContent":["/*\n|--------------------------------------------------------------------------\n| Iodine - JavaScript Library\n|--------------------------------------------------------------------------\n|\n| This library contains a collection of useful validation rules that can\n| be used to quickly verify whether items meet certain conditions.\n|\n*/\nexport class Iodine {\n /**\n * Constructor.\n *\n */\n constructor() {\n this.locale = undefined;\n\n this.messages = this._defaultMessages();\n\n this.defaultFieldName = 'Value';\n }\n\n /**\n * @internal.\n *\n */\n _dateCompare(first, second, type, equals = false) {\n if (!this.isDate(first)) return false;\n\n if (!this.isDate(second) && !this.isInteger(second)) return false;\n\n second = typeof second === 'number' ? second : second.getTime();\n\n if (type === 'less' && equals) return first.getTime() <= second;\n if (type === 'less' && !equals) return first.getTime() < second;\n if (type === 'more' && equals) return first.getTime() >= second;\n if (type === 'more' && !equals) return first.getTime() > second;\n }\n\n /**\n * @internal.\n *\n */\n _defaultMessages() {\n return {\n after : `The date must be after: '[PARAM]'`,\n afterOrEqual : `The date must be after or equal to: '[PARAM]'`,\n array : `[FIELD] must be an array`,\n before : `The date must be before: '[PARAM]'`,\n beforeOrEqual : `The date must be before or equal to: '[PARAM]'`,\n boolean : `[FIELD] must be true or false`,\n date : `[FIELD] must be a date`,\n different : `[FIELD] must be different to '[PARAM]'`,\n endingWith : `[FIELD] must end with '[PARAM]'`,\n email : `[FIELD] must be a valid email address`,\n falsy : `[FIELD] must be a falsy value (false, 'false', 0 or '0')`,\n in : `[FIELD] must be one of the following options: [PARAM]`,\n integer : `[FIELD] must be an integer`,\n json : `[FIELD] must be a parsable JSON object string`,\n max : `[FIELD] must be less than or equal to [PARAM]`,\n min : `[FIELD] must be greater than or equal to [PARAM]`,\n maxLength : `[FIELD] must not be greater than '[PARAM]' in character length`,\n minLength : `[FIELD] must not be less than '[PARAM]' character length`,\n notIn : `[FIELD] must not be one of the following options: [PARAM]`,\n numeric : `[FIELD] must be numeric`,\n optional : `[FIELD] is optional`,\n regexMatch : `[FIELD] must satisify the regular expression: [PARAM]`,\n required : `[FIELD] must be present`,\n same : `[FIELD] must be '[PARAM]'`,\n startingWith : `[FIELD] must start with '[PARAM]'`,\n string : `[FIELD] must be a string`,\n truthy : `[FIELD] must be a truthy value (true, 'true', 1 or '1')`,\n url : `[FIELD] must be a valid url`,\n uuid : `[FIELD] must be a valid UUID`,\n };\n }\n\n /**\n * @internal.\n *\n */\n _prepare(value, rules = []) {\n if (!rules.length) return [];\n\n if (rules[0] === 'optional' && this.isOptional(value)) return [];\n\n return rules.filter(rule => rule !== 'optional')\n .map(rule => [rule, this._titleCase(rule.split(':').shift()), rule.split(':').slice(1)]);\n }\n\n /**\n * @internal.\n *\n */\n _titleCase(value) {\n return `${value[0].toUpperCase()}${value.slice(1)}`;\n }\n\n /**\n * Attach a custom validation rule to the library.\n *\n */\n addRule(name, closure) {\n Iodine.prototype[`is${this._titleCase(name)}`] = closure;\n }\n\n /**\n * Determine whether the given value meets the given synchronous or asynchronous rules.\n *\n */\n async asyncIs(value, rules = []) {\n for (let index in rules = this._prepare(value, rules)) {\n if (!await this[`is${rules[index][1]}`].apply(this, [value, rules[index][2].join(':')])) {\n return await rules[index][0];\n }\n }\n\n return true;\n }\n\n /**\n * Determine whether the given value meets the given rules.\n *\n */\n async asyncIsValid(value, rules = []) {\n return await this.asyncIs(value, rules) === true;\n }\n\n /**\n * Retrieve an error message for the given rule.\n *\n */\n getErrorMessage(rule, args = undefined) {\n let { param, field } = typeof args === 'object' ? args : { param: args, field: undefined };\n\n const chunks = rule.split(':');\n\n let key = chunks.shift();\n\n param = param || chunks.join(':');\n\n if (['after', 'afterOrEqual', 'before', 'beforeOrEqual'].includes(key)) {\n param = new Date(parseInt(param)).toLocaleTimeString(this.locale, {\n year : 'numeric',\n month : 'short',\n day : 'numeric',\n hour : '2-digit',\n minute : 'numeric',\n hour12 : false,\n });\n }\n\n let message = [null, undefined, ''].includes(param)\n ? this.messages[key]\n : this.messages[key].replace('[PARAM]', param);\n\n return [null, undefined, ''].includes(field)\n ? message.replace('[FIELD]', this.defaultFieldName)\n : message.replace('[FIELD]', field);\n }\n\n /**\n * Determine if the given date is after another given date.\n *\n */\n isAfter(value, after) {\n return this._dateCompare(value, after, 'more', false);\n }\n\n /**\n * Determine if the given date is after or equal to another given date.\n *\n */\n isAfterOrEqual(value, after) {\n return this._dateCompare(value, after, 'more', true);\n }\n\n /**\n * Determine if the given value is an array.\n *\n */\n isArray(value) {\n return Array.isArray(value);\n }\n\n /**\n * Determine if the given date is before another given date.\n *\n */\n isBefore(value, before) {\n return this._dateCompare(value, before, 'less', false);\n }\n\n /**\n * Determine if the given date is before or equal to another given date.\n *\n */\n isBeforeOrEqual(value, before) {\n return this._dateCompare(value, before, 'less', true);\n }\n\n /**\n * Determine if the given value is a boolean.\n *\n */\n isBoolean(value) {\n return [true, false].includes(value);\n }\n\n /**\n * Determine if the given value is a date object.\n *\n */\n isDate(value) {\n return (value && Object.prototype.toString.call(value) === '[object Date]' && !isNaN(value));\n }\n\n /**\n * Determine if the given value is different to another given value.\n *\n */\n isDifferent(value, different) {\n return value != different;\n }\n\n /**\n * Determine if the given value ends with another given value.\n *\n */\n isEndingWith(value, sub) {\n return this.isString(value) && value.endsWith(sub);\n }\n\n /**\n * Determine if the given value is a valid email address.\n *\n */\n isEmail(value) {\n return new RegExp(\"^\\\\S+@\\\\S+[\\\\.][0-9a-z]+$\").test(String(value).toLowerCase());\n }\n\n /**\n * Determine if the given value is falsy.\n *\n */\n isFalsy(value) {\n return [0, '0', false, 'false'].includes(value);\n }\n\n /**\n * Determine if the given value is within the given array of options.\n *\n */\n isIn(value, options) {\n return (typeof options === 'string' ? options.split(',') : options).includes(value);\n }\n\n /**\n * Determine if the given value is an integer.\n *\n */\n isInteger(value) {\n return Number.isInteger(value) && parseInt(value).toString() === value.toString();\n }\n\n /**\n * Determine if the given value is a JSON string.\n *\n */\n isJson(value) {\n try {\n return typeof JSON.parse(value) === 'object';\n } catch (e) {\n return false;\n }\n }\n\n /**\n * Determine if the given number is less than or equal to the maximum limit.\n *\n */\n isMax(value, limit) {\n return parseFloat(value) <= limit;\n }\n\n /**\n * Determine if the given number is greater than or equal to the minimum limit.\n *\n */\n isMin(value, limit) {\n return parseFloat(value) >= limit;\n }\n\n /**\n * Determine if the given value string length is less than or equal to the maximum limit.\n *\n */\n isMaxLength(value, limit) {\n return typeof value === 'string' ? value.length <= limit : false;\n }\n\n /**\n * Determine if the given value string length is greater than or equal to the minimum limit.\n *\n */\n isMinLength(value, limit) {\n return typeof value === 'string' ? value.length >= limit : false;\n }\n\n /**\n * Determine if the given value is not within the given array of options.\n *\n */\n isNotIn(value, options) {\n return !this.isIn(value, options);\n }\n\n /**\n * Determine if the given value is numeric (an integer or a float).\n *\n */\n isNumeric(value) {\n return !isNaN(parseFloat(value)) && isFinite(value);\n }\n\n /**\n * Determine if the given value is optional.\n *\n */\n isOptional(value) {\n return [null, undefined, ''].includes(value);\n }\n\n /**\n * Determine if the given value satisifies the given regular expression.\n *\n */\n isRegexMatch(value, expression) {\n return new RegExp(expression).test(String(value));\n }\n\n /**\n * Determine if the given value is present.\n *\n */\n isRequired(value) {\n return !this.isOptional(value);\n }\n\n /**\n * Determine if the given value is the same as another given value.\n *\n */\n isSame(value, same) {\n return value == same;\n }\n\n /**\n * Determine if the given value starts with another given value.\n *\n */\n isStartingWith(value, sub) {\n return this.isString(value) && value.startsWith(sub);\n }\n\n /**\n * Determine if the given value is a string.\n *\n */\n isString(value) {\n return typeof value === 'string';\n }\n\n /**\n * Determine if the given value is truthy.\n *\n */\n isTruthy(value) {\n return [1, '1', true, 'true'].includes(value);\n }\n\n /**\n * Determine if the given value is a valid URL.\n *\n */\n isUrl(value) {\n let regex = \"^(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_]*)?$\";\n\n return new RegExp(regex).test(String(value).toLowerCase());\n }\n\n /**\n * Determine if the given value is a valid UUID.\n *\n */\n isUuid(value) {\n let regex = \"^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$\";\n\n return new RegExp(regex).test(String(value).toLowerCase());\n }\n\n /**\n * Determine whether the given value meets the given rules.\n *\n */\n is(value, rules = []) {\n for (let index in rules = this._prepare(value, rules)) {\n if (!this[`is${rules[index][1]}`].apply(this, [value, rules[index][2].join(':')])) {\n return rules[index][0];\n }\n }\n\n return true;\n }\n\n /**\n * Determine whether the given value meets the given rules.\n *\n */\n isValid(value, rules = []) {\n return this.is(value, rules) === true;\n }\n\n /**\n * Replace the default error messages with a new set.\n *\n */\n setErrorMessages(messages) {\n this.messages = messages;\n }\n\n /**\n * Add or replace an error message.\n *\n */\n setErrorMessage(key, message) {\n this.messages[key] = message;\n }\n\n /**\n * Replace the default locale with a new value.\n *\n */\n setLocale(locale) {\n this.locale = locale;\n }\n\n /**\n * Replace the default field name with a new value.\n *\n */\n setDefaultFieldName(fieldName) {\n this.defaultFieldName = fieldName;\n }\n}\n\n/**\n * Create an instance of the library.\n *\n */\nif(typeof window !== 'undefined') {\n window.Iodine = new Iodine();\n}\n"],"names":["pact","state","value","s","o","_settle","bind","v","then","observer","_Pact","prototype","onFulfilled","onRejected","result","this","callback","e","_this","Iodine","constructor","locale","undefined","messages","_defaultMessages","defaultFieldName","_dateCompare","first","second","type","equals","isDate","isInteger","getTime","after","afterOrEqual","array","before","beforeOrEqual","boolean","date","different","endingWith","email","falsy","in","integer","json","max","min","maxLength","minLength","notIn","numeric","optional","regexMatch","required","same","startingWith","string","truthy","url","uuid","_prepare","rules","length","isOptional","filter","rule","map","_titleCase","split","shift","slice","toUpperCase","addRule","name","closure","asyncIs","target","body","check","keys","key","push","reject","i","_cycle","thenable","index","apply","join","asyncIsValid","getErrorMessage","args","param","field","chunks","includes","Date","parseInt","toLocaleTimeString","year","month","day","hour","minute","hour12","message","replace","isAfter","isAfterOrEqual","isArray","Array","isBefore","isBeforeOrEqual","isBoolean","Object","toString","call","isNaN","isDifferent","isEndingWith","sub","isString","endsWith","isEmail","RegExp","test","String","toLowerCase","isFalsy","isIn","options","Number","isJson","JSON","parse","isMax","limit","parseFloat","isMin","isMaxLength","isMinLength","isNotIn","isNumeric","isFinite","isRegexMatch","expression","isRequired","isSame","isStartingWith","startsWith","isTruthy","isUrl","isUuid","is","isValid","setErrorMessages","setErrorMessage","setLocale","setDefaultFieldName","fieldName","window"],"mappings":"gOAuCO,WAAiBA,EAAMC,EAAOC,GACpC,IAAKF,EAAKG,EAAG,CACZ,GAAID,eAAwB,CAC3B,IAAIA,EAAMC,EAOT,YADAD,EAAME,EAAIC,EAAQC,KAAK,KAAMN,EAAMC,IALvB,EAARA,IACHA,EAAQC,EAAMC,GAEfD,EAAQA,EAAMK,EAMhB,GAA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,SACRA,OAAOhJ,OAAS,IAAIA"} \ No newline at end of file diff --git a/package.json b/package.json index 665b104..3a1e2f2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kingshott/iodine", - "version": "7.0.0", + "version": "7.0.1", "description": "A micro client-side validation library", "repository": { "type": "git", @@ -23,14 +23,14 @@ "author": "Matt Kingshott", "license": "MIT", "devDependencies": { - "@babel/core": "^7.13.15", - "@babel/preset-env": "^7.13.15", - "babel-jest": "^26.6.3", + "@babel/core": "^7.16.0", + "@babel/preset-env": "^7.16.4", + "babel-jest": "^27.4.2", "braces": "^3.0.2", - "jest": "^26.6.3", - "js-yaml": "^4.0.0", - "microbundle": "^0.13.0", - "prettier": "^2.2.1", - "serialize-javascript": "^5.0.1" + "jest": "^27.4.3", + "js-yaml": "^4.1.0", + "microbundle": "^0.14.2", + "prettier": "^2.5.0", + "serialize-javascript": "^6.0.0" } } diff --git a/resources/version.svg b/resources/version.svg index eeae978..ec32cbb 100644 --- a/resources/version.svg +++ b/resources/version.svg @@ -14,7 +14,7 @@ stable stable - v7.0.0 - v7.0.0 + v7.0.1 + v7.0.1 diff --git a/src/iodine.js b/src/iodine.js index 0f32be7..84078a4 100644 --- a/src/iodine.js +++ b/src/iodine.js @@ -447,6 +447,7 @@ export class Iodine { /** * Replace the default field name with a new value. + * */ setDefaultFieldName(fieldName) { this.defaultFieldName = fieldName; @@ -457,6 +458,6 @@ export class Iodine { * Create an instance of the library. * */ -if(typeof window !== undefined) { +if(typeof window !== 'undefined') { window.Iodine = new Iodine(); } diff --git a/tests/test.js b/tests/test.js index d636dbc..00d53ac 100644 --- a/tests/test.js +++ b/tests/test.js @@ -1,3 +1,8 @@ +/** + * @jest-environment jsdom + * + */ + import { Iodine as Library } from '../src/iodine'; window.Iodine = new Library();