Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rsuite-schema

Package Overview
Dependencies
Maintainers
2
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rsuite-schema - npm Package Compare versions

Comparing version 0.0.1-alpha.6 to 0.0.1-alpha.7

2

lib/index.js

@@ -11,3 +11,3 @@ 'use strict';

Object.keys(_Schema).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key === "default") return;
Object.defineProperty(exports, key, {

@@ -14,0 +14,0 @@ enumerable: true,

@@ -103,3 +103,3 @@ 'use strict';

_get(Object.getPrototypeOf(StringType.prototype), 'addValidator', this).call(this, function (v) {
return strArr.includes(v);
return ~strArr.indexOf(v);
}, errorMessage);

@@ -106,0 +106,0 @@ return this;

@@ -29,3 +29,3 @@ 'use strict';

if (!this.required && (typeof value === 'undefined' || value === null || value === '')) {
if (!this.required && (typeof value === 'undefined' || value.length === 0)) {
return { hasError: false };

@@ -50,15 +50,4 @@ }

this.required = true;
this.addValidator(function (value) {
//String trim
if (typeof value === 'string') {
value = value.replace(/(^\s*)|(\s*$)/g, '');
}
//String/Array length > 0
if (value && value.length && value.length > 0) {
return true;
}
return typeof value !== 'undefined' && value !== null && value !== '';
this.addValidator(function (v) {
return typeof v !== 'undefined' && v.length > 0;
}, errorMessage);

@@ -65,0 +54,0 @@ return this;

@@ -22,3 +22,2 @@ 'use strict';

this.name = name;
this.required = false;
this.validators = [];

@@ -30,33 +29,19 @@ }

value: function check(v) {
for (var i = this.validators.length; i > 0; i--) {
var _validators = this.validators[i - 1];
var onValid = _validators.onValid;
var errorMessage = _validators.errorMessage;
for (var i = 0, len = this.validators.length; i < len; i++) {
var _validators$i = this.validators[i];
var vd = _validators$i.vd;
var msg = _validators$i.msg;
if (!this.required && (typeof v === 'undefined' || v.length === 0)) {
return { hasError: false };
if (!vd(v)) {
return { err: true, msg: msg };
}
if (!onValid(v)) {
return { hasError: true, errorMessage: errorMessage };
}
}
return { hasError: false };
return { err: false };
}
}, {
key: 'addValidator',
value: function addValidator(onValid, errorMessage) {
errorMessage = errorMessage || this.validators[0].errorMessage;
this.validators.push({ onValid: onValid, errorMessage: errorMessage });
value: function addValidator(vd, msg) {
msg = msg || this.validators[0].msg;
this.validators.push({ vd: vd, msg: msg });
}
}, {
key: 'isRequired',
value: function isRequired(errorMessage) {
this.required = true;
this.addValidator(function (v) {
return typeof v !== 'undefined' && v.length > 0;
}, errorMessage);
return this;
}
}]);

@@ -78,3 +63,3 @@

function Str() {
var errorMessage = arguments.length <= 0 || arguments[0] === undefined ? 'no error message' : arguments[0];
var msg = arguments.length <= 0 || arguments[0] === undefined ? 'no error message' : arguments[0];

@@ -87,3 +72,3 @@ _classCallCheck(this, Str);

return typeof v === 'string';
}, errorMessage);
}, msg);
return _this;

@@ -94,6 +79,6 @@ }

key: 'isLongerThan',
value: function isLongerThan(n, errorMessage) {
value: function isLongerThan(n, msg) {
_get(Object.getPrototypeOf(Str.prototype), 'addValidator', this).call(this, function (v) {
return v.length > n;
}, errorMessage);
}, msg);
return this;

@@ -103,7 +88,7 @@ }

key: 'containsLetter',
value: function containsLetter(errorMessage) {
value: function containsLetter(msg) {
_get(Object.getPrototypeOf(Str.prototype), 'addValidator', this).call(this, function (v) {
return (/[a-zA-Z]/.test(v)
);
}, errorMessage);
}, msg);
return this;

@@ -113,7 +98,7 @@ }

key: 'containsUppercaseLetter',
value: function containsUppercaseLetter(errorMessage) {
value: function containsUppercaseLetter(msg) {
_get(Object.getPrototypeOf(Str.prototype), 'addValidator', this).call(this, function (v) {
return (/[A-Z]/.test(v)
);
}, errorMessage);
}, msg);
return this;

@@ -123,7 +108,7 @@ }

key: 'containsLowercaseLetter',
value: function containsLowercaseLetter(errorMessage) {
value: function containsLowercaseLetter(msg) {
_get(Object.getPrototypeOf(Str.prototype), 'addValidator', this).call(this, function (v) {
return (/[a-z]/.test(v)
);
}, errorMessage);
}, msg);
return this;

@@ -133,7 +118,7 @@ }

key: 'containsLetterOnly',
value: function containsLetterOnly(errorMessage) {
value: function containsLetterOnly(msg) {
_get(Object.getPrototypeOf(Str.prototype), 'addValidator', this).call(this, function (v) {
return (/^[a-zA-Z]+$/.test(v)
);
}, errorMessage);
}, msg);
return this;

@@ -143,7 +128,7 @@ }

key: 'containsNumber',
value: function containsNumber(errorMessage) {
value: function containsNumber(msg) {
_get(Object.getPrototypeOf(Str.prototype), 'addValidator', this).call(this, function (v) {
return (/[0-9]/.test(v)
);
}, errorMessage);
}, msg);
return this;

@@ -153,15 +138,15 @@ }

key: 'isOneOf',
value: function isOneOf(strArr, errorMessage) {
value: function isOneOf(strArr, msg) {
_get(Object.getPrototypeOf(Str.prototype), 'addValidator', this).call(this, function (v) {
return strArr.includes(v);
}, errorMessage);
}, msg);
return this;
}
}, {
key: 'isEmail',
value: function isEmail(errorMessage) {
var re = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
key: 'isValidEmail',
value: function isValidEmail(msg) {
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
_get(Object.getPrototypeOf(Str.prototype), 'addValidator', this).call(this, function (v) {
return re.test(v);
}, errorMessage);
}, msg);
return this;

@@ -185,3 +170,3 @@ }

function Num() {
var errorMessage = arguments.length <= 0 || arguments[0] === undefined ? 'no error message' : arguments[0];
var msg = arguments.length <= 0 || arguments[0] === undefined ? 'no error message' : arguments[0];

@@ -194,3 +179,3 @@ _classCallCheck(this, Num);

return typeof v === 'number' && !isNaN(v);
}, errorMessage);
}, msg);
return _this2;

@@ -201,6 +186,6 @@ }

key: 'isOneOf',
value: function isOneOf(numLst, errorMessage) {
value: function isOneOf(numLst, msg) {
_get(Object.getPrototypeOf(Num.prototype), 'addValidator', this).call(this, function (v) {
return v in numLst;
}, errorMessage);
}, msg);
return this;

@@ -213,7 +198,7 @@ }

var StringType = exports.StringType = function StringType(errorMessage) {
return new Str(errorMessage);
var StringType = exports.StringType = function StringType(msg) {
return new Str(msg);
};
var NumberType = exports.NumberType = function NumberType(errorMessage) {
return new Num(errorMessage);
var NumberType = exports.NumberType = function NumberType(msg) {
return new Num(msg);
};
{
"name": "rsuite-schema",
"version": "0.0.1-alpha.6",
"version": "0.0.1-alpha.7",
"description": "Schema for data modeling & validation",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc