robert-util
Version:
Utilities for robert and robert-server packages
42 lines (41 loc) • 836 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseTime = exports.times = void 0;
const ms = 1;
const s = ms * 1000;
const m = s * 60;
const h = m * 60;
exports.times = {
ms,
msec: ms,
msecs: ms,
millisecond: ms,
milliseconds: ms,
s,
sec: s,
secs: s,
second: s,
seconds: s,
m,
min: m,
mins: m,
minute: m,
minutes: m,
h,
hr: h,
hrs: h,
hour: h,
hours: h
};
function parseTime(time) {
var _a;
if (typeof time === "number")
return time;
const amount = parseInt(time.match(/^\d+/)[0]);
const unit = time
.replace(/^\d+\s*/, "")
.trimEnd()
.toLowerCase();
return amount * ((_a = exports.times[unit]) !== null && _a !== void 0 ? _a : 0);
}
exports.parseTime = parseTime;