Skip to content
This repository has been archived by the owner on Dec 12, 2020. It is now read-only.

Commit

Permalink
Merge b3d1ff2 into 3604a88
Browse files Browse the repository at this point in the history
  • Loading branch information
ktutnik committed Jun 21, 2020
2 parents 3604a88 + b3d1ff2 commit 5ca36af
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 22 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
],
"scripts": {
"test": "jest",
"prepublish": "tsc -p tsconfig.build.json",
"compile": "tsc -p tsconfig.build.json",
"gen": "ts-node src/generator.ts",
"clean": "rm -rf src/*.js && rm -rf test/*.js && rm -rf lib",
"benchmark": "ts-node benchmark/index.ts"
Expand All @@ -19,7 +19,7 @@
"license": "MIT",
"dependencies": {
"@types/validator": "^13.0.0",
"tinspector": "^3.1.0",
"tinspector": "3.2.2",
"tslib": "^2.0.0",
"validator": "^13.0.0"
},
Expand Down
39 changes: 29 additions & 10 deletions script/date-snapshot-serializer.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
/**
* This module will serialize function as [typeof: <Function Name>] instead of [Function]
*/

function extractValues(date) {
return {
year: date.getFullYear(),
month: date.getMonth(),
date: date.getDate()
}
}

function isToday(date) {
var today = extractValues(new Date());
var value = extractValues(date);

if (
today.year !== value.year ||
today.month !== value.month ||
today.date !== value.date
) {
return false;
}

return true;
}

module.exports = {
test(val) {
return val instanceof Date;
return val && typeof val === 'object' && 'getFullYear' in val
},
print(d) {
return [
d.getFullYear(),
('0' + (d.getMonth() + 1)).slice(-2),
('0' + d.getDate()).slice(-2)
].join('-');
print(val) {
if(isToday(val)) return "DATE NOW"
var d = extractValues(val);
return [d.year, d.month, d.date].join('-');
},
}
20 changes: 10 additions & 10 deletions test/__snapshots__/validation.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Object {
"value": Array [
undefined,
AnimalClass {
"birthday": 2018-02-02,
"birthday": 2018-1-2,
"deceased": true,
"id": "",
"name": "Mimi",
Expand All @@ -47,7 +47,7 @@ Object {
"value": Array [
undefined,
AnimalClass {
"birthday": 2018-02-02,
"birthday": 2018-1-2,
"deceased": true,
"name": "Mimi",
},
Expand All @@ -68,7 +68,7 @@ Object {
"value": Array [
undefined,
AnimalClass {
"birthday": 2018-02-02,
"birthday": 2018-1-2,
"deceased": true,
"name": "Mimi",
},
Expand Down Expand Up @@ -336,7 +336,7 @@ exports[`Required Validator and Partial Nested Object Validator Should valid if
Object {
"issues": undefined,
"value": AnimalClass {
"birthday": 2018-02-02,
"birthday": 2018-1-2,
"deceased": true,
"id": 123,
"name": "Mimi",
Expand Down Expand Up @@ -370,7 +370,7 @@ Object {
},
],
"value": AnimalClass {
"birthday": 2018-02-02,
"birthday": 2018-1-2,
"deceased": true,
"id": 123,
"name": "Mimi",
Expand All @@ -393,7 +393,7 @@ Object {
},
],
"value": AnimalClass {
"birthday": 2018-02-02,
"birthday": 2018-1-2,
"deceased": true,
"id": 123,
"name": "Mimi",
Expand All @@ -415,7 +415,7 @@ Object {
},
],
"value": AnimalClass {
"birthday": 2018-02-02,
"birthday": 2018-1-2,
"deceased": true,
"id": 123,
"name": "Mimi",
Expand Down Expand Up @@ -455,7 +455,7 @@ Object {
},
],
"value": AnimalClass {
"birthday": 2018-02-02,
"birthday": 2018-1-2,
"deceased": true,
"id": "",
"name": "",
Expand All @@ -474,7 +474,7 @@ Object {
},
],
"value": AnimalClass {
"birthday": 2018-02-02,
"birthday": 2018-1-2,
"deceased": true,
"name": "Mimi",
},
Expand All @@ -492,7 +492,7 @@ Object {
},
],
"value": AnimalClass {
"birthday": 2018-02-02,
"birthday": 2018-1-2,
"deceased": true,
"name": "Mimi",
},
Expand Down

0 comments on commit 5ca36af

Please sign in to comment.