cronstrue
Version:
Convert cron expressions into human readable descriptions
1,052 lines (1,024 loc) • 43.6 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define("cronstrue", [], factory);
else if(typeof exports === 'object')
exports["cronstrue"] = factory();
else
root["cronstrue"] = factory();
})(typeof self !== 'undefined' ? self : this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 5);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExpressionDescriptor = void 0;
var stringUtilities_1 = __webpack_require__(1);
var cronParser_1 = __webpack_require__(2);
var ExpressionDescriptor = (function () {
function ExpressionDescriptor(expression, options) {
this.expression = expression;
this.options = options;
this.expressionParts = new Array(5);
if (ExpressionDescriptor.locales[options.locale]) {
this.i18n = ExpressionDescriptor.locales[options.locale];
}
else {
console.warn("Locale '" + options.locale + "' could not be found; falling back to 'en'.");
this.i18n = ExpressionDescriptor.locales["en"];
}
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, use24HourTimeFormat = _b.use24HourTimeFormat, _f = _b.locale, locale = _f === void 0 ? "en" : _f;
var options = {
throwExceptionOnParseError: throwExceptionOnParseError,
verbose: verbose,
dayOfWeekStartIndexZero: dayOfWeekStartIndexZero,
use24HourTimeFormat: use24HourTimeFormat,
locale: locale,
};
var descripter = new ExpressionDescriptor(expression, options);
return descripter.getFullDescription();
};
ExpressionDescriptor.initialize = function (localesLoader) {
ExpressionDescriptor.specialCharacters = ["/", "-", ",", "*"];
localesLoader.load(ExpressionDescriptor.locales);
};
ExpressionDescriptor.prototype.getFullDescription = function () {
var description = "";
try {
var parser = new cronParser_1.CronParser(this.expression, this.options.dayOfWeekStartIndexZero);
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 "" + 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.length > 0 && minutesDescription.length > 0) {
description += ", ";
}
description += minutesDescription;
if (minutesDescription === hoursDescription) {
return description;
}
if (description.length > 0 && hoursDescription.length > 0) {
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);
}, function (s) {
return _this.i18n.secondsX0ThroughX1PastTheMinute();
}, function (s) {
return s == "0"
? ""
: parseInt(s) < 20
? _this.i18n.atX0SecondsPastTheMinute()
: _this.i18n.atX0SecondsPastTheMinuteGt20() || _this.i18n.atX0SecondsPastTheMinute();
});
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);
}, 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()
: _this.i18n.atX0MinutesPastTheHourGt20() || _this.i18n.atX0MinutesPastTheHour();
}
catch (e) {
return _this.i18n.atX0MinutesPastTheHour();
}
});
return description;
};
ExpressionDescriptor.prototype.getHoursDescription = function () {
var _this = this;
var expression = this.expressionParts[2];
var description = this.getSegmentDescription(expression, this.i18n.everyHour(), function (s) {
return _this.formatTime(s, "0", "");
}, function (s) {
return stringUtilities_1.StringUtilities.format(_this.i18n.everyX0Hours(), 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) {
var exp = s;
if (s.indexOf("#") > -1) {
exp = s.substr(0, s.indexOf("#"));
}
else if (s.indexOf("L") > -1) {
exp = exp.replace("L", "");
}
return daysOfWeekNames[parseInt(exp)];
}, function (s) {
if (parseInt(s) == 1) {
return "";
}
else {
return stringUtilities_1.StringUtilities.format(_this.i18n.commaEveryX0DaysOfTheWeek(), s);
}
}, function (s) {
return _this.i18n.commaX0ThroughX1();
}, function (s) {
var format = null;
if (s.indexOf("#") > -1) {
var dayOfWeekOfMonthNumber = s.substring(s.indexOf("#") + 1);
var dayOfWeekOfMonthDescription = null;
switch (dayOfWeekOfMonthNumber) {
case "1":
dayOfWeekOfMonthDescription = _this.i18n.first();
break;
case "2":
dayOfWeekOfMonthDescription = _this.i18n.second();
break;
case "3":
dayOfWeekOfMonthDescription = _this.i18n.third();
break;
case "4":
dayOfWeekOfMonthDescription = _this.i18n.fourth();
break;
case "5":
dayOfWeekOfMonthDescription = _this.i18n.fifth();
break;
}
format = _this.i18n.commaOnThe() + dayOfWeekOfMonthDescription + _this.i18n.spaceX0OfTheMonth();
}
else if (s.indexOf("L") > -1) {
format = _this.i18n.commaOnTheLastX0OfTheMonth();
}
else {
var domSpecified = _this.expressionParts[3] != "*";
format = domSpecified ? _this.i18n.commaAndOnX0() : _this.i18n.commaOnlyOnX0();
}
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) {
return monthNames[parseInt(s) - 1];
}, function (s) {
if (parseInt(s) == 1) {
return "";
}
else {
return stringUtilities_1.StringUtilities.format(_this.i18n.commaEveryX0Months(), 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);
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();
}, function (s) {
return _this.i18n.commaBetweenDayX0AndX1OfTheMonth();
}, function (s) {
return _this.i18n.commaOnDayX0OfTheMonth();
});
}
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);
}, 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 += 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]);
var rangeSegment2Description = getSingleItemDescription(rangeSegments[1]);
rangeSegment2Description = rangeSegment2Description.replace(":00", ":59");
var rangeDescriptionFormat = getRangeDescriptionFormat(rangeExpression);
description += stringUtilities_1.StringUtilities.format(rangeDescriptionFormat, rangeSegment1Description, rangeSegment2Description);
return description;
};
ExpressionDescriptor.prototype.formatTime = function (hourExpression, minuteExpression, secondExpression) {
var hour = parseInt(hourExpression);
var period = "";
var setPeriodBeforeTime = false;
if (!this.options.use24HourTimeFormat) {
setPeriodBeforeTime = this.i18n.setPeriodBeforeTime && this.i18n.setPeriodBeforeTime();
period = setPeriodBeforeTime ? this.getPeriod(hour) + " " : " " + this.getPeriod(hour);
if (hour > 12) {
hour -= 12;
}
if (hour === 0) {
hour = 12;
}
}
var minute = minuteExpression;
var second = "";
if (secondExpression) {
second = ":" + ("00" + secondExpression).substring(secondExpression.length);
}
return "" + (setPeriodBeforeTime ? period : "") + ("00" + hour.toString()).substring(hour.toString().length) + ":" + ("00" + minute.toString()).substring(minute.toString().length) + second + (!setPeriodBeforeTime ? period : "");
};
ExpressionDescriptor.prototype.transformVerbosity = function (description, useVerboseFormat) {
if (!useVerboseFormat) {
description = description.replace(new RegExp(", " + this.i18n.everyMinute(), "g"), "");
description = description.replace(new RegExp(", " + this.i18n.everyHour(), "g"), "");
description = description.replace(new RegExp(this.i18n.commaEveryDay(), "g"), "");
description = description.replace(/\, ?$/, "");
}
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;
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StringUtilities = void 0;
var StringUtilities = (function () {
function StringUtilities() {
}
StringUtilities.format = function (template) {
var values = [];
for (var _i = 1; _i < arguments.length; _i++) {
values[_i - 1] = arguments[_i];
}
return template.replace(/%s/g, function () {
return values.shift();
});
};
StringUtilities.containsAny = function (text, searchStrings) {
return searchStrings.some(function (c) {
return text.indexOf(c) > -1;
});
};
return StringUtilities;
}());
exports.StringUtilities = StringUtilities;
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CronParser = void 0;
var rangeValidator_1 = __webpack_require__(3);
var CronParser = (function () {
function CronParser(expression, dayOfWeekStartIndexZero) {
if (dayOfWeekStartIndexZero === void 0) { dayOfWeekStartIndexZero = true; }
this.expression = expression;
this.dayOfWeekStartIndexZero = dayOfWeekStartIndexZero;
}
CronParser.prototype.parse = function () {
var parsed = this.extractParts(this.expression);
this.normalize(parsed);
this.validate(parsed);
return parsed;
};
CronParser.prototype.extractParts = function (expression) {
if (!this.expression) {
throw new Error("Expression is empty");
}
var parsed = expression.trim().split(/[ ]+/);
if (parsed.length < 5) {
throw new Error("Expression has only " + parsed.length + " part" + (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 " + 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());
}
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] += "-" + 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] = parts[0] + "-" + stepRangeThrough + "/" + parts[1];
}
}
}
};
CronParser.prototype.validate = function (parsed) {
this.assertNoInvalidCharacters("DOW", parsed[5]);
this.assertNoInvalidCharacters("DOM", parsed[3]);
this.validateRange(parsed);
};
CronParser.prototype.validateRange = 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]);
rangeValidator_1.default.dayOfWeekRange(parsed[5]);
};
CronParser.prototype.assertNoInvalidCharacters = function (partDescription, expression) {
var invalidChars = expression.match(/[A-KM-VX-Z]+/gi);
if (invalidChars && invalidChars.length) {
throw new Error(partDescription + " part contains invalid values: '" + invalidChars.toString() + "'");
}
};
return CronParser;
}());
exports.CronParser = CronParser;
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function assert(value, message) {
if (!value) {
throw new Error(message);
}
}
var RangeValidator = (function () {
function RangeValidator() {
}
RangeValidator.secondRange = function (parse) {
var parsed = parse.split(',');
for (var i = 0; i < parsed.length; i++) {
if (!isNaN(parseInt(parsed[i], 10))) {
var second = parseInt(parsed[i], 10);
assert(second >= 0 && second <= 59, 'seconds part must be >= 0 and <= 59');
}
}
};
RangeValidator.minuteRange = function (parse) {
var parsed = parse.split(',');
for (var i = 0; i < parsed.length; i++) {
if (!isNaN(parseInt(parsed[i], 10))) {
var minute = parseInt(parsed[i], 10);
assert(minute >= 0 && minute <= 59, 'minutes part must be >= 0 and <= 59');
}
}
};
RangeValidator.hourRange = function (parse) {
var parsed = parse.split(',');
for (var i = 0; i < parsed.length; i++) {
if (!isNaN(parseInt(parsed[i], 10))) {
var hour = parseInt(parsed[i], 10);
assert(hour >= 0 && hour <= 23, 'hours part must be >= 0 and <= 23');
}
}
};
RangeValidator.dayOfMonthRange = function (parse) {
var parsed = parse.split(',');
for (var i = 0; i < parsed.length; i++) {
if (!isNaN(parseInt(parsed[i], 10))) {
var dayOfMonth = parseInt(parsed[i], 10);
assert(dayOfMonth >= 1 && dayOfMonth <= 31, 'DOM part must be >= 1 and <= 31');
}
}
};
RangeValidator.monthRange = function (parse) {
var parsed = parse.split(',');
for (var i = 0; i < parsed.length; i++) {
if (!isNaN(parseInt(parsed[i], 10))) {
var month = parseInt(parsed[i], 10);
assert(month >= 1 && month <= 12, 'month part must be >= 1 and <= 12');
}
}
};
RangeValidator.dayOfWeekRange = function (parse) {
var parsed = parse.split(',');
for (var i = 0; i < parsed.length; i++) {
if (!isNaN(parseInt(parsed[i], 10))) {
var dayOfWeek = parseInt(parsed[i], 10);
assert(dayOfWeek >= 0 && dayOfWeek <= 6, 'DOW part must be >= 0 and <= 6');
}
}
};
return RangeValidator;
}());
exports.default = RangeValidator;
/***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.en = void 0;
var en = (function () {
function en() {
}
en.prototype.atX0SecondsPastTheMinuteGt20 = function () {
return null;
};
en.prototype.atX0MinutesPastTheHourGt20 = function () {
return null;
};
en.prototype.commaMonthX0ThroughMonthX1 = function () {
return null;
};
en.prototype.commaYearX0ThroughYearX1 = function () {
return null;
};
en.prototype.use24HourTimeFormatByDefault = function () {
return false;
};
en.prototype.anErrorOccuredWhenGeneratingTheExpressionD = function () {
return "An error occured when generating the expression description. Check the cron expression syntax.";
};
en.prototype.everyMinute = function () {
return "every minute";
};
en.prototype.everyHour = function () {
return "every hour";
};
en.prototype.atSpace = function () {
return "At ";
};
en.prototype.everyMinuteBetweenX0AndX1 = function () {
return "Every minute between %s and %s";
};
en.prototype.at = function () {
return "At";
};
en.prototype.spaceAnd = function () {
return " and";
};
en.prototype.everySecond = function () {
return "every second";
};
en.prototype.everyX0Seconds = function () {
return "every %s seconds";
};
en.prototype.secondsX0ThroughX1PastTheMinute = function () {
return "seconds %s through %s past the minute";
};
en.prototype.atX0SecondsPastTheMinute = function () {
return "at %s seconds past the minute";
};
en.prototype.everyX0Minutes = function () {
return "every %s minutes";
};
en.prototype.minutesX0ThroughX1PastTheHour = function () {
return "minutes %s through %s past the hour";
};
en.prototype.atX0MinutesPastTheHour = function () {
return "at %s minutes past the hour";
};
en.prototype.everyX0Hours = function () {
return "every %s hours";
};
en.prototype.betweenX0AndX1 = function () {
return "between %s and %s";
};
en.prototype.atX0 = function () {
return "at %s";
};
en.prototype.commaEveryDay = function () {
return ", every day";
};
en.prototype.commaEveryX0DaysOfTheWeek = function () {
return ", every %s days of the week";
};
en.prototype.commaX0ThroughX1 = function () {
return ", %s through %s";
};
en.prototype.first = function () {
return "first";
};
en.prototype.second = function () {
return "second";
};
en.prototype.third = function () {
return "third";
};
en.prototype.fourth = function () {
return "fourth";
};
en.prototype.fifth = function () {
return "fifth";
};
en.prototype.commaOnThe = function () {
return ", on the ";
};
en.prototype.spaceX0OfTheMonth = function () {
return " %s of the month";
};
en.prototype.lastDay = function () {
return "the last day";
};
en.prototype.commaOnTheLastX0OfTheMonth = function () {
return ", on the last %s of the month";
};
en.prototype.commaOnlyOnX0 = function () {
return ", only on %s";
};
en.prototype.commaAndOnX0 = function () {
return ", and on %s";
};
en.prototype.commaEveryX0Months = function () {
return ", every %s months";
};
en.prototype.commaOnlyInX0 = function () {
return ", only in %s";
};
en.prototype.commaOnTheLastDayOfTheMonth = function () {
return ", on the last day of the month";
};
en.prototype.commaOnTheLastWeekdayOfTheMonth = function () {
return ", on the last weekday of the month";
};
en.prototype.commaDaysBeforeTheLastDayOfTheMonth = function () {
return ", %s days before the last day of the month";
};
en.prototype.firstWeekday = function () {
return "first weekday";
};
en.prototype.weekdayNearestDayX0 = function () {
return "weekday nearest day %s";
};
en.prototype.commaOnTheX0OfTheMonth = function () {
return ", on the %s of the month";
};
en.prototype.commaEveryX0Days = function () {
return ", every %s days";
};
en.prototype.commaBetweenDayX0AndX1OfTheMonth = function () {
return ", between day %s and %s of the month";
};
en.prototype.commaOnDayX0OfTheMonth = function () {
return ", on day %s of the month";
};
en.prototype.commaEveryHour = function () {
return ", every hour";
};
en.prototype.commaEveryX0Years = function () {
return ", every %s years";
};
en.prototype.commaStartingX0 = function () {
return ", starting %s";
};
en.prototype.daysOfTheWeek = function () {
return ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
};
en.prototype.monthsOfTheYear = function () {
return [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
];
};
return en;
}());
exports.en = en;
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toString = void 0;
var expressionDescriptor_1 = __webpack_require__(0);
var enLocaleLoader_1 = __webpack_require__(6);
expressionDescriptor_1.ExpressionDescriptor.initialize(new enLocaleLoader_1.enLocaleLoader());
exports.default = expressionDescriptor_1.ExpressionDescriptor;
var toString = expressionDescriptor_1.ExpressionDescriptor.toString;
exports.toString = toString;
/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.enLocaleLoader = void 0;
var en_1 = __webpack_require__(4);
var enLocaleLoader = (function () {
function enLocaleLoader() {
}
enLocaleLoader.prototype.load = function (availableLocales) {
availableLocales["en"] = new en_1.en();
};
return enLocaleLoader;
}());
exports.enLocaleLoader = enLocaleLoader;
/***/ })
/******/ ]);
});