xpress-mongo
Advanced tools
Comparing version 0.0.39 to 0.0.40
@@ -11,3 +11,13 @@ "use strict"; | ||
const isArray = (v) => Array.isArray(v); | ||
const isDate = (v) => v instanceof Date; | ||
const isDate = (v) => { | ||
if (v instanceof Date) { | ||
return true; | ||
} | ||
else if (typeof v === "string") { | ||
return !isNaN(new Date(v).getTime()); | ||
} | ||
else { | ||
return false; | ||
} | ||
}; | ||
const isNumber = (v) => !isBoolean(v) && !isNaN(v); | ||
@@ -85,2 +95,10 @@ const is = { | ||
.validator(isDate) | ||
.cast((value) => { | ||
if (value instanceof Date) { | ||
return value; | ||
} | ||
else { | ||
return new Date(value); | ||
} | ||
}) | ||
.validatorError((key) => `(${key}) is not a Date`); | ||
@@ -87,0 +105,0 @@ }, |
{ | ||
"name": "xpress-mongo", | ||
"version": "0.0.39", | ||
"version": "0.0.40", | ||
"description": "Light Weight ODM for mongoDb", | ||
@@ -11,3 +11,3 @@ "main": "js/index.js", | ||
"scripts": { | ||
"test": "node tests/test.js" | ||
"test": "nodemon tests/test.js" | ||
}, | ||
@@ -14,0 +14,0 @@ "repository": { |
@@ -11,3 +11,11 @@ import XMongoDataType = require("./XMongoDataType"); | ||
const isArray = (v: any) => Array.isArray(v); | ||
const isDate = (v: any) => v instanceof Date; | ||
const isDate = (v: any) => { | ||
if (v instanceof Date) { | ||
return true | ||
} else if (typeof v === "string") { | ||
return !isNaN(new Date(v).getTime()) | ||
} else { | ||
return false | ||
} | ||
}; | ||
const isNumber = (v: any) => !isBoolean(v) && !isNaN(v); | ||
@@ -49,3 +57,2 @@ | ||
.validatorError((key) => `(${key}) is not a Mongodb-ObjectID`); | ||
}, | ||
@@ -107,2 +114,9 @@ | ||
.validator(isDate) | ||
.cast((value) => { | ||
if (value instanceof Date) { | ||
return value | ||
} else { | ||
return new Date(value) | ||
} | ||
}) | ||
.validatorError((key) => `(${key}) is not a Date`); | ||
@@ -109,0 +123,0 @@ }, |
@@ -1,2 +0,2 @@ | ||
const {Client} = require('../index'); | ||
const {Client} = require('../'); | ||
@@ -3,0 +3,0 @@ const db = "mongodb://127.0.0.1:27017"; |
@@ -1,2 +0,2 @@ | ||
const {is, ModelDataType} = require('../index'); | ||
const {is, ModelDataType} = require('../'); | ||
const Database = global['Database']; | ||
@@ -39,3 +39,3 @@ | ||
]), | ||
created_at: is.Date().required() | ||
updated_at: is.Date().required() | ||
}; | ||
@@ -42,0 +42,0 @@ |
@@ -12,15 +12,14 @@ const connection = require('./connection'); | ||
*/ | ||
const guest = new Users().set({ | ||
type: 'guest', | ||
first_name: 'Hello', | ||
last_name: 'World', | ||
guestId: Users.id('5e5acba088ebeef8a715ca43'), | ||
updated_at: 'Fri, 03 Apr 2020 00:00:00 GMT' | ||
}); | ||
// console.log(guest.data); | ||
console.log(guest.validate()); | ||
const guest = new Users().set({ | ||
type: 'guest', | ||
first_name: 'Hello', | ||
last_name: 'World', | ||
guestId: Users.id('5e5acba088ebeef8a715ca43') | ||
}); | ||
// console.log(guest.data); | ||
console.log(guest.validate()); | ||
/** | ||
@@ -27,0 +26,0 @@ * End Async Space |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
137371
3780