cleaner-node
Advanced tools
Comparing version 0.2.2 to 0.2.3
{ | ||
"name": "cleaner-node", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "Helpful utilities and scripts to make Node projects more legible and easier for the next developer to take over.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
const moment = require('moment'); | ||
const { padLeft } = require('strings'); | ||
const isValid = value => { | ||
return (typeof value !== 'undefined' && value instanceof Date); | ||
} | ||
const ifValid = (value, defaultValue) => { | ||
return isValid(value) ? value : defaultValue; | ||
} | ||
const parse = value => { | ||
@@ -43,6 +51,24 @@ const date = moment(value); | ||
const toBlockDate = (value, includeMilliseconds = true) => { | ||
const date = ifValid(value, (new Date())); | ||
const result = [ | ||
String(date.getFullYear()), | ||
padLeft(date.getMonth() + 1), | ||
padLeft(date.getDate()), | ||
padLeft(date.getHours()), | ||
padLeft(date.getMinutes()), | ||
padLeft(date.getSeconds()), | ||
'.', | ||
padLeft(date.getMilliseconds(), 3) | ||
].join(''); | ||
return includeMilliseconds ? result : result.split('.')[0]; | ||
} | ||
module.exports = { | ||
isValid, | ||
ifValid, | ||
parse, | ||
add, | ||
subtract, | ||
toBlockDate, | ||
toUnixDateStamp, | ||
@@ -49,0 +75,0 @@ toUnix: toUnixDateStamp, |
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
45300
1129