Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: error message on max and min #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jasine wants to merge 2 commits into node-modules:master
base: master
Choose a base branch
Loading
from jasine:master
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions index.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,11 @@ function checkInt(rule, value) {
}

if (rule.hasOwnProperty('max') && value > rule.max) {
return this.t('should smaller than %s', rule.max);
return this.t('should not bigger than %s', rule.max);
}

if (rule.hasOwnProperty('min') && value < rule.min) {
return this.t('should bigger than %s', rule.min);
return this.t('should not smaller than %s', rule.min);
}
}

Expand All @@ -342,10 +342,10 @@ function checkNumber(rule, value) {
return this.t('should be a number');
}
if (rule.hasOwnProperty('max') && value > rule.max) {
return this.t('should smaller than %s', rule.max);
return this.t('should not bigger than %s', rule.max);
}
if (rule.hasOwnProperty('min') && value < rule.min) {
return this.t('should bigger than %s', rule.min);
return this.t('should not smaller than %s', rule.min);
}
}

Expand Down Expand Up @@ -385,10 +385,10 @@ function checkString(rule, value) {
}

if (rule.hasOwnProperty('max') && value.length > rule.max) {
return this.t('length should smaller than %s', rule.max);
return this.t('length should not bigger than %s', rule.max);
}
if (rule.hasOwnProperty('min') && value.length < rule.min) {
return this.t('length should bigger than %s', rule.min);
return this.t('length should not smaller than %s', rule.min);
}

if (rule.format && !rule.format.test(value)) {
Expand Down Expand Up @@ -582,10 +582,10 @@ function checkArray(rule, value) {
}

if (rule.hasOwnProperty('max') && value.length > rule.max) {
return this.t('length should smaller than %s', rule.max);
return this.t('length should not bigger than %s', rule.max);
}
if (rule.hasOwnProperty('min') && value.length < rule.min) {
return this.t('length should bigger than %s', rule.min);
return this.t('length should not smaller than %s', rule.min);
}

if (!rule.itemType) {
Expand Down
22 changes: 11 additions & 11 deletions test/index.test.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ describe('parameter', () => {
it('should check max error', () => {
var value = { int: 101 };
var rule = { int: {type: 'int', max: 100, min: 1 }};
parameter.validate(rule, value)[0].message.should.equal('should smaller than 100');
parameter.validate(rule, value)[0].message.should.equal('should not bigger than 100');
});

it('should check min error', () => {
var value = { int: -1 };
var rule = { int: {type: 'int', max: 100, min: 0 }};
parameter.validate(rule, value)[0].message.should.equal('should bigger than 0');
parameter.validate(rule, value)[0].message.should.equal('should not smaller than 0');
});
});

Expand All @@ -149,13 +149,13 @@ describe('parameter', () => {
it('should check max error', () => {
var value = { number: 101 };
var rule = { number: {type: 'number', max: 100, min: 1 }};
parameter.validate(rule, value)[0].message.should.equal('should smaller than 100');
parameter.validate(rule, value)[0].message.should.equal('should not bigger than 100');
});

it('should check min error', () => {
var value = { number: -1 };
var rule = { number: {type: 'number', max: 100, min: 0 }};
parameter.validate(rule, value)[0].message.should.equal('should bigger than 0');
parameter.validate(rule, value)[0].message.should.equal('should not smaller than 0');
});
});

Expand Down Expand Up @@ -184,13 +184,13 @@ describe('parameter', () => {
it('should check max error', () => {
var value = { string: 'hello' };
var rule = { string: {type: 'string', max: 4, min: 1 }};
parameter.validate(rule, value)[0].message.should.equal('length should smaller than 4');
parameter.validate(rule, value)[0].message.should.equal('length should not bigger than 4');
});

it('should check min error', () => {
var value = { string: 'hello' };
var rule = { string: {type: 'string', max: 100, min: 10 }};
parameter.validate(rule, value)[0].message.should.equal('length should bigger than 10');
parameter.validate(rule, value)[0].message.should.equal('length should not smaller than 10');
});

it('should check format error', () => {
Expand Down Expand Up @@ -432,7 +432,7 @@ describe('parameter', () => {
{
code: 'invalid',
field: 'password',
message: 'length should bigger than 6'
message: 'length should not smaller than 6'
}
]);

Expand All @@ -449,7 +449,7 @@ describe('parameter', () => {
{
code: 'invalid',
field: 'password',
message: 'length should bigger than 4'
message: 'length should not smaller than 4'
}
]);
});
Expand Down Expand Up @@ -622,13 +622,13 @@ describe('parameter', () => {
it('should check max error', () => {
var value = {array: [0, 1, 2, 3, 4]};
var rule = {array: {type: 'array', itemType: 'int', max: 4, min: 1}};
parameter.validate(rule, value)[0].message.should.equal('length should smaller than 4');
parameter.validate(rule, value)[0].message.should.equal('length should not bigger than 4');
});

it('should check min error', () => {
var value = {array: [0, 1, 2, 3, 4]};
var rule = {array: {type: 'array', itemType: 'int', max: 100, min: 10}};
parameter.validate(rule, value)[0].message.should.equal('length should bigger than 10');
parameter.validate(rule, value)[0].message.should.equal('length should not smaller than 10');
});

it('should check itemType=object error', () => {
Expand Down Expand Up @@ -1115,4 +1115,4 @@ describe('validate with options.convert', function() {
});
});
});
});
});

AltStyle によって変換されたページ (->オリジナル) /