UNPKG

cron-js-parser

Version:

Cron expression parser to human readable format from Expression as well as Individual values

1,125 lines (1,100 loc) 279 kB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if(typeof define === 'function' && define.amd) define("cron-js-parser", [], factory); else if(typeof exports === 'object') exports["cron-js-parser"] = factory(); else root["cron-js-parser"] = factory(); })(globalThis, () => { return /******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ /***/ 61: /***/ (function(__unused_webpack_module, exports, __webpack_require__) { "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.parseCronExpression = exports.parseHumanReadable = void 0; const i18n_1 = __importDefault(__webpack_require__(116)); const abstracts_1 = __webpack_require__(709); const logical_1 = __webpack_require__(421); class Parser extends abstracts_1.QuartzParser { getExpression(cronObj) { let expr = ""; expr += this.seconds(cronObj.seconds); expr += this.minutes(cronObj.minutes); expr += this.hours(cronObj.hours); expr += this.daysOfMonth(cronObj.daysOfMonth); expr += this.months(cronObj.months); expr += this.daysOfWeek(cronObj.daysOfWeek); expr += this.years(cronObj.years); return expr; } isValid(cronObj) { return true; } commonLogic(cronObj) { let expr = ""; if (cronObj.mode === logical_1.cycle) { expr = "* "; } else if (cronObj.mode === logical_1.startAtRepeatCycleEvery) { expr = `${cronObj.value.startAt}/${cronObj.value.every} `; } else if (cronObj.mode === logical_1.startCycleInRange) { expr = `${cronObj.value.from}-${cronObj.value.to} `; } else if (cronObj.mode === logical_1.at) { if (cronObj.value.length > 0) { expr = `${cronObj.value.toString()} `; } else { throw new Error("Specified mode is missing values"); } } else { expr = "0 "; } return expr; } seconds(cronObj) { return this.commonLogic(cronObj); } minutes(cronObj) { return this.commonLogic(cronObj); } hours(cronObj) { return this.commonLogic(cronObj); } daysOfMonth(cronObj) { if (cronObj === undefined) { return "? "; } return this.commonLogic(cronObj); } months(cronObj) { return this.commonLogic(cronObj); } daysOfWeek(cronObj) { if (cronObj === undefined) { return "? "; } let expr = ""; if (cronObj.mode === logical_1.startAtRepeatCycleEvery) { expr = `${cronObj.value.startAt}/${cronObj.value.every} `; } else if (cronObj.mode === logical_1.onWeekDay) { if (cronObj.value.isLastWeek) { expr = cronObj.value.dayIndex + "L "; } else { expr = cronObj.value.dayIndex + "#" + cronObj.value.weekIndex + " "; } } else if (cronObj.mode === logical_1.startCycleInRange) { expr = `${cronObj.value.from}-${cronObj.value.to} `; } else if (cronObj.mode === logical_1.at) { if (cronObj.value.length > 0) { expr = `${cronObj.value.toString()} `; } else { throw new Error("Specified mode is missing values"); } } return expr; } years(cronObj) { if (cronObj !== undefined) { return this.commonLogic(cronObj); } return ""; } } const parseHumanReadable = (cronExpr, cronValues, language) => { let expr = cronExpr; if (!cronExpr) { const parser = new Parser(); expr = parser.getExpression(cronValues); } return i18n_1.default.toString(expr, { verbose: true, locale: language }); }; exports.parseHumanReadable = parseHumanReadable; const parseCronExpression = (cronValues) => { const parser = new Parser(); return parser.getExpression(cronValues); }; exports.parseCronExpression = parseCronExpression; /***/ }), /***/ 75: /***/ ((__unused_webpack_module, exports, __webpack_require__) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.deparseCronExpression = void 0; const abstracts_1 = __webpack_require__(709); const logical_1 = __webpack_require__(421); const constants_1 = __webpack_require__(106); class Deparser extends abstracts_1.QuartzDeparser { getCronObject(cronExpr) { this.isValid(cronExpr); const expressions = cronExpr.split(' '); const cronObj = { seconds: this.seconds(expressions[0]), minutes: this.minutes(expressions[1]), hours: this.hours(expressions[2]), daysOfMonth: this.daysOfMonth(expressions[3]), months: this.months(expressions[4]), }; const daysOfWeek = this.daysOfWeek(expressions[5]); if (daysOfWeek) { cronObj['daysOfWeek'] = daysOfWeek; } if (this.hasYearConfig(expressions)) { cronObj['years'] = this.years(expressions[6]); } return cronObj; } isValid(cronObj) { const expressions = cronObj.split(' '); if (expressions.length < 6) { throw new Error(constants_1.ErrorMessages.minimumRequired); } return true; } seconds(cronObj) { return this.commonLogic(cronObj); } minutes(cronObj) { return this.commonLogic(cronObj); } hours(cronObj) { return this.commonLogic(cronObj); } daysOfMonth(cronObj) { const trimmed = cronObj.trim(); if (trimmed === "?") { return undefined; } return this.commonLogic(cronObj); } months(cronObj) { return this.commonLogic(cronObj); } daysOfWeek(cronObj) { const trimmed = cronObj.trim(); if (trimmed === "?") { return undefined; } if (/^\d+\/\d+$/.test(trimmed)) { const [startAtStr, everyStr] = trimmed.split('/'); return { mode: logical_1.startAtRepeatCycleEvery, value: { startAt: parseInt(startAtStr, 10), every: parseInt(everyStr, 10), }, }; } if (/^\d+L$/.test(trimmed)) { const dayIndex = parseInt(trimmed.replace('L', ''), 10); return { mode: logical_1.onWeekDay, value: { dayIndex, isLastWeek: true, }, }; } if (/^\d+#\d+$/.test(trimmed)) { const [dayIndexStr, weekIndexStr] = trimmed.split('#'); return { mode: logical_1.onWeekDay, value: { dayIndex: parseInt(dayIndexStr, 10), weekIndex: parseInt(weekIndexStr, 10), isLastWeek: false, }, }; } if (/^\d+-\d+$/.test(trimmed)) { const [fromStr, toStr] = trimmed.split('-'); return { mode: logical_1.startCycleInRange, value: { from: fromStr, to: toStr, }, }; } if (/^\d+(,\d+)*$/.test(trimmed)) { const values = trimmed.split(',').map(Number); return { mode: logical_1.at, value: values, }; } } years(cronObj) { return this.commonLogic(cronObj); } hasYearConfig(exprs) { if ((exprs.length - 1) > 5) { return true; } ; return false; } commonLogic(expr) { const trimmed = expr.trim(); if (trimmed === '*') { return { mode: logical_1.cycle }; } if (trimmed.includes('/') && !trimmed.includes(',')) { const [startAtStr, everyStr] = trimmed.split('/'); const startAt = parseInt(startAtStr, 10); const every = parseInt(everyStr, 10); if (!isNaN(startAt) && !isNaN(every)) { return { mode: logical_1.startAtRepeatCycleEvery, value: { startAt, every } }; } } if (trimmed.includes('-') && !trimmed.includes(',')) { const [fromStr, toStr] = trimmed.split('-'); const from = parseInt(fromStr, 10); const to = parseInt(toStr, 10); if (!isNaN(from) && !isNaN(to)) { return { mode: logical_1.startCycleInRange, value: { from, to } }; } } if (trimmed.includes(',')) { const values = trimmed.split(',').map((v) => parseInt(v, 10)); if (values.every((v) => !isNaN(v))) { return { mode: logical_1.at, value: values }; } } if (!isNaN(parseInt(trimmed, 10))) { return { mode: logical_1.at, value: [parseInt(trimmed, 10)] }; } throw new Error('Invalid cron expression format'); } } const deparseCronExpression = (cronExpr) => { const deparser = new Deparser(); return deparser.getCronObject(cronExpr); }; exports.deparseCronExpression = deparseCronExpression; /***/ }), /***/ 91: /***/ ((module) => { (function webpackUniversalModuleDefinition(root, factory) { if(true) module.exports = factory(); else {} })(globalThis, () => { return /******/ (() => { // webpackBootstrap /******/ "use strict"; /******/ var __webpack_modules__ = ({ /***/ 949: /***/ ((__unused_webpack_module, exports, __nested_webpack_require_540__) => { Object.defineProperty(exports, "__esModule", ({ value: true })); exports.CronParser = void 0; var rangeValidator_1 = __nested_webpack_require_540__(515); var CronParser = (function () { function CronParser(expression, dayOfWeekStartIndexZero, monthStartIndexZero) { if (dayOfWeekStartIndexZero === void 0) { dayOfWeekStartIndexZero = true; } if (monthStartIndexZero === void 0) { monthStartIndexZero = false; } this.expression = expression; this.dayOfWeekStartIndexZero = dayOfWeekStartIndexZero; this.monthStartIndexZero = monthStartIndexZero; } CronParser.prototype.parse = function () { var _a; var parsed; var expression = (_a = this.expression) !== null && _a !== void 0 ? _a : ''; if (expression.startsWith('@')) { var special = this.parseSpecial(this.expression); parsed = this.extractParts(special); } else { parsed = this.extractParts(this.expression); } this.normalize(parsed); this.validate(parsed); return parsed; }; CronParser.prototype.parseSpecial = function (expression) { var specialExpressions = { '@yearly': '0 0 1 1 *', '@annually': '0 0 1 1 *', '@monthly': '0 0 1 * *', '@weekly': '0 0 * * 0', '@daily': '0 0 * * *', '@midnight': '0 0 * * *', '@hourly': '0 * * * *' }; var special = specialExpressions[expression]; if (!special) { throw new Error('Unknown special expression.'); } return special; }; CronParser.prototype.extractParts = function (expression) { if (!this.expression) { throw new Error("cron expression is empty"); } var parsed = expression.trim().split(/[ ]+/); for (var i = 0; i < parsed.length; i++) { if (parsed[i].includes(",")) { var arrayElement = parsed[i] .split(",") .map(function (item) { return item.trim(); }) .filter(function (item) { return item !== ""; }) .map(function (item) { return (!isNaN(Number(item)) ? Number(item) : item); }) .filter(function (item) { return item !== null && item !== ""; }); if (arrayElement.length === 0) { arrayElement.push("*"); } arrayElement.sort(function (a, b) { return (a !== null && b !== null ? a - b : 0); }); parsed[i] = arrayElement.map(function (item) { return (item !== null ? item.toString() : ""); }).join(","); } } if (parsed.length < 5) { throw new Error("Expression has only ".concat(parsed.length, " part").concat(parsed.length == 1 ? "" : "s", ". At least 5 parts are required.")); } else if (parsed.length == 5) { parsed.unshift(""); parsed.push(""); } else if (parsed.length == 6) { var isYearWithNoSecondsPart = /\d{4}$/.test(parsed[5]) || parsed[4] == "?" || parsed[2] == "?"; if (isYearWithNoSecondsPart) { parsed.unshift(""); } else { parsed.push(""); } } else if (parsed.length > 7) { throw new Error("Expression has ".concat(parsed.length, " parts; too many!")); } return parsed; }; CronParser.prototype.normalize = function (expressionParts) { var _this = this; expressionParts[3] = expressionParts[3].replace("?", "*"); expressionParts[5] = expressionParts[5].replace("?", "*"); expressionParts[2] = expressionParts[2].replace("?", "*"); if (expressionParts[0].indexOf("0/") == 0) { expressionParts[0] = expressionParts[0].replace("0/", "*/"); } if (expressionParts[1].indexOf("0/") == 0) { expressionParts[1] = expressionParts[1].replace("0/", "*/"); } if (expressionParts[2].indexOf("0/") == 0) { expressionParts[2] = expressionParts[2].replace("0/", "*/"); } if (expressionParts[3].indexOf("1/") == 0) { expressionParts[3] = expressionParts[3].replace("1/", "*/"); } if (expressionParts[4].indexOf("1/") == 0) { expressionParts[4] = expressionParts[4].replace("1/", "*/"); } if (expressionParts[6].indexOf("1/") == 0) { expressionParts[6] = expressionParts[6].replace("1/", "*/"); } expressionParts[5] = expressionParts[5].replace(/(^\d)|([^#/\s]\d)/g, function (t) { var dowDigits = t.replace(/\D/, ""); var dowDigitsAdjusted = dowDigits; if (_this.dayOfWeekStartIndexZero) { if (dowDigits == "7") { dowDigitsAdjusted = "0"; } } else { dowDigitsAdjusted = (parseInt(dowDigits) - 1).toString(); } return t.replace(dowDigits, dowDigitsAdjusted); }); if (expressionParts[5] == "L") { expressionParts[5] = "6"; } if (expressionParts[3] == "?") { expressionParts[3] = "*"; } if (expressionParts[3].indexOf("W") > -1 && (expressionParts[3].indexOf(",") > -1 || expressionParts[3].indexOf("-") > -1)) { throw new Error("The 'W' character can be specified only when the day-of-month is a single day, not a range or list of days."); } var days = { SUN: 0, MON: 1, TUE: 2, WED: 3, THU: 4, FRI: 5, SAT: 6, }; for (var day in days) { expressionParts[5] = expressionParts[5].replace(new RegExp(day, "gi"), days[day].toString()); } expressionParts[4] = expressionParts[4].replace(/(^\d{1,2})|([^#/\s]\d{1,2})/g, function (t) { var dowDigits = t.replace(/\D/, ""); var dowDigitsAdjusted = dowDigits; if (_this.monthStartIndexZero) { dowDigitsAdjusted = (parseInt(dowDigits) + 1).toString(); } return t.replace(dowDigits, dowDigitsAdjusted); }); var months = { JAN: 1, FEB: 2, MAR: 3, APR: 4, MAY: 5, JUN: 6, JUL: 7, AUG: 8, SEP: 9, OCT: 10, NOV: 11, DEC: 12, }; for (var month in months) { expressionParts[4] = expressionParts[4].replace(new RegExp(month, "gi"), months[month].toString()); } if (expressionParts[0] == "0") { expressionParts[0] = ""; } if (!/\*|\-|\,|\//.test(expressionParts[2]) && (/\*|\//.test(expressionParts[1]) || /\*|\//.test(expressionParts[0]))) { expressionParts[2] += "-".concat(expressionParts[2]); } for (var i = 0; i < expressionParts.length; i++) { if (expressionParts[i].indexOf(",") != -1) { expressionParts[i] = expressionParts[i] .split(",") .filter(function (str) { return str !== ""; }) .join(",") || "*"; } if (expressionParts[i] == "*/1") { expressionParts[i] = "*"; } if (expressionParts[i].indexOf("/") > -1 && !/^\*|\-|\,/.test(expressionParts[i])) { var stepRangeThrough = null; switch (i) { case 4: stepRangeThrough = "12"; break; case 5: stepRangeThrough = "6"; break; case 6: stepRangeThrough = "9999"; break; default: stepRangeThrough = null; break; } if (stepRangeThrough !== null) { var parts = expressionParts[i].split("/"); expressionParts[i] = "".concat(parts[0], "-").concat(stepRangeThrough, "/").concat(parts[1]); } } } }; CronParser.prototype.validate = function (parsed) { var standardCronPartCharacters = "0-9,\\-*\/"; this.validateOnlyExpectedCharactersFound(parsed[0], standardCronPartCharacters); this.validateOnlyExpectedCharactersFound(parsed[1], standardCronPartCharacters); this.validateOnlyExpectedCharactersFound(parsed[2], standardCronPartCharacters); this.validateOnlyExpectedCharactersFound(parsed[3], "0-9,\\-*\/LW"); this.validateOnlyExpectedCharactersFound(parsed[4], standardCronPartCharacters); this.validateOnlyExpectedCharactersFound(parsed[5], "0-9,\\-*\/L#"); this.validateOnlyExpectedCharactersFound(parsed[6], standardCronPartCharacters); this.validateAnyRanges(parsed); }; CronParser.prototype.validateAnyRanges = function (parsed) { rangeValidator_1.default.secondRange(parsed[0]); rangeValidator_1.default.minuteRange(parsed[1]); rangeValidator_1.default.hourRange(parsed[2]); rangeValidator_1.default.dayOfMonthRange(parsed[3]); rangeValidator_1.default.monthRange(parsed[4], this.monthStartIndexZero); rangeValidator_1.default.dayOfWeekRange(parsed[5], this.dayOfWeekStartIndexZero); }; CronParser.prototype.validateOnlyExpectedCharactersFound = function (cronPart, allowedCharsExpression) { var invalidChars = cronPart.match(new RegExp("[^".concat(allowedCharsExpression, "]+"), "gi")); if (invalidChars && invalidChars.length) { throw new Error("Expression contains invalid values: '".concat(invalidChars.toString(), "'")); } }; return CronParser; }()); exports.CronParser = CronParser; /***/ }), /***/ 333: /***/ ((__unused_webpack_module, exports, __nested_webpack_require_10753__) => { Object.defineProperty(exports, "__esModule", ({ value: true })); exports.ExpressionDescriptor = void 0; var stringUtilities_1 = __nested_webpack_require_10753__(823); var cronParser_1 = __nested_webpack_require_10753__(949); var ExpressionDescriptor = (function () { function ExpressionDescriptor(expression, options) { this.expression = expression; this.options = options; this.expressionParts = new Array(5); if (!this.options.locale && ExpressionDescriptor.defaultLocale) { this.options.locale = ExpressionDescriptor.defaultLocale; } if (!ExpressionDescriptor.locales[this.options.locale]) { var fallBackLocale = Object.keys(ExpressionDescriptor.locales)[0]; console.warn("Locale '".concat(this.options.locale, "' could not be found; falling back to '").concat(fallBackLocale, "'.")); this.options.locale = fallBackLocale; } this.i18n = ExpressionDescriptor.locales[this.options.locale]; if (options.use24HourTimeFormat === undefined) { options.use24HourTimeFormat = this.i18n.use24HourTimeFormatByDefault(); } } ExpressionDescriptor.toString = function (expression, _a) { var _b = _a === void 0 ? {} : _a, _c = _b.throwExceptionOnParseError, throwExceptionOnParseError = _c === void 0 ? true : _c, _d = _b.verbose, verbose = _d === void 0 ? false : _d, _e = _b.dayOfWeekStartIndexZero, dayOfWeekStartIndexZero = _e === void 0 ? true : _e, _f = _b.monthStartIndexZero, monthStartIndexZero = _f === void 0 ? false : _f, use24HourTimeFormat = _b.use24HourTimeFormat, _g = _b.locale, locale = _g === void 0 ? null : _g, _h = _b.tzOffset, tzOffset = _h === void 0 ? 0 : _h; var options = { throwExceptionOnParseError: throwExceptionOnParseError, verbose: verbose, dayOfWeekStartIndexZero: dayOfWeekStartIndexZero, monthStartIndexZero: monthStartIndexZero, use24HourTimeFormat: use24HourTimeFormat, locale: locale, tzOffset: tzOffset, }; if (options.tzOffset) { console.warn("'tzOffset' option has been deprecated and will be removed in a future release."); } var descripter = new ExpressionDescriptor(expression, options); return descripter.getFullDescription(); }; ExpressionDescriptor.initialize = function (localesLoader, defaultLocale) { if (defaultLocale === void 0) { defaultLocale = "en"; } ExpressionDescriptor.specialCharacters = ["/", "-", ",", "*"]; ExpressionDescriptor.defaultLocale = defaultLocale; localesLoader.load(ExpressionDescriptor.locales); }; ExpressionDescriptor.prototype.getFullDescription = function () { var description = ""; try { var parser = new cronParser_1.CronParser(this.expression, this.options.dayOfWeekStartIndexZero, this.options.monthStartIndexZero); this.expressionParts = parser.parse(); var timeSegment = this.getTimeOfDayDescription(); var dayOfMonthDesc = this.getDayOfMonthDescription(); var monthDesc = this.getMonthDescription(); var dayOfWeekDesc = this.getDayOfWeekDescription(); var yearDesc = this.getYearDescription(); description += timeSegment + dayOfMonthDesc + dayOfWeekDesc + monthDesc + yearDesc; description = this.transformVerbosity(description, !!this.options.verbose); description = description.charAt(0).toLocaleUpperCase() + description.substr(1); } catch (ex) { if (!this.options.throwExceptionOnParseError) { description = this.i18n.anErrorOccuredWhenGeneratingTheExpressionD(); } else { throw "".concat(ex); } } return description; }; ExpressionDescriptor.prototype.getTimeOfDayDescription = function () { var secondsExpression = this.expressionParts[0]; var minuteExpression = this.expressionParts[1]; var hourExpression = this.expressionParts[2]; var description = ""; if (!stringUtilities_1.StringUtilities.containsAny(minuteExpression, ExpressionDescriptor.specialCharacters) && !stringUtilities_1.StringUtilities.containsAny(hourExpression, ExpressionDescriptor.specialCharacters) && !stringUtilities_1.StringUtilities.containsAny(secondsExpression, ExpressionDescriptor.specialCharacters)) { description += this.i18n.atSpace() + this.formatTime(hourExpression, minuteExpression, secondsExpression); } else if (!secondsExpression && minuteExpression.indexOf("-") > -1 && !(minuteExpression.indexOf(",") > -1) && !(minuteExpression.indexOf("/") > -1) && !stringUtilities_1.StringUtilities.containsAny(hourExpression, ExpressionDescriptor.specialCharacters)) { var minuteParts = minuteExpression.split("-"); description += stringUtilities_1.StringUtilities.format(this.i18n.everyMinuteBetweenX0AndX1(), this.formatTime(hourExpression, minuteParts[0], ""), this.formatTime(hourExpression, minuteParts[1], "")); } else if (!secondsExpression && hourExpression.indexOf(",") > -1 && hourExpression.indexOf("-") == -1 && hourExpression.indexOf("/") == -1 && !stringUtilities_1.StringUtilities.containsAny(minuteExpression, ExpressionDescriptor.specialCharacters)) { var hourParts = hourExpression.split(","); description += this.i18n.at(); for (var i = 0; i < hourParts.length; i++) { description += " "; description += this.formatTime(hourParts[i], minuteExpression, ""); if (i < hourParts.length - 2) { description += ","; } if (i == hourParts.length - 2) { description += this.i18n.spaceAnd(); } } } else { var secondsDescription = this.getSecondsDescription(); var minutesDescription = this.getMinutesDescription(); var hoursDescription = this.getHoursDescription(); description += secondsDescription; if (description && minutesDescription) { description += ", "; } description += minutesDescription; if (minutesDescription === hoursDescription) { return description; } if (description && hoursDescription) { description += ", "; } description += hoursDescription; } return description; }; ExpressionDescriptor.prototype.getSecondsDescription = function () { var _this = this; var description = this.getSegmentDescription(this.expressionParts[0], this.i18n.everySecond(), function (s) { return s; }, function (s) { return stringUtilities_1.StringUtilities.format(_this.i18n.everyX0Seconds(s), s); }, function (s) { return _this.i18n.secondsX0ThroughX1PastTheMinute(); }, function (s) { return s == "0" ? "" : parseInt(s) < 20 ? _this.i18n.atX0SecondsPastTheMinute(s) : _this.i18n.atX0SecondsPastTheMinuteGt20() || _this.i18n.atX0SecondsPastTheMinute(s); }); return description; }; ExpressionDescriptor.prototype.getMinutesDescription = function () { var _this = this; var secondsExpression = this.expressionParts[0]; var hourExpression = this.expressionParts[2]; var description = this.getSegmentDescription(this.expressionParts[1], this.i18n.everyMinute(), function (s) { return s; }, function (s) { return stringUtilities_1.StringUtilities.format(_this.i18n.everyX0Minutes(s), s); }, function (s) { return _this.i18n.minutesX0ThroughX1PastTheHour(); }, function (s) { try { return s == "0" && hourExpression.indexOf("/") == -1 && secondsExpression == "" ? _this.i18n.everyHour() : parseInt(s) < 20 ? _this.i18n.atX0MinutesPastTheHour(s) : _this.i18n.atX0MinutesPastTheHourGt20() || _this.i18n.atX0MinutesPastTheHour(s); } catch (e) { return _this.i18n.atX0MinutesPastTheHour(s); } }); return description; }; ExpressionDescriptor.prototype.getHoursDescription = function () { var _this = this; var expression = this.expressionParts[2]; var hourIndex = 0; var rangeEndValues = []; expression .split("/")[0] .split(",") .forEach(function (range) { var rangeParts = range.split("-"); if (rangeParts.length === 2) { rangeEndValues.push({ value: rangeParts[1], index: hourIndex + 1 }); } hourIndex += rangeParts.length; }); var evaluationIndex = 0; var description = this.getSegmentDescription(expression, this.i18n.everyHour(), function (s) { var match = rangeEndValues.find(function (r) { return r.value === s && r.index === evaluationIndex; }); var isRangeEndWithNonZeroMinute = match && _this.expressionParts[1] !== "0"; evaluationIndex++; return isRangeEndWithNonZeroMinute ? _this.formatTime(s, "59", "") : _this.formatTime(s, "0", ""); }, function (s) { return stringUtilities_1.StringUtilities.format(_this.i18n.everyX0Hours(s), s); }, function (s) { return _this.i18n.betweenX0AndX1(); }, function (s) { return _this.i18n.atX0(); }); return description; }; ExpressionDescriptor.prototype.getDayOfWeekDescription = function () { var _this = this; var daysOfWeekNames = this.i18n.daysOfTheWeek(); var description = null; if (this.expressionParts[5] == "*") { description = ""; } else { description = this.getSegmentDescription(this.expressionParts[5], this.i18n.commaEveryDay(), function (s, form) { var exp = s; if (s.indexOf("#") > -1) { exp = s.substring(0, s.indexOf("#")); } else if (s.indexOf("L") > -1) { exp = exp.replace("L", ""); } var parsedExp = parseInt(exp); if (_this.options.tzOffset) { var hourExpression = _this.expressionParts[2]; var hour = parseInt(hourExpression) + (_this.options.tzOffset ? _this.options.tzOffset : 0); if (hour >= 24) { parsedExp++; } else if (hour < 0) { parsedExp--; } if (parsedExp > 6) { parsedExp = 0; } else if (parsedExp < 0) { parsedExp = 6; } } var description = _this.i18n.daysOfTheWeekInCase ? _this.i18n.daysOfTheWeekInCase(form)[parsedExp] : daysOfWeekNames[parsedExp]; if (s.indexOf("#") > -1) { var dayOfWeekOfMonthDescription = null; var dayOfWeekOfMonthNumber = s.substring(s.indexOf("#") + 1); var dayOfWeekNumber = s.substring(0, s.indexOf("#")); switch (dayOfWeekOfMonthNumber) { case "1": dayOfWeekOfMonthDescription = _this.i18n.first(dayOfWeekNumber); break; case "2": dayOfWeekOfMonthDescription = _this.i18n.second(dayOfWeekNumber); break; case "3": dayOfWeekOfMonthDescription = _this.i18n.third(dayOfWeekNumber); break; case "4": dayOfWeekOfMonthDescription = _this.i18n.fourth(dayOfWeekNumber); break; case "5": dayOfWeekOfMonthDescription = _this.i18n.fifth(dayOfWeekNumber); break; } description = dayOfWeekOfMonthDescription + " " + description; } return description; }, function (s) { if (parseInt(s) == 1) { return ""; } else { return stringUtilities_1.StringUtilities.format(_this.i18n.commaEveryX0DaysOfTheWeek(s), s); } }, function (s) { var beginFrom = s.substring(0, s.indexOf("-")); var domSpecified = _this.expressionParts[3] != "*"; return domSpecified ? _this.i18n.commaAndX0ThroughX1(beginFrom) : _this.i18n.commaX0ThroughX1(beginFrom); }, function (s) { var format = null; if (s.indexOf("#") > -1) { var dayOfWeekOfMonthNumber = s.substring(s.indexOf("#") + 1); var dayOfWeek = s.substring(0, s.indexOf("#")); format = _this.i18n.commaOnThe(dayOfWeekOfMonthNumber, dayOfWeek).trim() + _this.i18n.spaceX0OfTheMonth(); } else if (s.indexOf("L") > -1) { format = _this.i18n.commaOnTheLastX0OfTheMonth(s.replace("L", "")); } else { var domSpecified = _this.expressionParts[3] != "*"; format = domSpecified ? _this.i18n.commaAndOnX0() : _this.i18n.commaOnlyOnX0(s); } return format; }); } return description; }; ExpressionDescriptor.prototype.getMonthDescription = function () { var _this = this; var monthNames = this.i18n.monthsOfTheYear(); var description = this.getSegmentDescription(this.expressionParts[4], "", function (s, form) { return form && _this.i18n.monthsOfTheYearInCase ? _this.i18n.monthsOfTheYearInCase(form)[parseInt(s) - 1] : monthNames[parseInt(s) - 1]; }, function (s) { if (parseInt(s) == 1) { return ""; } else { return stringUtilities_1.StringUtilities.format(_this.i18n.commaEveryX0Months(s), s); } }, function (s) { return _this.i18n.commaMonthX0ThroughMonthX1() || _this.i18n.commaX0ThroughX1(); }, function (s) { return _this.i18n.commaOnlyInMonthX0 ? _this.i18n.commaOnlyInMonthX0() : _this.i18n.commaOnlyInX0(); }); return description; }; ExpressionDescriptor.prototype.getDayOfMonthDescription = function () { var _this = this; var description = null; var expression = this.expressionParts[3]; switch (expression) { case "L": description = this.i18n.commaOnTheLastDayOfTheMonth(); break; case "WL": case "LW": description = this.i18n.commaOnTheLastWeekdayOfTheMonth(); break; default: var weekDayNumberMatches = expression.match(/(\d{1,2}W)|(W\d{1,2})/); if (weekDayNumberMatches) { var dayNumber = parseInt(weekDayNumberMatches[0].replace("W", "")); var dayString = dayNumber == 1 ? this.i18n.firstWeekday() : stringUtilities_1.StringUtilities.format(this.i18n.weekdayNearestDayX0(), dayNumber.toString()); description = stringUtilities_1.StringUtilities.format(this.i18n.commaOnTheX0OfTheMonth(), dayString); break; } else { var lastDayOffSetMatches = expression.match(/L-(\d{1,2})/); if (lastDayOffSetMatches) { var offSetDays = lastDayOffSetMatches[1]; description = stringUtilities_1.StringUtilities.format(this.i18n.commaDaysBeforeTheLastDayOfTheMonth(offSetDays), offSetDays); break; } else if (expression == "*" && this.expressionParts[5] != "*") { return ""; } else { description = this.getSegmentDescription(expression, this.i18n.commaEveryDay(), function (s) { return s == "L" ? _this.i18n.lastDay() : _this.i18n.dayX0 ? stringUtilities_1.StringUtilities.format(_this.i18n.dayX0(), s) : s; }, function (s) { return s == "1" ? _this.i18n.commaEveryDay() : _this.i18n.commaEveryX0Days(s); }, function (s) { return _this.i18n.commaBetweenDayX0AndX1OfTheMonth(s); }, function (s) { return _this.i18n.commaOnDayX0OfTheMonth(s); }); } break; } } return description; }; ExpressionDescriptor.prototype.getYearDescription = function () { var _this = this; var description = this.getSegmentDescription(this.expressionParts[6], "", function (s) { return /^\d+$/.test(s) ? new Date(parseInt(s), 1).getFullYear().toString() : s; }, function (s) { return stringUtilities_1.StringUtilities.format(_this.i18n.commaEveryX0Years(s), s); }, function (s) { return _this.i18n.commaYearX0ThroughYearX1() || _this.i18n.commaX0ThroughX1(); }, function (s) { return _this.i18n.commaOnlyInYearX0 ? _this.i18n.commaOnlyInYearX0() : _this.i18n.commaOnlyInX0(); }); return description; }; ExpressionDescriptor.prototype.getSegmentDescription = function (expression, allDescription, getSingleItemDescription, getIncrementDescriptionFormat, getRangeDescriptionFormat, getDescriptionFormat) { var description = null; var doesExpressionContainIncrement = expression.indexOf("/") > -1; var doesExpressionContainRange = expression.indexOf("-") > -1; var doesExpressionContainMultipleValues = expression.indexOf(",") > -1; if (!expression) { description = ""; } else if (expression === "*") { description = allDescription; } else if (!doesExpressionContainIncrement && !doesExpressionContainRange && !doesExpressionContainMultipleValues) { description = stringUtilities_1.StringUtilities.format(getDescriptionFormat(expression), getSingleItemDescription(expression)); } else if (doesExpressionContainMultipleValues) { var segments = expression.split(","); var descriptionContent = ""; for (var i = 0; i < segments.length; i++) { if (i > 0 && segments.length > 2) { descriptionContent += ","; if (i < segments.length - 1) { descriptionContent += " "; } } if (i > 0 && segments.length > 1 && (i == segments.length - 1 || segments.length == 2)) { descriptionContent += "".concat(this.i18n.spaceAnd(), " "); } if (segments[i].indexOf("/") > -1 || segments[i].indexOf("-") > -1) { var isSegmentRangeWithoutIncrement = segments[i].indexOf("-") > -1 && segments[i].indexOf("/") == -1; var currentDescriptionContent = this.getSegmentDescription(segments[i], allDescription, getSingleItemDescription, getIncrementDescriptionFormat, isSegmentRangeWithoutIncrement ? this.i18n.commaX0ThroughX1 : getRangeDescriptionFormat, getDescriptionFormat); if (isSegmentRangeWithoutIncrement) { currentDescriptionContent = currentDescriptionContent.replace(", ", ""); } descriptionContent += currentDescriptionContent; } else if (!doesExpressionContainIncrement) { descriptionContent += getSingleItemDescription(segments[i]); } else { descriptionContent += this.getSegmentDescription(segments[i], allDescription, getSingleItemDescription, getIncrementDescriptionFormat, getRangeDescriptionFormat, getDescriptionFormat); } } if (!doesExpressionContainIncrement) { description = stringUtilities_1.StringUtilities.format(getDescriptionFormat(expression), descriptionContent); } else { description = descriptionContent; } } else if (doesExpressionContainIncrement) { var segments = expression.split("/"); description = stringUtilities_1.StringUtilities.format(getIncrementDescriptionFormat(segments[1]), segments[1]); if (segments[0].indexOf("-") > -1) { var rangeSegmentDescription = this.generateRangeSegmentDescription(segments[0], getRangeDescriptionFormat, getSingleItemDescription); if (rangeSegmentDescription.indexOf(", ") != 0) { description += ", "; } description += rangeSegmentDescription; } else if (segments[0].indexOf("*") == -1) { var rangeItemDescription = stringUtilities_1.StringUtilities.format(getDescriptionFormat(segments[0]), getSingleItemDescription(segments[0])); rangeItemDescription = rangeItemDescription.replace(", ", ""); description += stringUtilities_1.StringUtilities.format(this.i18n.commaStartingX0(), rangeItemDescription); } } else if (doesExpressionContainRange) { description = this.generateRangeSegmentDescription(expression, getRangeDescriptionFormat, getSingleItemDescription); } return description; }; ExpressionDescriptor.prototype.generateRangeSegmentDescription = function (rangeExpression, getRangeDescriptionFormat, getSingleItemDescription) { var description = ""; var rangeSegments = rangeExpression.split("-"); var rangeSegment1Description = getSingleItemDescription(rangeSegments[0], 1); var rangeSegment2Description = getSingleItemDescription(rangeSegments[1], 2); var rangeDescriptionFormat = getRangeDescriptionFormat(rangeExpression); description += stringUtilities_1.StringUtilities.format(rangeDescriptionFormat, rangeSegment1Description, rangeSegment2Description); return description; }; ExpressionDescriptor.prototype.formatTime = function (hourExpression, minuteExpression, secondExpression) { var hourOffset = 0; var minuteOffset = 0; if (this.options.tzOffset) { hourOffset = this.options.tzOffset > 0 ? Math.floor(this.options.tzOffset) : Math.ceil(this.options.tzOffset); minuteOffset = parseFloat((this.options.tzOffset % 1).toFixed(2)); if (minuteOffset != 0) { minuteOffset *= 60; } } var hour = parseInt(hourExpression) + hourOffset; var minute = parseInt(minuteExpression) + minuteOffset; if (minute >= 60) { minute -= 60; hour += 1; } else if (minute < 0) { minute += 60; hour -= 1; } if (hour >= 24) { hour = hour - 24; } else if (hour < 0) { hour = 24 + hour; } var period = ""; var setPeriodBeforeTime = false; if (!this.options.use24HourTimeFormat) { setPeriodBeforeTime = !!(this.i18n.setPeriodBeforeTime && this.i18n.setPeriodBeforeTime()); period = setPeriodBeforeTime ? "".concat(this.getPeriod(hour), " ") : " ".concat(this.getPeriod(hour)); if (hour > 12) { hour -= 12; } if (hour === 0) { hour = 12; } } var second = ""; if (secondExpression) { second = ":".concat(("00" + secondExpression).substring(secondExpression.length)); } return "".concat(setPeriodBeforeTime ? period : "").concat(("00" + hour.toString()).substring(hour.toString().length), ":").concat(("00" + minute.toString()).substring(minute.toString().length)).concat(second).concat(!setPeriodBeforeTime ? period : ""); }; ExpressionDescriptor.prototype.transformVerbosity = function (description, useVerboseFormat) { if (!useVerboseFormat) { description = description.replace(new RegExp(", ".concat(this.i18n.everyMinute()), "g"), ""); description = description.replace(new RegExp(", ".concat(this.i18n.everyHour()), "g"), ""); description = description.replace(new RegExp(this.i18n.commaEveryDay(), "g"), ""); description = description.replace(/\, ?$/, ""); if (this.i18n.conciseVerbosityReplacements) { for (var _i = 0, _a = Object.entries(this.i18n.conciseVerbosityReplacements()); _i < _a.length; _i++) { var _b = _a[_i], key = _b[0], value = _b[1]; description = description.replace(new RegExp(key, "g"), value); } } } return description; }; ExpressionDescriptor.prototype.getPeriod = function (hour) { return hour >= 12 ? (this.i18n.pm && this.i18n.pm()) || "PM" : (this.i18n.am && this.i18n.am()) || "AM"; }; ExpressionDescriptor.locales = {}; return ExpressionDescriptor; }()); exports.ExpressionDescriptor = ExpressionDescriptor; /***/ }), /***/ 99: /***/ ((__unused_webpack_module, exports, __nested_webpack_require_37468__) => { Object.defineProperty(exports, "__esModule", ({ value: true })); exports.bg = exports.my = exports.vi = exports.ar = exports.th = exports.af = exports.hu = exports.be = exports.ca = exports.fa = exports.sw = exports.sl = exports.fi = exports.sk = exports.cs = exports.he = exports.ja = exports.zh_TW = exports.zh_CN = exports.uk = exports.tr = exports.ru = exports.ro = exports.pt_PT = exports.pt_BR = exports.pl = exports.sv = exports.nb = exports.nl = exports.ko = exports.id = exports.it = exports.fr = exports.es = exports.de = exports.da = exports.en = void 0; var en_1 = __nested_webpack_require_37468__(486); Object.defineProperty(exports, "en", ({ enumerable: true, get: function () { return en_1.en; } })); var da_1 = __nested_webpack_require_37468__(506); Object.defineProperty(exports, "da", ({ enumerable: true, get: function () { return da_1.da; } })); var de_1 = __nested_webpack_require_37468__(230); Object.defineProperty(exports, "de", ({ enumerable: true, get: function () { return de_1.de; } })); var es_1 = __nested_webpack_require_37468__(153); Object.defineProperty(exports, "es", ({ enumerable: true, get: function () { return es_1.es; } })); var fr_1 = __nested_webpack_require_37468__(517); Object.defineProperty(exports, "fr", ({ enumerable: true, get: function () { return fr_1.fr; } })); var it_1 = __nested_webpack_require_37468__(488); Object.defineProperty(exports, "it", ({ enumerable: true, get: function () { return it_1.it; } })); var id_1 = __nested_webpack_require_37468__(72); Object.defineProperty(exports, "id", ({ enumerable: true, get: function () { return id_1.id; } })); var ko_1 = __nested_webpack_require_37468__(839); Object.defineProperty(exports, "ko", ({ enumerable: true, get: function () { return ko_1.ko; } })); var nl_1 = __nested_webpack_require_37468__(647); Object.defineProperty(exports, "nl", ({ enumerable: true, get: function () { return nl_1.nl; } })); var nb_1 = __nested_webpack_require_37468__(957); Object.defineProperty(exports, "nb", ({ enumerable: true, get: function () { return nb_1.nb; } })); var sv_1 = __nested_webpack_require_37468__(544); Object.defineProperty(exports, "sv", ({ enumerable: true, get: function () { return sv_1.sv; } })); var pl_1 = __nested_webpack_require_37468__(905); Object.defineProperty(exports, "pl", ({ enumerable: true, get: function () { return pl_1.pl; } })); var pt_BR_1 = __nested_webpack_require_37468__(556); Object.defineProperty(exports, "pt_BR", ({ enumerable: true, get: