Skip to content

Commit 9585ad5

Browse files
author
João Faustino
committed
Fix #20 and upgrade dependencies
1 parent 8b466ce commit 9585ad5

File tree

5 files changed

+58
-28
lines changed

5 files changed

+58
-28
lines changed

dist/Validator.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Validator",
3-
"version": "1.0.9",
4-
"description": "A client-side JavaScript validation package, based on Laravel 5.2 validation.",
3+
"version": "1.1.0",
4+
"description": "A JavaScript validation package, based on Laravel validation.",
55
"main": "dist/Validator.js",
66
"scripts": {
77
"test": "nyc --check-coverage --lines 85 mocha --require @babel/register",

src/validator.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,10 @@ class Validator {
666666
getSize(name, value) {
667667
let hasNumeric = this.hasRule(name, this.numericRules);
668668

669+
if (!value) {
670+
return 0;
671+
}
672+
669673
if (hasNumeric && !isNaN(parseFloat(value))) {
670674
return parseFloat(value);
671675
}

test/validator.js

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,30 @@ describe('Validator', () => {
408408
const v = Validator.make({ name: 'Rati' }, {});
409409
expect(v.getSize('name', 'Rati')).to.equal(4);
410410
});
411+
412+
it('should correctly validate min rules on null data fields', () => {
413+
const data = { test: null };
414+
const rules = { test: 'min:1' };
415+
416+
const v = Validator.make(data, rules);
417+
418+
expect(v.fails()).to.be.true;
419+
expect(v.getErrors()).to.deep.equal({
420+
test: ['The test must be at least 1 characters.'],
421+
});
422+
});
423+
424+
it('should correctly validate min and max rules on null data fields', () => {
425+
const data = { test: null };
426+
const rules = { test: 'min:1|max:3' };
427+
428+
const v = Validator.make(data, rules);
429+
430+
expect(v.fails()).to.be.true;
431+
expect(v.getErrors()).to.deep.equal({
432+
test: ['The test must be at least 1 characters.'],
433+
});
434+
});
411435
});
412436

413437
describe('#validateMin()', () => {
@@ -1807,18 +1831,20 @@ describe('Validator', () => {
18071831
});
18081832
});
18091833

1810-
describe('should correctly return a correctly formatted message when a variable name consists of more than two words', () => {
1811-
const data = { threeWordProperty: '' };
1812-
const rules = { threeWordProperty: 'required|min:1' };
1834+
describe('#message', () => {
1835+
it('should correctly return a correctly formatted message when a variable name consists of more than two words', () => {
1836+
const data = { threeWordProperty: '' };
1837+
const rules = { threeWordProperty: 'required|min:1' };
18131838

1814-
const v = Validator.make(data, rules);
1839+
const v = Validator.make(data, rules);
18151840

1816-
expect(v.fails()).to.be.true;
1817-
expect(v.getErrors()).to.deep.equal({
1818-
threeWordProperty: [
1819-
'The three word property field is required.',
1820-
'The three word property must be at least 1 characters.',
1821-
],
1841+
expect(v.fails()).to.be.true;
1842+
expect(v.getErrors()).to.deep.equal({
1843+
threeWordProperty: [
1844+
'The three word property field is required.',
1845+
'The three word property must be at least 1 characters.',
1846+
],
1847+
});
18221848
});
18231849
});
18241850
});

yarn.lock

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -804,9 +804,9 @@
804804
integrity sha512-jnqIUKDUqJbDIUxm0Uj7bnlMnRm1T/eZ9N+AVMqhPgzrba2GhGG5o/jCTwmdPK709nEZsGoMzXEDUjcXHa3W0g==
805805

806806
"@types/node@*":
807-
version "14.0.23"
808-
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.0.23.tgz#676fa0883450ed9da0bb24156213636290892806"
809-
integrity sha512-Z4U8yDAl5TFkmYsZdFPdjeMa57NOvnaf1tljHzhouaPEp7LCj2JKkejpI1ODviIAQuW4CcQmxkQ77rnLsOOoKw==
807+
version "14.0.26"
808+
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.0.26.tgz#22a3b8a46510da8944b67bfc27df02c34a35331c"
809+
integrity sha512-W+fpe5s91FBGE0pEa0lnqGLL4USgpLgs4nokw16SrBBco/gQxuua7KnArSEOd5iaMqbbSHV10vUDkJYJJqpXKA==
810810

811811
"@types/resolve@0.0.8":
812812
version "0.0.8"
@@ -1101,9 +1101,9 @@ camelcase@^5.0.0:
11011101
integrity sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==
11021102

11031103
caniuse-lite@^1.0.30001093:
1104-
version "1.0.30001102"
1105-
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001102.tgz#3275e7a8d09548f955f665e532df88de0b63741a"
1106-
integrity sha512-fOjqRmHjRXv1H1YD6QVLb96iKqnu17TjcLSaX64TwhGYed0P1E1CCWZ9OujbbK4Z/7zax7zAzvQidzdtjx8RcA==
1104+
version "1.0.30001107"
1105+
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001107.tgz#809360df7a5b3458f627aa46b0f6ed6d5239da9a"
1106+
integrity sha512-86rCH+G8onCmdN4VZzJet5uPELII59cUzDphko3thQFgAQG1RNa+sVLDoALIhRYmflo5iSIzWY3vu1XTWtNMQQ==
11071107

11081108
caseless@~0.12.0:
11091109
version "0.12.0"
@@ -1382,9 +1382,9 @@ ecc-jsbn@~0.1.1:
13821382
safer-buffer "^2.1.0"
13831383

13841384
electron-to-chromium@^1.3.488:
1385-
version "1.3.500"
1386-
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.500.tgz#ac082dd2279251b14f1a7f6af6fd16655cf3eb7b"
1387-
integrity sha512-Zz8BZh4Ssb/rZBaicqpi+GOQ0uu3y+24+MxBLCk0UYt8EGoZRP4cYzYHHwXGZfrSbCU4VDjbWN+Tg+TPgOUX6Q==
1385+
version "1.3.509"
1386+
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.509.tgz#830fcb89cd66dc2984d18d794973b99e3f00584c"
1387+
integrity sha512-cN4lkjNRuTG8rtAqTOVgwpecEC2kbKA04PG6YijcKGHK/kD0xLjiqExcAOmLUwtXZRF8cBeam2I0VZcih919Ug==
13881388

13891389
emoji-regex@^7.0.1:
13901390
version "7.0.3"
@@ -2590,9 +2590,9 @@ node-modules-regexp@^1.0.0:
25902590
integrity sha1-jZ2+KJZKSsVxLpExZCEHxx6Q7EA=
25912591

25922592
node-releases@^1.1.58:
2593-
version "1.1.59"
2594-
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-1.1.59.tgz#4d648330641cec704bff10f8e4fe28e453ab8e8e"
2595-
integrity sha512-H3JrdUczbdiwxN5FuJPyCHnGHIFqQ0wWxo+9j1kAXAzqNMAHlo+4I/sYYxpyK0irQ73HgdiyzD32oqQDcU2Osw==
2593+
version "1.1.60"
2594+
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-1.1.60.tgz#6948bdfce8286f0b5d0e5a88e8384e954dfe7084"
2595+
integrity sha512-gsO4vjEdQaTusZAEebUWp2a5d7dF5DYoIpDG7WySnk7BuZDW+GPpHXoXXuYawRBr/9t5q54tirPz79kFIWg4dA==
25962596

25972597
normalize-package-data@^2.3.2:
25982598
version "2.5.0"
@@ -2970,9 +2970,9 @@ regenerate@^1.4.0:
29702970
integrity sha512-j2+C8+NtXQgEKWk49MMP5P/u2GhnahTtVkRIHr5R5lVRlbKvmQ+oS+A5aLKWp2ma5VkT8sh6v+v4hbH0YHR66A==
29712971

29722972
regenerator-runtime@^0.13.4:
2973-
version "0.13.5"
2974-
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.5.tgz#d878a1d094b4306d10b9096484b33ebd55e26697"
2975-
integrity sha512-ZS5w8CpKFinUzOwW3c83oPeVXoNsrLsaCoLtJvAClH135j/R77RuymhiSErhm2lKcwSCIpmvIWSbDkIfAqKQlA==
2973+
version "0.13.7"
2974+
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.7.tgz#cac2dacc8a1ea675feaabaeb8ae833898ae46f55"
2975+
integrity sha512-a54FxoJDIr27pgf7IgeQGxmqUNYrcV338lf/6gH456HZ/PhX+5BcwHXG9ajESmwe6WRO0tAzRUrRmNONWgkrew==
29762976

29772977
regenerator-transform@^0.14.2:
29782978
version "0.14.5"

0 commit comments

Comments
 (0)