@toreda/time
Version:
Simple, small footprint library for common time operations and converting between units of time.
23 lines (22 loc) • 788 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.timeUnitFromAlias = timeUnitFromAlias;
const aliases_1 = require("../aliases");
/**
* Resolve a loose alias string (e.g. `'day'`, `'sec'`, `'minutes'`) to
* its canonical `TimeUnit` value. Intended for user-facing functions
* that accept alias input; returns `null` when the value is not a
* recognized alias or canonical unit.
*
* @param value Candidate alias or canonical unit string.
* @returns Canonical `TimeUnit` when recognized, otherwise `null`.
*
* @category Time Units
*/
function timeUnitFromAlias(value) {
var _a;
if (typeof value !== 'string') {
return null;
}
return (_a = aliases_1.timeUnitAliases.get(value)) !== null && _a !== void 0 ? _a : null;
}