@toreda/time
Version:
Simple, small footprint library for common time operations and converting between units of time.
25 lines (24 loc) • 745 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.timeUnitValue = timeUnitValue;
const supported_1 = require("./supported");
/**
* Returns the first value that is a valid `TimeUnit`. If none of the
* provided values are valid, returns `fallback`.
*
* @param fallback Returned when no `values` entry is a valid `TimeUnit`.
* @param values Candidate values to validate, in priority order.
*
* @category Time Units
*/
function timeUnitValue(fallback, ...values) {
if (!Array.isArray(values) || !values.length) {
return fallback;
}
for (const value of values) {
if ((0, supported_1.timeUnitSupported)(value)) {
return value;
}
}
return fallback;
}