cronstrue 3.13.0 → 3.18.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.
package/README.md CHANGED
@@ -105,18 +105,8 @@ By default, only the English translation (`en`) is included when you import and
105
105
  ### CLI Usage
106
106
 
107
107
  ```sh
108
- $ npm install -g cronstrue
109
-
110
- $ cronstrue 1 2 3 4 5
111
- At 02:01 AM, on day 3 of the month, and on Friday, only in April
112
-
113
- $ cronstrue 1 2 3
114
- Error: too few arguments (3): 1 2 3
115
- Usage (5 args): cronstrue minute hour day-of-month month day-of-week
116
- or
117
- Usage (6 args): cronstrue second minute hour day-of-month month day-of-week
118
- or
119
- Usage (7 args): cronstrue second minute hour day-of-month month day-of-week year
108
+ npx cronstrue "*/5 * * * *"
109
+ Every 5 minutes
120
110
  ```
121
111
 
122
112
  ## Options
@@ -128,6 +118,7 @@ An options object can be passed as the second parameter to `cronstrue.toString`.
128
118
  - **dayOfWeekStartIndexZero: boolean** - Whether to interpret cron expression DOW `1` as Sunday or Monday. (Default: true)
129
119
  - **monthStartIndexZero: boolean** - Whether to interpret January as `0` or `1`. (Default: false)
