react-cron-generator 2.0.3 → 2.0.5

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.
package/build/index.js CHANGED
@@ -336,15 +336,15 @@ var cronstrueI18n = {exports: {}};
336
336
  var description = this.getSegmentDescription(this.expressionParts[0], this.i18n.everySecond(), function (s) {
337
337
  return s;
338
338
  }, function (s) {
339
- return stringUtilities_1.StringUtilities.format(_this.i18n.everyX0Seconds(), s);
339
+ return stringUtilities_1.StringUtilities.format(_this.i18n.everyX0Seconds(s), s);
340
340
  }, function (s) {
341
341
  return _this.i18n.secondsX0ThroughX1PastTheMinute();
342
342
  }, function (s) {
343
343
  return s == "0"
344
344
  ? ""
345
345
  : parseInt(s) < 20
346
- ? _this.i18n.atX0SecondsPastTheMinute()
347
- : _this.i18n.atX0SecondsPastTheMinuteGt20() || _this.i18n.atX0SecondsPastTheMinute();
346
+ ? _this.i18n.atX0SecondsPastTheMinute(s)
347
+ : _this.i18n.atX0SecondsPastTheMinuteGt20() || _this.i18n.atX0SecondsPastTheMinute(s);
348
348
  });
349
349
  return description;
350
350
  };
@@ -355,7 +355,7 @@ var cronstrueI18n = {exports: {}};
355
355
  var description = this.getSegmentDescription(this.expressionParts[1], this.i18n.everyMinute(), function (s) {
356
356
  return s;
357
357
  }, function (s) {
358
- return stringUtilities_1.StringUtilities.format(_this.i18n.everyX0Minutes(), s);
358
+ return stringUtilities_1.StringUtilities.format(_this.i18n.everyX0Minutes(s), s);
359
359
  }, function (s) {
360
360
  return _this.i18n.minutesX0ThroughX1PastTheHour();
361
361
  }, function (s) {
@@ -363,11 +363,11 @@ var cronstrueI18n = {exports: {}};
363
363
  return s == "0" && hourExpression.indexOf("/") == -1 && secondsExpression == ""
364
364
  ? _this.i18n.everyHour()
365
365
  : parseInt(s) < 20
366
- ? _this.i18n.atX0MinutesPastTheHour()
367
- : _this.i18n.atX0MinutesPastTheHourGt20() || _this.i18n.atX0MinutesPastTheHour();
366
+ ? _this.i18n.atX0MinutesPastTheHour(s)
367
+ : _this.i18n.atX0MinutesPastTheHourGt20() || _this.i18n.atX0MinutesPastTheHour(s);
368
368
  }
369
369
  catch (e) {
370
- return _this.i18n.atX0MinutesPastTheHour();
370
+ return _this.i18n.atX0MinutesPastTheHour(s);
371
371
  }
372
372
  });
373
373
  return description;
@@ -378,7 +378,7 @@ var cronstrueI18n = {exports: {}};
378
378
  var description = this.getSegmentDescription(expression, this.i18n.everyHour(), function (s) {
379
379
  return _this.formatTime(s, "0", "");
380
380
  }, function (s) {
381
- return stringUtilities_1.StringUtilities.format(_this.i18n.everyX0Hours(), s);
381
+ return stringUtilities_1.StringUtilities.format(_this.i18n.everyX0Hours(s), s);
382
382
  }, function (s) {
383
383
  return _this.i18n.betweenX0AndX1();
384
384
  }, function (s) {
@@ -388,7 +388,10 @@ var cronstrueI18n = {exports: {}};
388
388
  var atTheHourMatches = Array.from(description.matchAll(/:00/g));
389
389
  if (atTheHourMatches.length > 1) {
390
390
  var lastAtTheHourMatchIndex = atTheHourMatches[atTheHourMatches.length - 1].index;
391
- description = description.substring(0, lastAtTheHourMatchIndex) + ":59" + description.substring(lastAtTheHourMatchIndex + 3);
391
+ description =
392
+ description.substring(0, lastAtTheHourMatchIndex) +
393
+ ":59" +
394
+ description.substring(lastAtTheHourMatchIndex + 3);
392
395
  }
393
396
  }
394
397
  return description;
@@ -401,7 +404,7 @@ var cronstrueI18n = {exports: {}};
401
404
  description = "";
402
405
  }
