Skip to content

Commit

Permalink
Fix #30 and upgrade dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
João Faustino committed Sep 16, 2020
1 parent 3d45e0c commit 4a717f4
Show file tree
Hide file tree
Showing 6 changed files with 7,222 additions and 40 deletions.
2 changes: 1 addition & 1 deletion dist/Validator.js

Large diffs are not rendered by default.

6,540 changes: 6,540 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

24 changes: 13 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "Validator",
"version": "1.1.1",
"version": "1.1.2",
"description": "A JavaScript validation package, based on Laravel validation.",
"main": "dist/Validator.js",
"scripts": {
"test": "nyc --check-coverage --lines 85 mocha --require @babel/register",
"coverage": "npm test && nyc report --reporter=text-lcov | coveralls",
"coverage": "npm run test && nyc report --reporter=text-lcov | coveralls",
"test:watch": "nodemon --exec npm run test",
"prebuild": "rimraf dist",
"build": "rollup -c",
"watch": "rollup -c -w",
Expand All @@ -30,19 +31,20 @@
"license": "MIT",
"homepage": "https://github.com/jfstn/Validator#readme",
"devDependencies": {
"@babel/core": "^7.3.4",
"@babel/preset-env": "^7.3.4",
"@babel/register": "^7.0.0",
"@babel/core": "^7.11.6",
"@babel/preset-env": "^7.11.5",
"@babel/register": "^7.11.5",
"chai": "^4.2.0",
"coveralls": "^3.0.3",
"mocha": "^6.0.2",
"nyc": "^13.3.0",
"rimraf": "^2.6.3",
"rollup": "^1.6.0",
"coveralls": "^3.1.0",
"mocha": "^8.1.3",
"nodemon": "^2.0.4",
"nyc": "^15.1.0",
"rimraf": "^3.0.2",
"rollup": "^2.27.0",
"rollup-plugin-babel": "^4.3.2",
"rollup-plugin-commonjs": "^9.2.1",
"rollup-plugin-node-resolve": "^4.0.1",
"rollup-plugin-uglify": "^6.0.2",
"rollup-plugin-uglify": "^6.0.4",
"rollup-watch": "^4.3.1"
}
}
14 changes: 0 additions & 14 deletions src/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class Validator {
rules: self.parseItemRules(rules[key]),
});
}

return arr;
}

Expand All @@ -94,16 +93,7 @@ class Validator {
itemRules = itemRules.split('|');
}

if (!Array.isArray(itemRules)) {
console.error('Unsupported type for item rule', itemRules);
}

itemRules.forEach(function (ruleAndArgs) {
if (typeof ruleAndArgs === 'function') {
self.extend('batata', ruleAndArgs, 'will this work?');
return;
}

if (ruleAndArgs.trim()) {
let args = ruleAndArgs.split(':');
rules.push({
Expand Down Expand Up @@ -783,7 +773,6 @@ class Validator {
: params[0];

if (!this.validateDate(name, date)) {
console.error(params[0] + ' does not appear to be a date.');
return false;
}

Expand All @@ -806,7 +795,6 @@ class Validator {
: params[0];

if (!this.validateDate(name, date)) {
console.error(params[0] + ' does not appear to be a date.');
return false;
}

Expand All @@ -829,7 +817,6 @@ class Validator {
: params[0];

if (!this.validateDate(name, date)) {
console.error(params[0] + ' does not appear to be a date.');
return false;
}

Expand All @@ -852,7 +839,6 @@ class Validator {
: params[0];

if (!this.validateDate(name, date)) {
console.error(params[0] + ' does not appear to be a date.');
return false;
}

Expand Down
37 changes: 32 additions & 5 deletions test/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,33 @@ describe('Validator', () => {
{ name: 'NotIn', params: ['admin', 'exec'] },
]);
});

//it('should not validate deep objects', () => {
// const data = {
// name: 'John Doe',
// test: {
// birthday: '20000000000000',
// },
// company: 'Example Co.',
// };

// const rules = {
// name: 'required',
// test: {
// birthday: 'required',
// },
// company: ['required', 'string'],
// };

// const v = Validator.make(data, rules);

// if (v.fails()) {
// const errors = v.getErrors();
// console.log(errors);
// } else {
// console.log('good!');
// }
// });
});

describe('#parseRules()', () => {
Expand Down Expand Up @@ -1749,7 +1776,7 @@ describe('Validator', () => {
{ color: '1', bar: '' },
{ bar: 'required_if:color,1' }
);
v.addCustomValues({ color: { '1': 'Red' } });
v.addCustomValues({ color: { 1: 'Red' } });
expect(v.passes()).to.be.false;
expect(v.getErrors()).to.deep.equal({
bar: ['The bar field is required when color is Red.'],
Expand All @@ -1763,8 +1790,8 @@ describe('Validator', () => {
);
v.addCustomValues({
type: {
'5': 'Short',
'300': 'Long',
5: 'Short',
300: 'Long',
},
});
expect(v.passes()).to.be.false;
Expand All @@ -1780,8 +1807,8 @@ describe('Validator', () => {
);
v.setValueNames({
type: {
'5': 'Short',
'300': 'Long',
5: 'Short',
300: 'Long',
},
});
expect(v.passes()).to.be.false;
Expand Down
Loading

0 comments on commit 4a717f4

Please sign in to comment.