@yorkjs/validator
Advanced tools
Comparing version 0.0.4 to 0.0.5
/** | ||
* validator.js v0.0.4 | ||
* validator.js v0.0.5 | ||
* (c) 2021-2022 musicode | ||
@@ -165,5 +165,5 @@ * Released under the MIT License. | ||
if (isObject(name)) { | ||
Object.assign(this.rules, name); | ||
extend(this.rules, name); | ||
if (isObject(handler)) { | ||
Object.assign(this.messages, handler); | ||
extend(this.messages, handler); | ||
} | ||
@@ -246,5 +246,5 @@ } | ||
*/ | ||
const version = "0.0.4"; | ||
const version = "0.0.5"; | ||
export { Validator, checkArray, checkBoolean, checkDate, checkDateTime, checkEnum, checkInteger, checkNumber, checkObject, checkString, version }; | ||
//# sourceMappingURL=validator.esm.js.map |
@@ -1,2 +0,2 @@ | ||
const{toString:t}=Object.prototype;function e(e){return t.call(e).toLowerCase().slice(8,-1)}function n(t){return!(!t||"object"!==e(t))}function i(t,e){for(let n in e)t[n]=e[n]}function r(t,n){if(!Array.isArray(n))return"type";const{length:i}=n;if(void 0!==t.min&&i<t.min)return"min";if(void 0!==t.max&&i>t.max)return"max";const{itemType:r}=t;if(r)for(let t=0;t<i;t++)if(e(n[t])!==r)return"itemType"}function s(t,e){return"boolean"!=typeof e?"type":void 0!==t.value&&t.value!==e?"value":void 0}function o(t,e){if("string"!=typeof e)return"type";if(""===e){if(!0===t.empty)return;return"empty"}if(void 0!==t.min&&e.length<t.min)return"min";if(void 0!==t.max&&e.length>t.max)return"max";if(void 0!==t.pattern&&!t.pattern.test(e))return"pattern";if(void 0!==t.custom){const n=t.custom(e);if(n)return n}}const u=/^\d{4}\-\d{2}\-\d{2}$/;function a(t,e){const n={};return i(n,t),i(n,{type:"string",pattern:u}),o(n,e)}const f=/^\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}$/;function c(t,e){const n={};return i(n,t),i(n,{type:"string",pattern:f}),o(n,e)}function m(t,e){if(!Array.isArray(t.values)||t.values.indexOf(e)<0)return"type"}function p(t,e){return"number"!=typeof e||e%1!=0?"type":void 0!==t.min&&e<t.min?"min":void 0!==t.max&&e>t.max?"max":void 0}function d(t,e){if("number"!=typeof e||isNaN(e))return"type";if(void 0!==t.min&&e<t.min)return"min";if(void 0!==t.max&&e>t.max)return"max";if(void 0!==t.precision){const n=(""+e).split(".");if(2===n.length&&n[1].length>t.precision)return"precision"}}function l(t,e){if(!n(e))return"type"}class y{constructor(){this.rules={int:p,integer:p,number:d,string:o,bool:s,boolean:s,enum:m,array:r,object:l,date:a,dateTime:c},this.messages={}}add(t,e,i){n(t)?(Object.assign(this.rules,t),n(e)&&Object.assign(this.messages,e)):(this.rules[t]=e,this.messages[t]=i)}validate(t,i,r){let s;for(let o in i){const u=i[o];let a,f;switch(e(u)){case"string":a={type:u};break;case"array":a={type:"enum",values:u};break;case"regexp":a={type:"string",pattern:u};break;default:a=u}if(!n(a)||!a.type)throw new Error(`${o}'s rule is not found.`);if(void 0!==t[o])f=this.rules[a.type](a,t[o],t);else{if(!1===a.required)continue;f="required"}if(f){let t=r&&r[o]&&r[o][f];switch("string"!=typeof t&&"function"!=typeof t&&(t=this.messages[a.type]&&this.messages[a.type][f]),s||(s={}),typeof t){case"string":s[o]=t;break;case"function":s[o]=t(a);break;default:s[o]=f}}}return s}}const g="0.0.4";export{y as Validator,r as checkArray,s as checkBoolean,a as checkDate,c as checkDateTime,m as checkEnum,p as checkInteger,d as checkNumber,l as checkObject,o as checkString,g as version}; | ||
const{toString:t}=Object.prototype;function e(e){return t.call(e).toLowerCase().slice(8,-1)}function n(t){return!(!t||"object"!==e(t))}function i(t,e){for(let n in e)t[n]=e[n]}function r(t,n){if(!Array.isArray(n))return"type";const{length:i}=n;if(void 0!==t.min&&i<t.min)return"min";if(void 0!==t.max&&i>t.max)return"max";const{itemType:r}=t;if(r)for(let t=0;t<i;t++)if(e(n[t])!==r)return"itemType"}function o(t,e){return"boolean"!=typeof e?"type":void 0!==t.value&&t.value!==e?"value":void 0}function s(t,e){if("string"!=typeof e)return"type";if(""===e){if(!0===t.empty)return;return"empty"}if(void 0!==t.min&&e.length<t.min)return"min";if(void 0!==t.max&&e.length>t.max)return"max";if(void 0!==t.pattern&&!t.pattern.test(e))return"pattern";if(void 0!==t.custom){const n=t.custom(e);if(n)return n}}const u=/^\d{4}\-\d{2}\-\d{2}$/;function a(t,e){const n={};return i(n,t),i(n,{type:"string",pattern:u}),s(n,e)}const f=/^\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}$/;function c(t,e){const n={};return i(n,t),i(n,{type:"string",pattern:f}),s(n,e)}function m(t,e){if(!Array.isArray(t.values)||t.values.indexOf(e)<0)return"type"}function p(t,e){return"number"!=typeof e||e%1!=0?"type":void 0!==t.min&&e<t.min?"min":void 0!==t.max&&e>t.max?"max":void 0}function d(t,e){if("number"!=typeof e||isNaN(e))return"type";if(void 0!==t.min&&e<t.min)return"min";if(void 0!==t.max&&e>t.max)return"max";if(void 0!==t.precision){const n=(""+e).split(".");if(2===n.length&&n[1].length>t.precision)return"precision"}}function l(t,e){if(!n(e))return"type"}class y{constructor(){this.rules={int:p,integer:p,number:d,string:s,bool:o,boolean:o,enum:m,array:r,object:l,date:a,dateTime:c},this.messages={}}add(t,e,r){n(t)?(i(this.rules,t),n(e)&&i(this.messages,e)):(this.rules[t]=e,this.messages[t]=r)}validate(t,i,r){let o;for(let s in i){const u=i[s];let a,f;switch(e(u)){case"string":a={type:u};break;case"array":a={type:"enum",values:u};break;case"regexp":a={type:"string",pattern:u};break;default:a=u}if(!n(a)||!a.type)throw new Error(`${s}'s rule is not found.`);if(void 0!==t[s])f=this.rules[a.type](a,t[s],t);else{if(!1===a.required)continue;f="required"}if(f){let t=r&&r[s]&&r[s][f];switch("string"!=typeof t&&"function"!=typeof t&&(t=this.messages[a.type]&&this.messages[a.type][f]),o||(o={}),typeof t){case"string":o[s]=t;break;case"function":o[s]=t(a);break;default:o[s]=f}}}return o}}const v="0.0.5";export{y as Validator,r as checkArray,o as checkBoolean,a as checkDate,c as checkDateTime,m as checkEnum,p as checkInteger,d as checkNumber,l as checkObject,s as checkString,v as version}; | ||
//# sourceMappingURL=validator.esm.min.js.map |
/** | ||
* validator.js v0.0.4 | ||
* validator.js v0.0.5 | ||
* (c) 2021-2022 musicode | ||
@@ -171,5 +171,5 @@ * Released under the MIT License. | ||
if (isObject(name)) { | ||
Object.assign(this.rules, name); | ||
extend(this.rules, name); | ||
if (isObject(handler)) { | ||
Object.assign(this.messages, handler); | ||
extend(this.messages, handler); | ||
} | ||
@@ -251,3 +251,3 @@ } | ||
*/ | ||
var version = "0.0.4"; | ||
var version = "0.0.5"; | ||
@@ -254,0 +254,0 @@ exports.Validator = Validator; |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Validator={})}(this,(function(e){"use strict";var t=Object.prototype.toString;function r(e){return t.call(e).toLowerCase().slice(8,-1)}function i(e){return!(!e||"object"!==r(e))}function n(e,t){for(var r in t)e[r]=t[r]}function o(e,t){if(!Array.isArray(t))return"type";var i=t.length;if(void 0!==e.min&&i<e.min)return"min";if(void 0!==e.max&&i>e.max)return"max";var n=e.itemType;if(n)for(var o=0;o<i;o++)if(r(t[o])!==n)return"itemType"}function a(e,t){return"boolean"!=typeof t?"type":void 0!==e.value&&e.value!==t?"value":void 0}function s(e,t){if("string"!=typeof t)return"type";if(""===t){if(!0===e.empty)return;return"empty"}if(void 0!==e.min&&t.length<e.min)return"min";if(void 0!==e.max&&t.length>e.max)return"max";if(void 0!==e.pattern&&!e.pattern.test(t))return"pattern";if(void 0!==e.custom){var r=e.custom(t);if(r)return r}}var u=/^\d{4}\-\d{2}\-\d{2}$/;function f(e,t){var r={};return n(r,e),n(r,{type:"string",pattern:u}),s(r,t)}var c=/^\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}$/;function p(e,t){var r={};return n(r,e),n(r,{type:"string",pattern:c}),s(r,t)}function d(e,t){if(!Array.isArray(e.values)||e.values.indexOf(t)<0)return"type"}function m(e,t){return"number"!=typeof t||t%1!=0?"type":void 0!==e.min&&t<e.min?"min":void 0!==e.max&&t>e.max?"max":void 0}function v(e,t){if("number"!=typeof t||isNaN(t))return"type";if(void 0!==e.min&&t<e.min)return"min";if(void 0!==e.max&&t>e.max)return"max";if(void 0!==e.precision){var r=(""+t).split(".");if(2===r.length&&r[1].length>e.precision)return"precision"}}function y(e,t){if(!i(t))return"type"}var l=function(){this.rules={int:m,integer:m,number:v,string:s,bool:a,boolean:a,enum:d,array:o,object:y,date:f,dateTime:p},this.messages={}};l.prototype.add=function(e,t,r){i(e)?(Object.assign(this.rules,e),i(t)&&Object.assign(this.messages,t)):(this.rules[e]=t,this.messages[e]=r)},l.prototype.validate=function(e,t,n){var o;for(var a in t){var s=t[a],u=void 0;switch(r(s)){case"string":u={type:s};break;case"array":u={type:"enum",values:s};break;case"regexp":u={type:"string",pattern:s};break;default:u=s}if(!i(u)||!u.type)throw new Error(a+"'s rule is not found.");var f=void 0;if(void 0!==e[a])f=this.rules[u.type](u,e[a],e);else{if(!1===u.required)continue;f="required"}if(f){var c=n&&n[a]&&n[a][f];switch("string"!=typeof c&&"function"!=typeof c&&(c=this.messages[u.type]&&this.messages[u.type][f]),o||(o={}),typeof c){case"string":o[a]=c;break;case"function":o[a]=c(u);break;default:o[a]=f}}}return o};e.Validator=l,e.checkArray=o,e.checkBoolean=a,e.checkDate=f,e.checkDateTime=p,e.checkEnum=d,e.checkInteger=m,e.checkNumber=v,e.checkObject=y,e.checkString=s,e.version="0.0.4",Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Validator={})}(this,(function(e){"use strict";var t=Object.prototype.toString;function r(e){return t.call(e).toLowerCase().slice(8,-1)}function i(e){return!(!e||"object"!==r(e))}function n(e,t){for(var r in t)e[r]=t[r]}function o(e,t){if(!Array.isArray(t))return"type";var i=t.length;if(void 0!==e.min&&i<e.min)return"min";if(void 0!==e.max&&i>e.max)return"max";var n=e.itemType;if(n)for(var o=0;o<i;o++)if(r(t[o])!==n)return"itemType"}function a(e,t){return"boolean"!=typeof t?"type":void 0!==e.value&&e.value!==t?"value":void 0}function u(e,t){if("string"!=typeof t)return"type";if(""===t){if(!0===e.empty)return;return"empty"}if(void 0!==e.min&&t.length<e.min)return"min";if(void 0!==e.max&&t.length>e.max)return"max";if(void 0!==e.pattern&&!e.pattern.test(t))return"pattern";if(void 0!==e.custom){var r=e.custom(t);if(r)return r}}var s=/^\d{4}\-\d{2}\-\d{2}$/;function f(e,t){var r={};return n(r,e),n(r,{type:"string",pattern:s}),u(r,t)}var c=/^\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}$/;function p(e,t){var r={};return n(r,e),n(r,{type:"string",pattern:c}),u(r,t)}function d(e,t){if(!Array.isArray(e.values)||e.values.indexOf(t)<0)return"type"}function m(e,t){return"number"!=typeof t||t%1!=0?"type":void 0!==e.min&&t<e.min?"min":void 0!==e.max&&t>e.max?"max":void 0}function v(e,t){if("number"!=typeof t||isNaN(t))return"type";if(void 0!==e.min&&t<e.min)return"min";if(void 0!==e.max&&t>e.max)return"max";if(void 0!==e.precision){var r=(""+t).split(".");if(2===r.length&&r[1].length>e.precision)return"precision"}}function y(e,t){if(!i(t))return"type"}var l=function(){this.rules={int:m,integer:m,number:v,string:u,bool:a,boolean:a,enum:d,array:o,object:y,date:f,dateTime:p},this.messages={}};l.prototype.add=function(e,t,r){i(e)?(n(this.rules,e),i(t)&&n(this.messages,t)):(this.rules[e]=t,this.messages[e]=r)},l.prototype.validate=function(e,t,n){var o;for(var a in t){var u=t[a],s=void 0;switch(r(u)){case"string":s={type:u};break;case"array":s={type:"enum",values:u};break;case"regexp":s={type:"string",pattern:u};break;default:s=u}if(!i(s)||!s.type)throw new Error(a+"'s rule is not found.");var f=void 0;if(void 0!==e[a])f=this.rules[s.type](s,e[a],e);else{if(!1===s.required)continue;f="required"}if(f){var c=n&&n[a]&&n[a][f];switch("string"!=typeof c&&"function"!=typeof c&&(c=this.messages[s.type]&&this.messages[s.type][f]),o||(o={}),typeof c){case"string":o[a]=c;break;case"function":o[a]=c(s);break;default:o[a]=f}}}return o};e.Validator=l,e.checkArray=o,e.checkBoolean=a,e.checkDate=f,e.checkDateTime=p,e.checkEnum=d,e.checkInteger=m,e.checkNumber=v,e.checkObject=y,e.checkString=u,e.version="0.0.5",Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=validator.min.js.map |
{ | ||
"name": "@yorkjs/validator", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "validate data", | ||
@@ -5,0 +5,0 @@ "main": "dist/validator.js", |
@@ -21,3 +21,3 @@ import { checkArray } from './checkArray'; | ||
*/ | ||
declare const version = "0.0.4"; | ||
declare const version = "0.0.5"; | ||
export { Validator, checkArray, checkBoolean, checkDate, checkDateTime, checkEnum, checkInteger, checkNumber, checkObject, checkString, version, }; |
30836