403
406
  else {
404
- description = this.getSegmentDescription(this.expressionParts[5], this.i18n.commaEveryDay(), function (s) {
407
+ description = this.getSegmentDescription(this.expressionParts[5], this.i18n.commaEveryDay(), function (s, form) {
405
408
  var exp = s;
406
409
  if (s.indexOf("#") > -1) {
407
410
  exp = s.substr(0, s.indexOf("#"));
@@ -409,47 +412,54 @@ var cronstrueI18n = {exports: {}};
409
412
  else if (s.indexOf("L") > -1) {
410
413
  exp = exp.replace("L", "");
411
414
  }
412
- return daysOfWeekNames[parseInt(exp)];
415
+ return _this.i18n.daysOfTheWeekInCase
416
+ ? _this.i18n.daysOfTheWeekInCase(form)[parseInt(exp)]
417
+ : daysOfWeekNames[parseInt(exp)];
413
418
  }, function (s) {
414
419
  if (parseInt(s) == 1) {
415
420
  return "";
416
421
  }
417
422
  else {
418
- return stringUtilities_1.StringUtilities.format(_this.i18n.commaEveryX0DaysOfTheWeek(), s);
423
+ return stringUtilities_1.StringUtilities.format(_this.i18n.commaEveryX0DaysOfTheWeek(s), s);
419
424
  }
420
425
  }, function (s) {
426
+ var beginFrom = s.substring(0, s.indexOf("-"));
421
427
  var domSpecified = _this.expressionParts[3] != "*";
422
- return domSpecified ? _this.i18n.commaAndX0ThroughX1() : _this.i18n.commaX0ThroughX1();
428
+ return domSpecified ? _this.i18n.commaAndX0ThroughX1(beginFrom) : _this.i18n.commaX0ThroughX1(beginFrom);
423
429
  }, function (s) {
424
430
  var format = null;
425
431
  if (s.indexOf("#") > -1) {
426
432
  var dayOfWeekOfMonthNumber = s.substring(s.indexOf("#") + 1);
433
+ var dayOfWeekNumber = s.substring(0, s.indexOf("#"));
427
434
  var dayOfWeekOfMonthDescription = null;
428
435
  switch (dayOfWeekOfMonthNumber) {
429
436
  case "1":
430
- dayOfWeekOfMonthDescription = _this.i18n.first();
437
+ dayOfWeekOfMonthDescription = _this.i18n.first(dayOfWeekNumber);
431
438
  break;
432
439
  case "2":
433
- dayOfWeekOfMonthDescription = _this.i18n.second();
440
+ dayOfWeekOfMonthDescription = _this.i18n.second(dayOfWeekNumber);
434
441
  break;
435
442
  case "3":
436
- dayOfWeekOfMonthDescription = _this.i18n.third();
443
+ dayOfWeekOfMonthDescription = _this.i18n.third(dayOfWeekNumber);
437
444
  break;
438
445
  case "4":
439
- dayOfWeekOfMonthDescription = _this.i18n.fourth();
446
+ dayOfWeekOfMonthDescription = _this.i18n.fourth(dayOfWeekNumber);
440
447
  break;
441
448
  case "5":
442
- dayOfWeekOfMonthDescription = _this.i18n.fifth();
449
+ dayOfWeekOfMonthDescription = _this.i18n.fifth(dayOfWeekNumber);
443
450
  break;
444
451
  }
445
- format = _this.i18n.commaOnThe() + dayOfWeekOfMonthDescription + _this.i18n.spaceX0OfTheMonth();
452
+ format =
453
+ _this.i18n.commaOnThe(dayOfWeekOfMonthNumber) +
454
+ dayOfWeekOfMonthDescription +
455
+ _this.i18n.spaceX0OfTheMonth();
446
456
  }
447
457
  else if (s.indexOf("L") > -1) {
448
- format = _this.i18n.commaOnTheLastX0OfTheMonth();
458
+ format = _this.i18n.commaOnTheLastX0OfTheMonth(s.replace("L", ""));
449
459
  }
450
460
  else {
451
461
  var domSpecified = _this.expressionParts[3] != "*";
452
- format = domSpecified ? _this.i18n.commaAndOnX0() : _this.i18n.commaOnlyOnX0();
462
+ format = domSpecified ? _this.i18n.commaAndOnX0() : _this.i18n.commaOnlyOnX0(s);
453
463
  }
454
464
  return format;
455
465
  });
@@ -459,14 +469,16 @@ var cronstrueI18n = {exports: {}};
459
469
  ExpressionDescriptor.prototype.getMonthDescription = function () {
460
470
  var _this = this;
461
471
  var monthNames = this.i18n.monthsOfTheYear();
462
- var description = this.getSegmentDescription(this.expressionParts[4], "", function (s) {
463
- return monthNames[parseInt(s) - 1];
472
+ var description = this.getSegmentDescription(this.expressionParts[4], "", function (s, form) {
473
+ return form && _this.i18n.monthsOfTheYearInCase
474
+ ? _this.i18n.monthsOfTheYearInCase(form)[parseInt(s) - 1]
475
+ : monthNames[parseInt(s) - 1];
464
476
  }, function (s) {
465
477
  if (parseInt(s) == 1) {
466
478
  return "";
467
479
  }
468
480
  else {
469
- return stringUtilities_1.StringUtilities.format(_this.i18n.commaEveryX0Months(), s);
481
+ return stringUtilities_1.StringUtilities.format(_this.i18n.commaEveryX0Months(s), s);
470
482
  }
471
483
  }, function (s) {
472
484
  return _this.i18n.commaMonthX0ThroughMonthX1() || _this.i18n.commaX0ThroughX1();
@@ -501,7 +513,7 @@ var cronstrueI18n = {exports: {}};
501
513
  var lastDayOffSetMatches = expression.match(/L-(\d{1,2})/);
502
514
  if (lastDayOffSetMatches) {
503
515
  var offSetDays = lastDayOffSetMatches[1];
504
- description = stringUtilities_1.StringUtilities.format(this.i18n.commaDaysBeforeTheLastDayOfTheMonth(), offSetDays);
516
+ description = stringUtilities_1.StringUtilities.format(this.i18n.commaDaysBeforeTheLastDayOfTheMonth(offSetDays), offSetDays);
505
517
  break;
506
518
  }
507
519
  else if (expression == "*" && this.expressionParts[5] != "*") {
@@ -515,11 +527,11 @@ var cronstrueI18n = {exports: {}};
515
527
  ? stringUtilities_1.StringUtilities.format(_this.i18n.dayX0(), s)
516
528
  : s;
517
529
  }, function (s) {
518
- return s == "1" ? _this.i18n.commaEveryDay() : _this.i18n.commaEveryX0Days();
530
+ return s == "1" ? _this.i18n.commaEveryDay() : _this.i18n.commaEveryX0Days(s);
519
531
  }, function (s) {
520
- return _this.i18n.commaBetweenDayX0AndX1OfTheMonth();
532
+ return _this.i18n.commaBetweenDayX0AndX1OfTheMonth(s);
521
533
  }, function (s) {
522
- return _this.i18n.commaOnDayX0OfTheMonth();
534
+ return _this.i18n.commaOnDayX0OfTheMonth(s);
523
535
  });
524
536
  }
525
537
  break;
@@ -532,7 +544,7 @@ var cronstrueI18n = {exports: {}};
532
544
  var description = this.getSegmentDescription(this.expressionParts[6], "", function (s) {
533
545
  return /^\d+$/.test(s) ? new Date(parseInt(s), 1).getFullYear().toString() : s;
534
546
  }, function (s) {
535
- return stringUtilities_1.StringUtilities.format(_this.i18n.commaEveryX0Years(), s);
547
+ return stringUtilities_1.StringUtilities.format(_this.i18n.commaEveryX0Years(s), s);
536
548
  }, function (s) {
537
549
  return _this.i18n.commaYearX0ThroughYearX1() || _this.i18n.commaX0ThroughX1();
538
550
  }, function (s) {
@@ -613,8 +625,8 @@ var cronstrueI18n = {exports: {}};
613
625
  ExpressionDescriptor.prototype.generateRangeSegmentDescription = function (rangeExpression, getRangeDescriptionFormat, getSingleItemDescription) {
614
626
  var description = "";
615
627
  var rangeSegments = rangeExpression.split("-");
616
- var rangeSegment1Description = getSingleItemDescription(rangeSegments[0]);
617
- var rangeSegment2Description = getSingleItemDescription(rangeSegments[1]);
628
+ var rangeSegment1Description = getSingleItemDescription(rangeSegments[0], 1);
629
+ var rangeSegment2Description = getSingleItemDescription(rangeSegments[1], 2);
618
630
  var rangeDescriptionFormat = getRangeDescriptionFormat(rangeExpression);
619
631
  description += stringUtilities_1.StringUtilities.format(rangeDescriptionFormat, rangeSegment1Description, rangeSegment2Description);
620
632
  return description;
@@ -5029,6 +5041,18 @@ var cronstrueI18n = {exports: {}};
5029
5041
 
5030
5042
  Object.defineProperty(exports, "__esModule", ({ value: true }));
5031
5043
  exports.ru = void 0;
5044
+ var getPhraseByNumber = function (str, words) {
5045
+ var number = Number(str);
5046
+ return number !== undefined
5047
+ ? words[number % 100 > 4 && number % 100 < 20 ? 2 : [2, 0, 1, 1, 1, 2][number % 10 < 5 ? Math.abs(number) % 10 : 5]]
5048
+ : words[2];
5049
+ };
5050
+ var getPhraseByDayOfWeek = function (str, words) {
5051
+ var number = Number(str);
5052
+ return number !== undefined
5053
+ ? words[number === 0 ? 0 : number === 1 || number === 2 || number === 4 ? 1 : 2]
5054
+ : words[1];
5055
+ };
5032
5056
  var ru = (function () {
5033
5057
  function ru() {
5034
5058
  }
@@ -5071,26 +5095,26 @@ var cronstrueI18n = {exports: {}};
5071
5095
  ru.prototype.everySecond = function () {
5072
5096
  return "каждую секунду";
5073
5097
  };
5074
- ru.prototype.everyX0Seconds = function () {
5075
- return "каждые %s секунд";
5098
+ ru.prototype.everyX0Seconds = function (s) {
5099
+ return getPhraseByNumber(s, ["каждую %s секунду", "каждые %s секунды", "каждые %s секунд"]);
5076
5100
  };
5077
5101
  ru.prototype.secondsX0ThroughX1PastTheMinute = function () {
5078
5102
  return "секунды с %s по %s";
5079
5103
  };
5080
- ru.prototype.atX0SecondsPastTheMinute = function () {
5081
- return "в %s секунд";
5104
+ ru.prototype.atX0SecondsPastTheMinute = function (s) {
5105
+ return getPhraseByNumber(s, ["в %s секунду", "в %s секунды", "в %s секунд"]);
5082
5106
  };
5083
- ru.prototype.everyX0Minutes = function () {
5084
- return "каждые %s минут";
5107
+ ru.prototype.everyX0Minutes = function (s) {
5108
+ return getPhraseByNumber(s, ["каждую %s минуту", "каждые %s минуты", "каждые %s минут"]);
5085
5109
  };
5086
5110
  ru.prototype.minutesX0ThroughX1PastTheHour = function () {
5087
5111
  return "минуты с %s по %s";
5088
5112
  };
5089
- ru.prototype.atX0MinutesPastTheHour = function () {
5090
- return "в %s минут";
5113
+ ru.prototype.atX0MinutesPastTheHour = function (s) {
5114
+ return getPhraseByNumber(s, ["в %s минуту", "в %s минуты", "в %s минут"]);
5091
5115
  };
5092
- ru.prototype.everyX0Hours = function () {
5093
- return "каждые %s часов";
5116
+ ru.prototype.everyX0Hours = function (s) {
5117
+ return getPhraseByNumber(s, ["каждый %s час", "каждые %s часа", "каждые %s часов"]);
5094
5118
  };
5095
5119
  ru.prototype.betweenX0AndX1 = function () {
5096
5120
  return "с %s по %s";
@@ -5101,32 +5125,32 @@ var cronstrueI18n = {exports: {}};
5101
5125
  ru.prototype.commaEveryDay = function () {
5102
5126
  return ", каждый день";
5103
5127
  };
5104
- ru.prototype.commaEveryX0DaysOfTheWeek = function () {
5105
- return ", каждые %s дней недели";
5128
+ ru.prototype.commaEveryX0DaysOfTheWeek = function (s) {
5129
+ return getPhraseByNumber(s, ["", ", каждые %s дня недели", ", каждые %s дней недели"]);
5106
5130
  };
5107
- ru.prototype.commaX0ThroughX1 = function () {
5108
- return ", %s по %s";
5131
+ ru.prototype.commaX0ThroughX1 = function (s) {
5132
+ return s && (s[0] == "2" || s[0] == "3") ? ", со %s по %s" : ", с %s по %s";
5109
5133
  };
5110
- ru.prototype.commaAndX0ThroughX1 = function () {
5111
- return ", и %s по %s";
5134
+ ru.prototype.commaAndX0ThroughX1 = function (s) {
5135
+ return s && (s[0] == "2" || s[0] == "3") ? " и со %s по %s" : " и с %s по %s";
5112
5136
  };
5113
- ru.prototype.first = function () {
5114
- return "первый";
5137
+ ru.prototype.first = function (s) {
5138
+ return getPhraseByDayOfWeek(s, ["первое", "первый", "первую"]);
5115
5139
  };
5116
- ru.prototype.second = function () {
5117
- return "второй";
5140
+ ru.prototype.second = function (s) {
5141
+ return getPhraseByDayOfWeek(s, ["второе", "второй", "вторую"]);
5118
5142
  };
5119
- ru.prototype.third = function () {
5120
- return "третий";
5143
+ ru.prototype.third = function (s) {
5144
+ return getPhraseByDayOfWeek(s, ["третье", "третий", "третью"]);
5121
5145
  };
5122
- ru.prototype.fourth = function () {
5123
- return "четвертый";
5146
+ ru.prototype.fourth = function (s) {
5147
+ return getPhraseByDayOfWeek(s, ["четвертое", "четвертый", "четвертую"]);
5124
5148
  };
5125
- ru.prototype.fifth = function () {
5126
- return "пятый";
5149
+ ru.prototype.fifth = function (s) {
5150
+ return getPhraseByDayOfWeek(s, ["пятое", "пятый", "пятую"]);
5127
5151
  };
5128
- ru.prototype.commaOnThe = function () {
5129
- return ", в ";
5152
+ ru.prototype.commaOnThe = function (s) {
5153
+ return s === "2" ? ", во " : ", в ";
5130
5154
  };
5131
5155
  ru.prototype.spaceX0OfTheMonth = function () {
5132
5156
  return " %s месяца";
@@ -5134,17 +5158,20 @@ var cronstrueI18n = {exports: {}};
5134
5158
  ru.prototype.lastDay = function () {
5135
5159
  return "последний день";
5136
5160
  };
5137
- ru.prototype.commaOnTheLastX0OfTheMonth = function () {
5138
- return ", в последний %s месяца";
5161
+ ru.prototype.commaOnTheLastX0OfTheMonth = function (s) {
5162
+ return getPhraseByDayOfWeek(s, [", в последнее %s месяца", ", в последний %s месяца", ", в последнюю %s месяца"]);
5139
5163
  };
5140
- ru.prototype.commaOnlyOnX0 = function () {
5141
- return ", только в %s";
5164
+ ru.prototype.commaOnlyOnX0 = function (s) {
5165
+ return s && s[0] === "2" ? ", только во %s" : ", только в %s";
5142
5166
  };
5143
5167
  ru.prototype.commaAndOnX0 = function () {
5144
- return ", и в %s";
5168
+ return ", и %s";
5145
5169
  };
5146
- ru.prototype.commaEveryX0Months = function () {
5147
- return ", каждые %s месяцев";
5170
+ ru.prototype.commaEveryX0Months = function (s) {
5171
+ return getPhraseByNumber(s, ["", " каждые %s месяца", " каждые %s месяцев"]);
5172
+ };
5173
+ ru.prototype.commaOnlyInMonthX0 = function () {
5174
+ return ", только %s";
5148
5175
  };
5149
5176
  ru.prototype.commaOnlyInX0 = function () {
5150
5177
  return ", только в %s";
@@ -5155,29 +5182,33 @@ var cronstrueI18n = {exports: {}};
5155
5182
  ru.prototype.commaOnTheLastWeekdayOfTheMonth = function () {
5156
5183
  return ", в последний будний день месяца";
5157
5184
  };
5158
- ru.prototype.commaDaysBeforeTheLastDayOfTheMonth = function () {
5159
- return ", %s дней до последнего дня месяца";
5185
+ ru.prototype.commaDaysBeforeTheLastDayOfTheMonth = function (s) {
5186
+ return getPhraseByNumber(s, [
5187
+ ", за %s день до конца месяца",
5188
+ ", за %s дня до конца месяца",
5189
+ ", за %s дней до конца месяца",
5190
+ ]);
5160
5191
  };
5161
5192
  ru.prototype.firstWeekday = function () {
5162
5193
  return "первый будний день";
5163
5194
  };
5164
5195
  ru.prototype.weekdayNearestDayX0 = function () {
5165
- return "ближайший будний день к %s";
5196
+ return "ближайший будний день к %s числу";
5166
5197
  };
5167
5198
  ru.prototype.commaOnTheX0OfTheMonth = function () {
5168
5199
  return ", в %s месяца";
5169
5200
  };
5170
- ru.prototype.commaEveryX0Days = function () {
5171
- return ", каждые %s дней";
5201
+ ru.prototype.commaEveryX0Days = function (s) {
5202
+ return getPhraseByNumber(s, [", каждый %s день", ", каждые %s дня", ", каждые %s дней"]);
5172
5203
  };
5173
- ru.prototype.commaBetweenDayX0AndX1OfTheMonth = function () {
5174
- return ", с %s по %s число месяца";
5204
+ ru.prototype.commaBetweenDayX0AndX1OfTheMonth = function (s) {
5205
+ return s && s.substring(0, s.indexOf("-")) == "2" ? ", со %s по %s число месяца" : ", с %s по %s число месяца";
5175
5206
  };
5176
- ru.prototype.commaOnDayX0OfTheMonth = function () {
5177
- return ", в %s число месяца";
5207
+ ru.prototype.commaOnDayX0OfTheMonth = function (s) {
5208
+ return s && s[0] == "2" ? ", во %s число месяца" : ", в %s число месяца";
5178
5209
  };
5179
- ru.prototype.commaEveryX0Years = function () {
5180
- return ", каждые %s лет";
5210
+ ru.prototype.commaEveryX0Years = function (s) {
5211
+ return getPhraseByNumber(s, [", каждый %s год", ", каждые %s года", ", каждые %s лет"]);
5181
5212
  };
5182
5213
  ru.prototype.commaStartingX0 = function () {
5183
5214
  return ", начало %s";
@@ -5185,6 +5216,12 @@ var cronstrueI18n = {exports: {}};
5185
5216
  ru.prototype.daysOfTheWeek = function () {
5186
5217
  return ["воскресенье", "понедельник", "вторник", "среда", "четверг", "пятница", "суббота"];
5187
5218
  };
5219
+ ru.prototype.daysOfTheWeekInCase = function (f) {
5220
+ if (f === void 0) { f = 2; }
5221
+ return f == 1
5222
+ ? ["воскресенья", "понедельника", "вторника", "среды", "четверга", "пятницы", "субботы"]
5223
+ : ["воскресенье", "понедельник", "вторник", "среду", "четверг", "пятницу", "субботу"];
5224
+ };
5188
5225
  ru.prototype.monthsOfTheYear = function () {
5189
5226
  return [
5190
5227
  "январь",
@@ -5201,6 +5238,24 @@ var cronstrueI18n = {exports: {}};
5201
5238
  "декабрь",
5202
5239
  ];
5203
5240
  };
5241
+ ru.prototype.monthsOfTheYearInCase = function (f) {
5242
+ return f == 1
5243
+ ? [
5244
+ "января",
5245
+ "февраля",
5246
+ "марта",
5247
+ "апреля",
5248
+ "мая",
5249
+ "июня",
5250
+ "июля",
5251
+ "августа",
5252
+ "сентября",
5253
+ "октября",
5254
+ "ноября",
5255
+ "декабря",
5256
+ ]
5257
+ : this.monthsOfTheYear();
5258
+ };
5204
5259
  return ru;
5205
5260
  }());
5206
5261
  exports.ru = ru;