cronstrue 2.2.0 → 2.5.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.
Files changed (64) hide show
  1. package/README.md +36 -19
  2. package/dist/cronstrue-i18n.js +7 -1
  3. package/dist/cronstrue-i18n.min.js +1 -1
  4. package/dist/cronstrue.js +7 -1
  5. package/dist/cronstrue.min.js +1 -1
  6. package/locales/be.js +287 -1
  7. package/locales/be.min.js +1 -1
  8. package/locales/ca.js +287 -1
  9. package/locales/ca.min.js +1 -1
  10. package/locales/cs.js +287 -1
  11. package/locales/cs.min.js +1 -1
  12. package/locales/da.js +287 -1
  13. package/locales/da.min.js +1 -1
  14. package/locales/de.js +287 -1
  15. package/locales/de.min.js +1 -1
  16. package/locales/en.js +290 -1
  17. package/locales/en.min.js +1 -1
  18. package/locales/es.js +287 -1
  19. package/locales/es.min.js +1 -1
  20. package/locales/fa.js +280 -1
  21. package/locales/fa.min.js +1 -1
  22. package/locales/fi.js +296 -1
  23. package/locales/fi.min.js +1 -1
  24. package/locales/fr.js +290 -1
  25. package/locales/fr.min.js +1 -1
  26. package/locales/he.js +274 -1
  27. package/locales/he.min.js +1 -1
  28. package/locales/id.js +290 -1
  29. package/locales/id.min.js +1 -1
  30. package/locales/it.js +287 -1
  31. package/locales/it.min.js +1 -1
  32. package/locales/ja.js +289 -1
  33. package/locales/ja.min.js +1 -1
  34. package/locales/ko.js +289 -1
  35. package/locales/ko.min.js +1 -1
  36. package/locales/nb.js +287 -1
  37. package/locales/nb.min.js +1 -1
  38. package/locales/nl.js +287 -1
  39. package/locales/nl.min.js +1 -1
  40. package/locales/pl.js +287 -1
  41. package/locales/pl.min.js +1 -1
  42. package/locales/pt_BR.js +287 -1
  43. package/locales/pt_BR.min.js +1 -1
  44. package/locales/ro.js +287 -1
  45. package/locales/ro.min.js +1 -1
  46. package/locales/ru.js +287 -1
  47. package/locales/ru.min.js +1 -1
  48. package/locales/sk.js +287 -1
  49. package/locales/sk.min.js +1 -1
  50. package/locales/sl.js +287 -1
  51. package/locales/sl.min.js +1 -1
  52. package/locales/sv.js +287 -1
  53. package/locales/sv.min.js +1 -1
  54. package/locales/sw.js +288 -1
  55. package/locales/sw.min.js +1 -1
  56. package/locales/tr.js +287 -1
  57. package/locales/tr.min.js +1 -1
  58. package/locales/uk.js +287 -1
  59. package/locales/uk.min.js +1 -1
  60. package/locales/zh_CN.js +292 -1
  61. package/locales/zh_CN.min.js +1 -1
  62. package/locales/zh_TW.js +283 -1
  63. package/locales/zh_TW.min.js +1 -1
  64. package/package.json +1 -1
package/README.md CHANGED
@@ -26,10 +26,10 @@ npm install cronstrue
26
26
 
27
27
  Then, depending upon your usage context, add a reference to it:
28
28
 
29
- ### Node
29
+ ### Node / CommonJS
30
30
 
31
31
  ```js
32
- var cronstrue = require('cronstrue');
32
+ const cronstrue = require('cronstrue');
33
33
  ```
34
34
 
35
35
  ### ESM / webpack / TypeScript
