typed-duration
Advanced tools
Comparing version 1.0.13 to 2.0.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Duration = void 0; | ||
const lib_1 = require("./lib"); | ||
@@ -4,0 +5,0 @@ exports.Duration = { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.daysFrom = exports.hoursFrom = exports.minutesFrom = exports.secondsFrom = exports.millisecondsFrom = exports.numberFrom = exports.daysOf = exports.hoursOf = exports.minutesOf = exports.millisecondsOf = exports.secondsOf = exports.valueOf = exports.valueFrom = exports.isTypedDuration = void 0; | ||
/** | ||
@@ -8,8 +9,10 @@ * Returns true if the argument is a typed duration object. | ||
*/ | ||
exports.isTypedDuration = (maybeTypedDuration) => typeof maybeTypedDuration === "object" && | ||
const isTypedDuration = (maybeTypedDuration) => typeof maybeTypedDuration === "object" && | ||
(maybeTypedDuration === null || maybeTypedDuration === void 0 ? void 0 : maybeTypedDuration.valueType) === "TYPED_DURATION"; | ||
exports.isTypedDuration = isTypedDuration; | ||
/** | ||
* Return the unwrapped number from any typed duration, regardless of its type | ||
*/ | ||
exports.valueFrom = (time) => exports.isTypedDuration(time) ? time.value : time; | ||
const valueFrom = (time) => (0, exports.isTypedDuration)(time) ? time.value : time; | ||
exports.valueFrom = valueFrom; | ||
/** | ||
@@ -19,9 +22,10 @@ * | ||
*/ | ||
exports.valueOf = (time, defaultUnit = "") => `${exports.valueFrom(time)}${exports.isTypedDuration(time) ? time.unit : defaultUnit}`; | ||
const isSeconds = (maybeSeconds) => exports.isTypedDuration(maybeSeconds) && maybeSeconds.type === "SECONDS"; | ||
const isMilliseconds = (maybeMilliseconds) => exports.isTypedDuration(maybeMilliseconds) && | ||
const valueOf = (time, defaultUnit = "") => `${(0, exports.valueFrom)(time)}${(0, exports.isTypedDuration)(time) ? time.unit : defaultUnit}`; | ||
exports.valueOf = valueOf; | ||
const isSeconds = (maybeSeconds) => (0, exports.isTypedDuration)(maybeSeconds) && maybeSeconds.type === "SECONDS"; | ||
const isMilliseconds = (maybeMilliseconds) => (0, exports.isTypedDuration)(maybeMilliseconds) && | ||
maybeMilliseconds.type === "MILLISECONDS"; | ||
const isMinutes = (maybeMinutes) => exports.isTypedDuration(maybeMinutes) && maybeMinutes.type === "MINUTES"; | ||
const isHours = (maybeHours) => exports.isTypedDuration(maybeHours) && maybeHours.type === "HOURS"; | ||
const isDays = (maybeDays) => exports.isTypedDuration(maybeDays) && maybeDays.type === "DAYS"; | ||
const isMinutes = (maybeMinutes) => (0, exports.isTypedDuration)(maybeMinutes) && maybeMinutes.type === "MINUTES"; | ||
const isHours = (maybeHours) => (0, exports.isTypedDuration)(maybeHours) && maybeHours.type === "HOURS"; | ||
const isDays = (maybeDays) => (0, exports.isTypedDuration)(maybeDays) && maybeDays.type === "DAYS"; | ||
const isNumber = (maybeNumber) => typeof maybeNumber === "number"; | ||
@@ -138,27 +142,33 @@ const newSeconds = (time) => ({ | ||
exports.daysOf = daysOf; | ||
exports.numberFrom = (time) => exports.isTypedDuration(time) ? time.value : time; | ||
exports.millisecondsFrom = (time) => isNumber(time) | ||
const numberFrom = (time) => (0, exports.isTypedDuration)(time) ? time.value : time; | ||
exports.numberFrom = numberFrom; | ||
const millisecondsFrom = (time) => isNumber(time) | ||
? time | ||
: isMilliseconds(time) | ||
? exports.numberFrom(time) | ||
: exports.millisecondsFrom(millisecondsOf(time)); | ||
exports.secondsFrom = (time) => isNumber(time) | ||
? (0, exports.numberFrom)(time) | ||
: (0, exports.millisecondsFrom)(millisecondsOf(time)); | ||
exports.millisecondsFrom = millisecondsFrom; | ||
const secondsFrom = (time) => isNumber(time) | ||
? time | ||
: isSeconds(time) | ||
? exports.numberFrom(time) | ||
: exports.secondsFrom(secondsOf(time)); | ||
exports.minutesFrom = (time) => isNumber(time) | ||
? (0, exports.numberFrom)(time) | ||
: (0, exports.secondsFrom)(secondsOf(time)); | ||
exports.secondsFrom = secondsFrom; | ||
const minutesFrom = (time) => isNumber(time) | ||
? time | ||
: isMinutes(time) | ||
? exports.numberFrom(time) | ||
: exports.minutesFrom(minutesOf(time)); | ||
exports.hoursFrom = (time) => isNumber(time) | ||
? (0, exports.numberFrom)(time) | ||
: (0, exports.minutesFrom)(minutesOf(time)); | ||
exports.minutesFrom = minutesFrom; | ||
const hoursFrom = (time) => isNumber(time) | ||
? time | ||
: isHours(time) | ||
? exports.numberFrom(time) | ||
: exports.hoursFrom(hoursOf(time)); | ||
exports.daysFrom = (time) => isNumber(time) | ||
? (0, exports.numberFrom)(time) | ||
: (0, exports.hoursFrom)(hoursOf(time)); | ||
exports.hoursFrom = hoursFrom; | ||
const daysFrom = (time) => isNumber(time) | ||
? time | ||
: isDays(time) | ||
? exports.numberFrom(time) | ||
: exports.daysFrom(daysOf(time)); | ||
? (0, exports.numberFrom)(time) | ||
: (0, exports.daysFrom)(daysOf(time)); | ||
exports.daysFrom = daysFrom; |
{ | ||
"name": "typed-duration", | ||
"version": "1.0.13", | ||
"version": "2.0.0", | ||
"description": "Zero-dependency typed duration library for JavaScript", | ||
@@ -15,12 +15,12 @@ "main": "dist/index.js", | ||
], | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"typescript": "^3.8.3", | ||
"@types/jest": "^25.1.4", | ||
"jest": "^25.1.0", | ||
"ts-jest": "^25.2.1" | ||
"@types/jest": "^29.5.8", | ||
"jest": "^29.7.0", | ||
"ts-jest": "^29.1.1", | ||
"typescript": "4.4" | ||
}, | ||
"scripts": { | ||
"test": "jest", | ||
"prepublishOnly": "jest && tsc" | ||
"prepublishOnly": "jest && tsc", | ||
"build": "tsc" | ||
}, | ||
@@ -27,0 +27,0 @@ "repository": { |
@@ -10,2 +10,7 @@ # Typed Duration | ||
**Note**: requires TypeScript 3.8 or later | ||
Version 1.x works on Node 10+ | ||
Version 2.x requires Node 16+ | ||
## Installation | ||
@@ -134,2 +139,2 @@ | ||
See the [GitHub repo](https://github.com/jwulf/typed-duration). | ||
See the [GitHub repo](https://github.com/jwulf/typed-duration). |
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
15449
292
139