cronstrue 3.46.0 → 3.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -60,6 +60,21 @@ var CronParser = (function () {
60
60
  }
61
61
  this.normalize(parsed);
62
62
  this.validate(parsed);
63
+ var hasWildcardItem = function (part) { return part.indexOf(",") > -1 && part.split(",").indexOf("*") > -1; };
64
+ for (var _i = 0, _b = [
65
+ [3, 5],
66
+ [5, 3],
67
+ ]; _i < _b.length; _i++) {
68
+ var _c = _b[_i], part = _c[0], otherPart = _c[1];
69
+ if (hasWildcardItem(parsed[part]) && parsed[part][0] !== "*" && parsed[otherPart][0] !== "*") {
70
+ parsed[otherPart] = "*";
71
+ }
72
+ }
73
+ for (var i = 0; i < parsed.length; i++) {
74
+ if (hasWildcardItem(parsed[i])) {
75
+ parsed[i] = "*";
76
+ }
77
+ }
63
78
  return parsed;
64
79
  };
65
80
  CronParser.prototype.parseSpecial = function (expression) {
@@ -94,7 +109,9 @@ var CronParser = (function () {
94
109
  if (arrayElement.length === 0) {
95
110
  arrayElement.push("*");
96
111
  }
97
- arrayElement.sort(function (a, b) { return (a !== null && b !== null ? a - b : 0); });
112
+ if (arrayElement.indexOf("*") === -1) {
113
+ arrayElement.sort(function (a, b) { return (a !== null && b !== null ? a - b : 0); });
114
+ }
98
115
  parsed[i] = arrayElement.map(function (item) { return (item !== null ? item.toString() : ""); }).join(",");
99
116
  }
100
117
  }
@@ -482,6 +499,10 @@ var ExpressionDescriptor = (function () {
482
499
  if (lastItems.length > 0 && otherItems.length > 0) {
483
500
  return describeSeparately(otherItems, lastItems);
484
501
  }
502
+ var startsWithAnd_1 = this.expressionParts[3] != "*" && !this.options.logicalAndDayFields && dayOfWeekExpression.indexOf(",") == -1;
503
+ var stepSegments = dayOfWeekExpression.split("/");
504
+ var hasStep_1 = stepSegments.length > 1 && parseInt(stepSegments[1]) != 1;
505
+ var andPrefix_1 = this.getAndPrefix();
485
506
  description = this.getSegmentDescription(dayOfWeekExpression, {
486
507
  all: this.i18n.commaEveryDay(),
487
508
  single: function (s, form) {
@@ -505,12 +526,17 @@ var ExpressionDescriptor = (function () {
505
526
  return description;
506
527
  },
507
528
  increment: function (s) {
508
- return parseInt(s) == 1 ? "" : stringUtilities_1.StringUtilities.format(_this.i18n.commaEveryX0DaysOfTheWeek(s), s);
529
+ if (parseInt(s) == 1) {
530
+ return "";
531
+ }
532
+ var format = _this.i18n.commaEveryX0DaysOfTheWeek(s);
533
+ return stringUtilities_1.StringUtilities.format(startsWithAnd_1 && andPrefix_1 ? andPrefix_1 + ExpressionDescriptor.removeLeadingComma(format) : format, s);
509
534
  },
510
535
  range: function (s) {
511
536
  var beginFrom = s.substring(0, s.indexOf("-"));
512
- var domSpecified = _this.expressionParts[3] != "*";
513
- return domSpecified ? _this.i18n.commaAndX0ThroughX1(beginFrom) : _this.i18n.commaX0ThroughX1(beginFrom);
537
+ return startsWithAnd_1 && (!hasStep_1 || !andPrefix_1)
538
+ ? _this.i18n.commaAndX0ThroughX1(beginFrom)
539
+ : _this.i18n.commaX0ThroughX1(beginFrom);
514
540
  },
515
541
  format: function (s) {
516
542
  var format = null;
@@ -557,6 +583,15 @@ var ExpressionDescriptor = (function () {
557
583
  format: function () { return (_this.i18n.commaOnlyInMonthX0 ? _this.i18n.commaOnlyInMonthX0() : _this.i18n.commaOnlyInX0()); },
558
584
  });
559
585
  };
586
+ ExpressionDescriptor.prototype.getAndPrefix = function () {
587
+ var plain = this.i18n.commaX0ThroughX1();
588
+ var withAnd = this.i18n.commaAndX0ThroughX1();
589
+ var body = ExpressionDescriptor.removeLeadingComma(plain);
590
+ if (withAnd == plain || withAnd.length <= body.length || withAnd.slice(-body.length) != body) {
591
+ return null;
592
+ }
593
+ return withAnd.slice(0, -body.length);
594
+ };
560
595
  ExpressionDescriptor.removeLeadingComma = function (description) {
561
596
  return description.replace(/^[,،,、] ?/, "");
562
597
  };
@@ -2742,7 +2777,7 @@ var en = (function () {
2742
2777
  return ", %s through %s";
2743
2778
  };
2744
2779
  en.prototype.commaAndX0ThroughX1 = function () {
2745
- return ", %s through %s";
2780
+ return ", and %s through %s";
2746
2781
  };
2747
2782
  en.prototype.first = function () {
2748
2783
  return "first";