130
120
  - **use24HourTimeFormat: boolean** - If true, descriptions will use a [24-hour clock](https://en.wikipedia.org/wiki/24-hour_clock) (Default: false but some translations will default to true)
121
+ - **trimHoursLeadingZero: boolean** - Whether to trim the leading zero that may appear in the hours description; e.g. "02:00 AM" -> "2:00 AM", "08:00" -> "8:00" (Default: false)
131
122
  - **locale: string** - The locale to use (Default: "en")
132
123
  - **logicalAndDayFields: boolean** - If true, descriptions for cron expressions with both day of month and day of week specified will follow a logical-AND wording rather than logical-OR wording; e.g. "...between day 11 and 17 of the month, only on Friday" rather than "...between day 11 and 17 of the month, and on Friday" (Default: false)
133
124
 
@@ -227,25 +218,36 @@ The following locales can be passed in for the `locale` option. Thank you to th
227
218
 
228
219
  This library does not do full validation of cron expressions and assumes the expression passed in is valid. If you need to validate an expression consider using a library like [cron-parser](https://www.npmjs.com/package/cron-parser). Example validation with cron-parser:
229
220
 
230
- ```
231
- const cronParser = require("cron-parser");
232
- const cronstrue = require("cronstrue");
221
+ ```javascript
222
+ import { CronExpressionParser } from "cron-parser";
223
+ import cronstrue from "cronstrue";
233
224
 
234
225
  const expression = "* * * * * *";
235
226
 
236
- // Validate expression first
237
- let isCronValid = true;
238
- try { cronParser.parseExpression(expression) } catch(e) { isCronValid = false; }
227
+ const isCronValid = (() => {
228
+ try {
229
+ CronExpressionParser.parse(expression);
230
+ return true;
231
+ } catch {
232
+ return false;
233
+ }
234
+ })();
239
235
 
240
- // If valid, then pass into cRonstrue
241
236
  if (isCronValid) {
242
- console.log(cronstrue.toString("* * * * *"));
237
+ console.log(cronstrue.toString(expression));
243
238
  }
244
239
  ```
245
240
 
246
241
  2. Can cRonstrue output the next occurrence of the cron expression?
247
242
 
248
- No, cRonstrue does not support this. This library simply describes a cron expression that is passed in.
243
+ No, cRonstrue does not support this. This library simply describes a cron expression that is passed in. You can do with with a library like [croner](https://www.npmjs.com/package/croner). Example:
244
+
245
+ ```javascript
246
+ import { Cron } from 'croner';
247
+ const job = new Cron('0 9 * * 1-5');
248
+ console.log(job.nextRun()); // next Date
249
+ console.log(job.nextRuns(5)); // next 5 Dates
250
+ ```
249
251
 
250
252
  ## Sponsors
251
253
 
@@ -287,13 +287,14 @@ var ExpressionDescriptor = (function () {
287
287
  }
288
288
  }
289
289
  ExpressionDescriptor.toString = function (expression, _a) {
290
- 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.logicalAndDayFields, logicalAndDayFields = _h === void 0 ? false : _h;
290
+ 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.trimHoursLeadingZero, trimHoursLeadingZero = _g === void 0 ? false : _g, _h = _b.locale, locale = _h === void 0 ? null : _h, _j = _b.logicalAndDayFields, logicalAndDayFields = _j === void 0 ? false : _j;
291
291
  var options = {
292
292
  throwExceptionOnParseError: throwExceptionOnParseError,
293
293
  verbose: verbose,
294
294
  dayOfWeekStartIndexZero: dayOfWeekStartIndexZero,
295
295
  monthStartIndexZero: monthStartIndexZero,
296
296
  use24HourTimeFormat: use24HourTimeFormat,
297
+ trimHoursLeadingZero: trimHoursLeadingZero,
297
298
  locale: locale,
298
299
  logicalAndDayFields: logicalAndDayFields,
299
300
  };
@@ -363,7 +364,9 @@ var ExpressionDescriptor = (function () {
363
364
  var hourParts = hourExpression.split(",");
364
365
  description += this.i18n.at();
365
366
  for (var i = 0; i < hourParts.length; i++) {
366
- description += " ";
367
+ if (description) {
368
+ description += " ";
369
+ }
367
370
  description += this.formatTime(hourParts[i], minuteExpression, "");
368
371
  if (i < hourParts.length - 2) {
369
372
  description += ",";
@@ -651,6 +654,7 @@ var ExpressionDescriptor = (function () {
651
654
  else if (doesExpressionContainMultipleValues) {
652
655
  var segments = expression.split(",");
653
656
  var descriptionContent = "";
657
+ var conjunction = this.i18n.spaceAnd();
654
658
  for (var i = 0; i < segments.length; i++) {
655
659
  if (i > 0 && segments.length > 2) {
656
660
  descriptionContent += ",";
@@ -659,7 +663,7 @@ var ExpressionDescriptor = (function () {
659
663
  }
660
664
  }
661
665
  if (i > 0 && segments.length > 1 && (i == segments.length - 1 || segments.length == 2)) {
662
- descriptionContent += "".concat(this.i18n.spaceAnd(), " ");
666
+ descriptionContent += conjunction == "," && segments.length > 2 ? " " : "".concat(conjunction, " ");
663
667
  }
664
668
  if (segments[i].indexOf("/") > -1 || segments[i].indexOf("-") > -1) {
665
669
  var isSegmentRangeWithoutIncrement = segments[i].indexOf("-") > -1 && segments[i].indexOf("/") == -1;
@@ -752,7 +756,12 @@ var ExpressionDescriptor = (function () {
752
756
  if (secondExpression) {
753
757
  second = ":".concat(("00" + secondExpression).substring(secondExpression.length));
754
758
  }
755
- 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 : "");
759
+ var hourStr = hour.toString();
760
+ var paddedHour = ("00" + hourStr).substring(hourStr.length);
761
+ var minuteStr = minute.toString();
762
+ var paddedMinute = ("00" + minuteStr).substring(minuteStr.length);
763
+ var displayHour = this.options.trimHoursLeadingZero ? hourStr : paddedHour;
764
+ return "".concat(setPeriodBeforeTime ? period : "").concat(displayHour, ":").concat(paddedMinute).concat(second).concat(!setPeriodBeforeTime ? period : "");
756
765
  };
757
766
  ExpressionDescriptor.prototype.transformVerbosity = function (description, useVerboseFormat) {
758
767
  if (!useVerboseFormat) {
@@ -785,7 +794,7 @@ exports.ExpressionDescriptor = ExpressionDescriptor;
785
794
 
786
795
 
787
796
  Object.defineProperty(exports, "__esModule", ({ value: true }));
788
- exports.sr = exports.hr = 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;
797
+ exports.sr = exports.hr = 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.nn = exports.nb = exports.nl = exports.ko = exports.id = exports.it = exports.fr = exports.es = exports.de = exports.da = exports.en = void 0;
789
798
  var en_1 = __webpack_require__(486);
790
799
  Object.defineProperty(exports, "en", ({ enumerable: true, get: function () { return en_1.en; } }));
791
800
  var da_1 = __webpack_require__(506);
@@ -806,6 +815,8 @@ var nl_1 = __webpack_require__(647);
806
815
  Object.defineProperty(exports, "nl", ({ enumerable: true, get: function () { return nl_1.nl; } }));
807
816
  var nb_1 = __webpack_require__(957);
808
817
  Object.defineProperty(exports, "nb", ({ enumerable: true, get: function () { return nb_1.nb; } }));
818
+ var nn_1 = __webpack_require__(633);
819
+ Object.defineProperty(exports, "nn", ({ enumerable: true, get: function () { return nn_1.nn; } }));
809
820
  var sv_1 = __webpack_require__(544);
810
821
  Object.defineProperty(exports, "sv", ({ enumerable: true, get: function () { return sv_1.sv; } }));
811
822
  var pl_1 = __webpack_require__(905);
@@ -4541,16 +4552,16 @@ var ko = (function () {
4541
4552
  return "1시간마다";
4542
4553
  };
4543
4554
  ko.prototype.atSpace = function () {
4544
- return "시간 ";
4555
+ return "";
4545
4556
  };
4546
4557
  ko.prototype.everyMinuteBetweenX0AndX1 = function () {
4547
4558
  return "매분 %s~%s";
4548
4559
  };
4549
4560
  ko.prototype.at = function () {
4550
- return "시간";
4561
+ return "";
4551
4562
  };
4552
4563
  ko.prototype.spaceAnd = function () {
4553
- return "";
4564
+ return ",";
4554
4565
  };
4555
4566
  ko.prototype.everySecond = function () {
4556
4567
  return "1초마다";
@@ -4577,7 +4588,7 @@ var ko = (function () {
4577
4588
  return "%s시간마다";
4578
4589
  };
4579
4590
  ko.prototype.betweenX0AndX1 = function () {
4580
- return "%s에서 %s 사이";
4591
+ return "%s부터 %s까지";
4581
4592
  };
4582
4593
  ko.prototype.atX0 = function () {
4583
4594
  return "%s에서";
@@ -4589,10 +4600,10 @@ var ko = (function () {
4589
4600
  return ", 주 중 %s일마다";
4590
4601
  };
4591
4602
  ko.prototype.commaX0ThroughX1 = function () {
4592
- return ", %s에서 %s까지";
4603
+ return ", %s부터 %s까지";
4593
4604
  };
4594
4605
  ko.prototype.commaAndX0ThroughX1 = function () {
4595
- return ", %s에서 %s까지";
4606
+ return ", %s부터 %s까지";
4596
4607
  };
4597
4608
  ko.prototype.first = function () {
4598
4609
  return "첫 번째";
@@ -4625,7 +4636,7 @@ var ko = (function () {
4625
4636
  return ", %s에만";
4626
4637
  };
4627
4638
  ko.prototype.commaAndOnX0 = function () {
4628
- return ", %s에";
4639
+ return ", %s에";
4629
4640
  };
4630
4641
  ko.prototype.commaEveryX0Months = function () {
4631
4642
  return ", %s개월마다";
@@ -5253,6 +5264,194 @@ var nl = (function () {
5253
5264
  exports.nl = nl;
5254
5265
 
5255
5266
 
5267
+ /***/ },
5268
+
5269
+ /***/ 633
5270
+ (__unused_webpack_module, exports) {
5271
+
5272
+
5273
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
5274
+ exports.nn = void 0;
5275
+ var nn = (function () {
5276
+ function nn() {
5277
+ }
5278
+ nn.prototype.atX0SecondsPastTheMinuteGt20 = function () {
5279
+ return null;
5280
+ };
5281
+ nn.prototype.atX0MinutesPastTheHourGt20 = function () {
5282
+ return null;
5283
+ };
5284
+ nn.prototype.commaMonthX0ThroughMonthX1 = function () {
5285
+ return null;
5286
+ };
5287
+ nn.prototype.commaYearX0ThroughYearX1 = function () {
5288
+ return null;
5289
+ };
5290
+ nn.prototype.use24HourTimeFormatByDefault = function () {
5291
+ return true;
5292
+ };
5293
+ nn.prototype.anErrorOccuredWhenGeneratingTheExpressionD = function () {
5294
+ return "Ein feil oppstod ved generering av uttrykksskildring. Sjekk cron-syntaksen.";
5295
+ };
5296
+ nn.prototype.at = function () {
5297
+ return "Kl.";
5298
+ };
5299
+ nn.prototype.atSpace = function () {
5300
+ return "Kl.";
5301
+ };
5302
+ nn.prototype.atX0 = function () {
5303
+ return "på %s";
5304
+ };
5305
+ nn.prototype.atX0MinutesPastTheHour = function () {
5306
+ return "på %s minutt etter timen";
5307
+ };
5308
+ nn.prototype.atX0SecondsPastTheMinute = function () {
5309
+ return "på %s sekund etter minuttet";
5310
+ };
5311
+ nn.prototype.betweenX0AndX1 = function () {
5312
+ return "mellom %s og %s";
5313
+ };
5314
+ nn.prototype.commaBetweenDayX0AndX1OfTheMonth = function () {
5315
+ return ", mellom dag %s og %s av månaden";
5316
+ };
5317
+ nn.prototype.commaEveryDay = function () {
5318
+ return ", kvar dag";
5319
+ };
5320
+ nn.prototype.commaEveryX0Days = function () {
5321
+ return ", kvar %s dag";
5322
+ };
5323
+ nn.prototype.commaEveryX0DaysOfTheWeek = function () {
5324
+ return ", kvar %s vekedag";
5325
+ };
5326
+ nn.prototype.commaEveryX0Months = function () {
5327
+ return ", kvar %s månad";
5328
+ };
5329
+ nn.prototype.commaEveryX0Years = function () {
5330
+ return ", kvart %s år";
5331
+ };
5332
+ nn.prototype.commaOnDayX0OfTheMonth = function () {
5333
+ return ", på dag %s av månaden";
5334
+ };
5335
+ nn.prototype.commaOnlyInX0 = function () {
5336
+ return ", berre i %s";
5337
+ };
5338
+ nn.prototype.commaOnlyOnX0 = function () {
5339
+ return ", på %s";
5340
+ };
5341
+ nn.prototype.commaAndOnX0 = function () {
5342
+ return ", og på %s";
5343
+ };
5344
+ nn.prototype.commaOnThe = function () {
5345
+ return ", på ";
5346
+ };
5347
+ nn.prototype.commaOnTheLastDayOfTheMonth = function () {
5348
+ return ", på den siste dagen i månaden";
5349
+ };
5350
+ nn.prototype.commaOnTheLastWeekdayOfTheMonth = function () {
5351
+ return ", den siste vekedagen i månaden";
5352
+ };
5353
+ nn.prototype.commaDaysBeforeTheLastDayOfTheMonth = function () {
5354
+ return ", %s dagar før den siste dagen i månaden";
5355
+ };
5356
+ nn.prototype.commaOnTheLastX0OfTheMonth = function () {
5357
+ return ", på den siste %s av månaden";
5358
+ };
5359
+ nn.prototype.commaOnTheX0OfTheMonth = function () {
5360
+ return ", på den %s av månaden";
5361
+ };
5362
+ nn.prototype.commaX0ThroughX1 = function () {
5363
+ return ", %s til og med %s";
5364
+ };
5365
+ nn.prototype.commaAndX0ThroughX1 = function () {
5366
+ return ", og %s til og med %s";
5367
+ };
5368
+ nn.prototype.everyHour = function () {
5369
+ return "kvar time";
5370
+ };
5371
+ nn.prototype.everyMinute = function () {
5372
+ return "kvart minutt";
5373
+ };
5374
+ nn.prototype.everyMinuteBetweenX0AndX1 = function () {
5375
+ return "Kvart minutt mellom %s og %s";
5376
+ };
5377
+ nn.prototype.everySecond = function () {
5378
+ return "kvart sekund";
5379
+ };
5380
+ nn.prototype.everyX0Hours = function () {
5381
+ return "kvar %s time";
5382
+ };
5383
+ nn.prototype.everyX0Minutes = function () {
5384
+ return "kvart %s minutt";
5385
+ };
5386
+ nn.prototype.everyX0Seconds = function () {
5387
+ return "kvart %s sekund";
5388
+ };
5389
+ nn.prototype.fifth = function () {
5390
+ return "femte";
5391
+ };
5392
+ nn.prototype.first = function () {
5393
+ return "første";
5394
+ };
5395
+ nn.prototype.firstWeekday = function () {
5396
+ return "første vekedag";
5397
+ };
5398
+ nn.prototype.fourth = function () {
5399
+ return "fjerde";
5400
+ };
5401
+ nn.prototype.minutesX0ThroughX1PastTheHour = function () {
5402
+ return "minutta frå %s til og med %s etter timen";
5403
+ };
5404
+ nn.prototype.second = function () {
5405
+ return "andre";
5406
+ };
5407
+ nn.prototype.secondsX0ThroughX1PastTheMinute = function () {
5408
+ return "sekunda frå %s til og med %s etter minuttet";
5409
+ };
5410
+ nn.prototype.spaceAnd = function () {
5411
+ return " og";
5412
+ };
5413
+ nn.prototype.spaceX0OfTheMonth = function () {
5414
+ return " %s i månaden";
5415
+ };
5416
+ nn.prototype.lastDay = function () {
5417
+ return "den siste dagen";
5418
+ };
5419
+ nn.prototype.third = function () {
5420
+ return "tredje";
5421
+ };
5422
+ nn.prototype.weekdayNearestDayX0 = function () {
5423
+ return "vekedag nærmast dag %s";
5424
+ };
5425
+ nn.prototype.commaStartingX0 = function () {
5426
+ return ", startar %s";
5427
+ };
5428
+ nn.prototype.daysOfTheWeek = function () {
5429
+ return ["sundag", "måndag", "tysdag", "onsdag", "torsdag", "fredag", "laurdag"];
5430
+ };
5431
+ nn.prototype.monthsOfTheYear = function () {
5432
+ return [
5433
+ "januar",
5434
+ "februar",
5435
+ "mars",
5436
+ "april",
5437
+ "mai",
5438
+ "juni",
5439
+ "juli",
5440
+ "august",
5441
+ "september",
5442
+ "oktober",
5443
+ "november",
5444
+ "desember",
5445
+ ];
5446
+ };
5447
+ nn.prototype.onTheHour = function () {
5448
+ return "på timen";
5449
+ };
5450
+ return nn;
5451
+ }());
5452
+ exports.nn = nn;
5453
+
5454
+
5256
5455
  /***/ },
5257
5456
 
5258
5457
  /***/ 905