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.2 to 0.0.3

.vscode/settings.json

23

lib/NumberType.js

@@ -21,2 +21,6 @@ 'use strict';

function _f(value) {
return +value;
}
var NumberType = function (_Type) {

@@ -26,3 +30,3 @@ _inherits(NumberType, _Type);

NumberType.from = function from(n) {
return +n;
return n;
};

@@ -38,3 +42,3 @@

_Type.prototype.addValidator.call(_this, function (value) {
return (/^[0-9]+.?[0-9]*$/.test(value)
return (/^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test(value)
);

@@ -45,2 +49,9 @@ }, errorMessage);

NumberType.prototype.isInteger = function isInteger() {
_Type.prototype.addValidator.call(this, function (value) {
return (/^-?\d+$/.test(value)
);
}, errorMessage);
};
NumberType.prototype.pattern = function pattern(regexp, errorMessage) {

@@ -55,3 +66,3 @@ _Type.prototype.addValidator.call(this, function (value) {

_Type.prototype.addValidator.call(this, function (value) {
return value in numLst;
return _f(value) in numLst;
}, errorMessage);

@@ -63,3 +74,3 @@ return this;

_Type.prototype.addValidator.call(this, function (value) {
return value >= min && value <= max;
return _f(value) >= min && _f(value) <= max;
}, errorMessage);

@@ -71,3 +82,3 @@ return this;

_Type.prototype.addValidator.call(this, function (value) {
return value >= _min;
return _f(value) >= _min;
}, errorMessage);

@@ -79,3 +90,3 @@ return this;

_Type.prototype.addValidator.call(this, function (value) {
return value <= _max;
return _f(value) <= _max;
}, errorMessage);

@@ -82,0 +93,0 @@ return this;

{
"name": "rsuite-schema",
"version": "0.0.2",
"version": "0.0.3",
"description": "Schema for data modeling & validation",
"main": "lib/index.js",
"scripts": {
"compile": "./node_modules/.bin/babel -d lib/ src/",
"prepublish": "npm run compile",
"test": "npm run compile && mocha"
"build": "./node_modules/.bin/babel -d lib/ src/",
"prepublish": "npm run build",
"test": "npm run build && mocha",
"tdd": "mocha"
},

@@ -11,0 +12,0 @@ "repository": {

var should = require('chai').should();
var schema = require('../lib');
var schemaBuilder = schema.SchemaBuilder;
var Schema = schema.Schema;
var stringType = schema.StringType;
var numberType = schema.NumberType;
describe('#SchemaBuilder', () => {
describe('#Schema', () => {
it('save Schema as proporty', () => {
let schemaData = { data: stringType() };
let schema = schemaBuilder(schemaData);
let schema = new Schema(schemaData);
schema.schema.should.equal(schemaData);
});
it('get field value type of given field name', () => {
let schemaData = { data: numberType() };
let schema = schemaBuilder(schemaData);
let schema = new Schema(schemaData);
schema.getFieldType('data').should.equal(schemaData.data);

@@ -22,6 +23,19 @@ });

let schemaData = { data: numberType() };
let schema = schemaBuilder(schemaData);
let checkResult = schema.checkForField('data', 233);
checkResult.should.have.property('err').be.a('boolean');
let schema = new Schema(schemaData);
let checkResult = schema.checkForField('data', "2.22");
checkResult.should.have.property('hasError').be.a('boolean');
});
it('should valid NumberType ', () => {
let schemaData = { data: numberType() };
let schema = new Schema(schemaData);
schema.checkForField('data', "2.22").hasError.should.equal(false);
schema.checkForField('data', 2.22).hasError.should.equal(false);
schema.checkForField('data', -222).hasError.should.equal(false);
});
});
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