diff --git a/lib/psSupported.js b/lib/psSupported.js index 8c04144..e06ae12 100644 --- a/lib/psSupported.js +++ b/lib/psSupported.js @@ -1,3 +1,9 @@ var semver = require('semver'); +/** + * Checks if the current Node.js version is supported by this library. + * + * @returns {boolean} + */ + module.exports = semver.satisfies(process.version, '^6.12.0 || >=8.0.0'); diff --git a/lib/timespan.js b/lib/timespan.js index e509869..ffb5af5 100644 --- a/lib/timespan.js +++ b/lib/timespan.js @@ -1,18 +1,32 @@ var ms = require('ms'); +/** + * + * - Returns the timespan of *time* from *iat* + * - if *iat* is undefined it return the timespan of time from current time + * - if params are invalid, it returns undefined + * + * @param {string|number} time -> 1m,1h... + * @param {number} iat -> in ms + * @returns {number} in s + * + */ module.exports = function (time, iat) { - var timestamp = iat || Math.floor(Date.now() / 1000); + + if (typeof iat != 'number') + return + + var timestamp = iat || Math.floor(Date.now() / 1000) if (typeof time === 'string') { - var milliseconds = ms(time); - if (typeof milliseconds === 'undefined') { - return; - } - return Math.floor(timestamp + milliseconds / 1000); + var milliseconds = ms(time) + if (typeof milliseconds === 'undefined') + return + return Math.floor(timestamp + milliseconds / 1000) } else if (typeof time === 'number') { - return timestamp + time; + return timestamp + time } else { - return; + return } }; \ No newline at end of file