Skip to content

Commit

Permalink
Merge pull request #51 from hckrnews/feature/add-url-validation
Browse files Browse the repository at this point in the history
Add url and date validation
  • Loading branch information
w3nl authored Nov 24, 2020
2 parents c6c656e + 574bb19 commit bca39cd
Show file tree
Hide file tree
Showing 8 changed files with 11,509 additions and 1,570 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:

strategy:
matrix:
node-version: [10.x, 12.x, 14.x, 15.x]
node-version: [10.x, 12.x, 14.x]

steps:
- uses: actions/checkout@v1
Expand Down
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ node_js:
- "10"
- "12"
- "14"
- "15"
before_script:
- npm run lint
- npm run cpd
Expand Down
13,055 changes: 11,491 additions & 1,564 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hckrnews/validator",
"version": "2.1.3",
"version": "2.1.4",
"description": "Object validator",
"main": "src/validator.js",
"files": [
Expand Down Expand Up @@ -28,7 +28,7 @@
"devDependencies": {
"@babel/core": "^7.12.3",
"@babel/preset-env": "^7.12.1",
"@hckrnews/eslint-config": "^0.2.0",
"@hckrnews/eslint-config": "^1.0.1",
"babel-eslint": "^10.1.0",
"babel-jest": "^25.5.1",
"codecov": "^3.8.1",
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/company.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default {
name: 'string',
'?website': 'string',
'?website': 'url',
};
1 change: 1 addition & 0 deletions src/schemas/person.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import companySchema from './company';
export default {
name: String,
age: Number,
birthDay: Date,
siblings: Array,
'?metaData': Object,
active: Boolean,
Expand Down
2 changes: 2 additions & 0 deletions src/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const types = {
object: Object,
number: Number,
boolean: Boolean,
url: URL,
date: Date,
};

/**
Expand Down
12 changes: 11 additions & 1 deletion tests/unit/validator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const testCases = [
input: {
name: 'James',
age: 25,
birthDay: new Date('1982-12-24'),
siblings: ['Johnnathan'],
metaData: {},
active: true,
Expand All @@ -73,7 +74,9 @@ const testCases = [
city: 'City',
country: 'Somewehere',
},
companies: [{ name: 'Example', website: 'https://hckr.news' }],
companies: [
{ name: 'Example', website: new URL('https://hckr.news') },
],
},
schema: personSchema,
expectedValue: true,
Expand All @@ -84,6 +87,7 @@ const testCases = [
input: {
name: 'James',
age: 25,
birthDay: new Date('1982-12-24'),
siblings: ['Johnnathan'],
active: true,
address: {
Expand All @@ -104,6 +108,7 @@ const testCases = [
input: {
name: 'James',
age: 25,
birthDay: new Date('1982-12-24'),
active: true,
},
schema: personSchema,
Expand All @@ -122,6 +127,7 @@ const testCases = [
expectedErrors: [
['name', String],
['age', Number],
['birthDay', Date],
['siblings', Array],
['?metaData', Object],
['active', Boolean],
Expand Down Expand Up @@ -150,6 +156,7 @@ const testCaseArrays = [
{
name: 'James',
age: 25,
birthDay: new Date('1982-12-24'),
siblings: ['Johnnathan'],
active: true,
address: {
Expand All @@ -171,6 +178,7 @@ const testCaseArrays = [
{
name: 'James',
age: 25,
birthDay: new Date('1982-12-24'),
active: true,
},
],
Expand All @@ -183,6 +191,7 @@ const testCaseArrays = [
{
name: 'James',
age: 25,
birthDay: new Date('1982-12-24'),
siblings: ['Johnnathan'],
active: true,
address: {
Expand All @@ -208,6 +217,7 @@ const testCaseArrays = [
input: {
name: 'James',
age: 25,
birthDay: new Date('1982-12-24'),
siblings: ['Johnnathan'],
active: true,
address: {
Expand Down

0 comments on commit bca39cd

Please sign in to comment.