You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

easy-object-validator

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

easy-object-validator - npm Package Compare versions

Comparing version

to
1.1.1

19

dist/validator.js
/**
* easy-object-valodator version 1.0.2
* easy-object-valodator version 1.1.1
*/

@@ -25,3 +25,5 @@ (function (global, factory) {

// 置反标志,如果为true,将校验结果置反
this.$flag = false;
this.$isOpposite = false;
// 必须标志
this.$isRequire = false;
// 最后执行所有校验规则

@@ -36,7 +38,12 @@ this.doValidate = function (value) {

}
if (!_this.$isRequire && (_this.value == null || _this.value === '')) {
return true;
}
return rule();
});
return _this.$flag ? !ret : ret;
return _this.$isOpposite ? !ret : ret;
};
}
Validate.type = type;

@@ -79,2 +86,3 @@

this.$isRequire = true;
this.$validRules.push(function () {

@@ -122,3 +130,3 @@ return _this2.value != null && _this2.value !== '';

not: function not() {
this.$flag = !this.$flag;
this.$isOpposite = !this.$isOpposite;
return this;

@@ -164,3 +172,4 @@ },

this.$validRules = [];
this.$flag = false;
this.$isOpposite = false;
this.$isRequire = false;
return this;

@@ -167,0 +176,0 @@ }

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.validator=e()}(this,function(){"use strict";function n(t){return Object.prototype.toString.call(t).slice(0,-1).slice(8).toLowerCase()}function r(){var n=this;if(!(this instanceof r))throw new Error("Validate should be called with the `new` keyword");this.$validRules=[],this.$flag=!1,this.doValidate=function(e){n.value=e;var t=n.$validRules.every(function(t){return"array"===r.type(t)?t.some(function(t){return t.doValidate(e)}):t()});return n.$flag?!t:t}}r.type=n,r.prototype={string:function(){return this.is("string")},number:function(){return this.is("number")},object:function(){return this.is("object")},array:function(){return this.is("array")},boolean:function(){return this.is("boolean")},isRequire:function(){var t=this;return this.$validRules.push(function(){return null!=t.value&&""!==t.value}),this},length:function(t){var e=this;return this.$validRules.push(function(){return e.value&&e.value.length===t}),this},test:function(t){var e=this;return this.$validRules.push(function(){return t.test(e.value)}),this},is:function(t){var e=this;return this.$validRules.push(function(){return n(e.value)===t}),this},not:function(){return this.$flag=!this.$flag,this},arrayOf:function(e){var t=this;if(!(e instanceof r))throw new TypeError("The parameter must be a instance of Validate");return this.$validRules.push(function(){return"array"===n(t.value)&&t.value.every(function(t){return e.doValidate(t)})}),this},oneOf:function(){for(var t=arguments.length,e=Array(t),n=0;n<t;n++)e[n]=arguments[n];if(!e.every(function(t){return t instanceof r}))throw new TypeError("The parameter must be a instance of Validate");return this.$validRules.push(e),this},reset:function(){return this.$validRules=[],this.$flag=!1,this}};var u=r;function o(r,i){var t=!1;return"object"===u.type(r)&&(t=Object.keys(i).every(function(t){var e=r[t],n=i[t];if(n instanceof u)return n.doValidate(e);if("object"===u.type(n))return o(e,n);throw new TypeError("The validator of "+t+" is not a right validator")})),t}var i=["extend","arguments","caller","length","prototype","apply","bind","call","toString","toLocaleString","name","constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","valueOf","$flag","$validRules","doValidate","value"];return o.extend=function(n){Object.keys(n).forEach(function(t){if(i.includes(t))throw new Error("The arrt `"+t+"` is reserved keyword");var e=n[t];if("function"!==u.type(e))throw new TypeError("The validate func must be a function");Object.defineProperty(u.prototype,t,{value:function(){var t=this;return this.$validRules.push(function(){return e(t.value)}),this},configurable:!0,enumerable:!1}),o[t]=function(){return(new u)[t]()}})},o.string=function(){return(new u).string()},o.number=function(){return(new u).number()},o.object=function(){return(new u).object()},o.array=function(){return(new u).array()},o.boolean=function(){return(new u).boolean()},o.isRequire=function(){return(new u).isRequire()},o.test=function(t){return(new u).test(t)},o.is=function(t){return(new u).is(t)},o.not=function(){return(new u).not()},o.arrayOf=function(t){return(new u).arrayOf(t)},o.oneOf=function(){var t;return(t=new u).oneOf.apply(t,arguments)},o.reset=function(){return(new u).reset()},o});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.validator=t()}(this,function(){"use strict";function n(e){return Object.prototype.toString.call(e).slice(0,-1).slice(8).toLowerCase()}function r(){var n=this;if(!(this instanceof r))throw new Error("Validate should be called with the `new` keyword");this.$validRules=[],this.$isOpposite=!1,this.$isRequire=!1,this.doValidate=function(t){n.value=t;var e=n.$validRules.every(function(e){return"array"===r.type(e)?e.some(function(e){return e.doValidate(t)}):!(n.$isRequire||null!=n.value&&""!==n.value)||e()});return n.$isOpposite?!e:e}}r.type=n,r.prototype={string:function(){return this.is("string")},number:function(){return this.is("number")},object:function(){return this.is("object")},array:function(){return this.is("array")},boolean:function(){return this.is("boolean")},isRequire:function(){var e=this;return this.$isRequire=!0,this.$validRules.push(function(){return null!=e.value&&""!==e.value}),this},length:function(e){var t=this;return this.$validRules.push(function(){return t.value&&t.value.length===e}),this},test:function(e){var t=this;return this.$validRules.push(function(){return e.test(t.value)}),this},is:function(e){var t=this;return this.$validRules.push(function(){return n(t.value)===e}),this},not:function(){return this.$isOpposite=!this.$isOpposite,this},arrayOf:function(t){var e=this;if(!(t instanceof r))throw new TypeError("The parameter must be a instance of Validate");return this.$validRules.push(function(){return"array"===n(e.value)&&e.value.every(function(e){return t.doValidate(e)})}),this},oneOf:function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];if(!t.every(function(e){return e instanceof r}))throw new TypeError("The parameter must be a instance of Validate");return this.$validRules.push(t),this},reset:function(){return this.$validRules=[],this.$isOpposite=!1,this.$isRequire=!1,this}};var u=r;function o(r,i){var e=!1;return"object"===u.type(r)&&(e=Object.keys(i).every(function(e){var t=r[e],n=i[e];if(n instanceof u)return n.doValidate(t);if("object"===u.type(n))return o(t,n);throw new TypeError("The validator of "+e+" is not a right validator")})),e}var i=["extend","arguments","caller","length","prototype","apply","bind","call","toString","toLocaleString","name","constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","valueOf","$flag","$validRules","doValidate","value"];return o.extend=function(n){Object.keys(n).forEach(function(e){if(i.includes(e))throw new Error("The arrt `"+e+"` is reserved keyword");var t=n[e];if("function"!==u.type(t))throw new TypeError("The validate func must be a function");Object.defineProperty(u.prototype,e,{value:function(){var e=this;return this.$validRules.push(function(){return t(e.value)}),this},configurable:!0,enumerable:!1}),o[e]=function(){return(new u)[e]()}})},o.string=function(){return(new u).string()},o.number=function(){return(new u).number()},o.object=function(){return(new u).object()},o.array=function(){return(new u).array()},o.boolean=function(){return(new u).boolean()},o.isRequire=function(){return(new u).isRequire()},o.test=function(e){return(new u).test(e)},o.is=function(e){return(new u).is(e)},o.not=function(){return(new u).not()},o.arrayOf=function(e){return(new u).arrayOf(e)},o.oneOf=function(){var e;return(e=new u).oneOf.apply(e,arguments)},o.reset=function(){return(new u).reset()},o});
{
"name": "easy-object-validator",
"version": "1.1.0",
"version": "1.1.1",
"description": "深度校验一个对象的属性值是否合法",

@@ -9,3 +9,4 @@ "main": "dist/validator.js",

"build": "rollup --config rollup.config.js",
"test": "jest"
"test": "jest",
"publish": "npm run build && npm publish"
},

@@ -12,0 +13,0 @@ "keywords": [

@@ -173,3 +173,4 @@ const Validate = require('../src/Validate');

e: validator.boolean(),
f: validator.not().isRequire()
f: validator.not().isRequire(),
g: validator.string()
})).toBeTruthy();

@@ -176,0 +177,0 @@