@@ -57,7 +57,7 @@ A simple way to load the library in a browser is by using the [unpkg](https://un
57
57
  <script src="https://unpkg.com/cronstrue@latest/dist/cronstrue.min.js" async></script>
58
58
  ```
59
59
 
60
- Using the "latest" tag will result in a 302 redirect to the latest version tag so it is highly recommended to use a specific version tag such as https://unpkg.com/cronstrue@1.48.0/dist/cronstrue.min.js to avoid this redirect.
60
+ Using the "latest" tag will result in a 302 redirect to the latest version tag so it is recommended to use a specific version tag such as https://unpkg.com/cronstrue@1.48.0/dist/cronstrue.min.js to avoid this redirect.
61
61
 
62
62
  ## Usage
63
63
 
@@ -99,31 +99,48 @@ An options object can be passed as the second parameter to `cronstrue.toString`.
99
99
 
100
100
  ## i18n
101
101
 
102
- To use the i18n support cRonstrue provides, you can import a specific locale and then call `toString()`. For example, for the es (Spanish) locale:
102
+ To use the i18n support cRonstrue provides, you can either import all the supported locales at once (using `cronstrue/i18n`) or import individual locales (using `cronstrue/locales/[locale]`). Then, when calling `toString` you pass in the name of the locale you want to use. For example, for the es (Spanish) locale, you would use: `cronstrue.toString("* * * * *", { locale: "es" })`.
103
+
104
+ ### All Locales
105
+
106
+ You can import all locales at once with `cronstrue/i18n`. This approach has the advantage of only having to load one module and having access to all supported locales. The tradeoff with this approach is a larger module (~130k, minified) that will take longer to load, particularly when sending down to a browser.
103
107
 
104
108
  ```js
105
- import cronstrue from 'cronstrue/locales/es';
106
- cronstrue.toString("*/5 * * * *");
107
- ```
109
+ // Node / CommonJS
110
+ const cronstrue = require('cronstrue/i18n');
108
111
 
109
- ### Browser
112
+ // ESM / webpack / TypeScript
113
+ import cronstrue from 'cronstrue/i18n';
110
114
 
111
- A locale file from the `/locales` folder in the npm package should be served to the browser.
115
+ // Browser
116
+ <script src="https://unpkg.com/cronstrue@latest/cronstrue-i18n.min.js" async></script>
112
117
 
113
- ```html
114
- <script src="https://unpkg.com/cronstrue@latest/locales/es.min.js" async></script>
115
- <script>
116
- cronstrue.toString("*/5 * * * *");
117
- </script>
118
+ cronstrue.toString("*/5 * * * *", { locale: "fr" }); // => Toutes les 5 minutes
119
+ cronstrue.toString("*/5 * * * *", { locale: "es" }); // => Cada 5 minutos
118
120
  ```
119
121
 
120
- ### All Locales
122
+ ### Individual Locales
121
123
 
122
- Alternatively you can import all locales and then pass in the `locale` option:
124
+ You can also load the main cronstrue module and then load individual locale modules you want to have access to. This works well when you have one or more locales you know you need access to and want to minimize load time, particularly when sending down to a browser. The main cronstrue module is about 42k (minified) and each locale is about 4k (minified) in size.
123
125
 
124
126
  ```js
125
- import cronstrue from 'cronstrue/i18n';
126
- cronstrue.toString("*/5 * * * *", { locale: "es" });
127
+ // Node / CommonJS
128
+ const cronstrue = require('cronstrue');
129
+ require('cronstrue/locales/fr');
130
+ require('cronstrue/locales/es');
131
+
132
+ // ESM / webpack / TypeScript
133
+ import cronstrue from 'cronstrue';
134
+ import 'cronstrue/locales/fr';
135
+ import 'cronstrue/locales/es';
136
+
137
+ // Browser
138
+ <script src="https://unpkg.com/cronstrue@latest/cronstrue.min.js" async></script>
139
+ <script src="https://unpkg.com/cronstrue@latest/locales/fr.min.js" async></script>
140
+ <script src="https://unpkg.com/cronstrue@latest/locales/es.min.js" async></script>
141
+
142
+ cronstrue.toString("*/5 * * * *", { locale: "fr" }); // => Toutes les 5 minutes
143
+ cronstrue.toString("*/5 * * * *", { locale: "es" }); // => Cada 5 minutos
127
144
  ```
128
145
 
129
146
  ## Frequently Asked Questions
@@ -134,7 +151,7 @@ This library does not do full validation of cron expressions and assumes the exp
134
151
 
135
152
  > Can cRonstrue output the next occurrence of the cron expression?
136
153
 
137
- No, cRonstrue does not support this. It simply describes a cron expression. You could use another library to get the next occurrence of a cron expression and then pass that expression into cRonstrue, to achieve this.
154
+ No, cRonstrue does not support this. This library simply describes a cron expression that is passed in.
138
155
 
139
156
  ### Supported Locales
140
157
 
@@ -386,6 +386,13 @@ var ExpressionDescriptor = (function () {
386
386
  }, function (s) {
387
387
  return _this.i18n.atX0();
388
388
  });
389
+ if (description && expression.includes("-") && this.expressionParts[1] != "0") {
390
+ var atTheHourMatches = Array.from(description.matchAll(/:00/g));
391
+ if (atTheHourMatches.length > 1) {
392
+ var lastAtTheHourMatchIndex = atTheHourMatches[atTheHourMatches.length - 1].index;
393
+ description = description.substring(0, lastAtTheHourMatchIndex) + ":59" + description.substring(lastAtTheHourMatchIndex + 3);
394
+ }
395
+ }
389
396
  return description;
390
397
  };
391
398
  ExpressionDescriptor.prototype.getDayOfWeekDescription = function () {
@@ -609,7 +616,6 @@ var ExpressionDescriptor = (function () {
609
616
  var rangeSegments = rangeExpression.split("-");
610
617
  var rangeSegment1Description = getSingleItemDescription(rangeSegments[0]);
611
618
  var rangeSegment2Description = getSingleItemDescription(rangeSegments[1]);
612
- rangeSegment2Description = rangeSegment2Description.replace(":00", ":59");
613
619
  var rangeDescriptionFormat = getRangeDescriptionFormat(rangeExpression);
614
620
  description += stringUtilities_1.StringUtilities.format(rangeDescriptionFormat, rangeSegment1Description, rangeSegment2Description);
615
621
  return description;