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.
- package/README.md +36 -19
- package/dist/cronstrue-i18n.js +7 -1
- package/dist/cronstrue-i18n.min.js +1 -1
- package/dist/cronstrue.js +7 -1
- package/dist/cronstrue.min.js +1 -1
- package/locales/be.js +287 -1
- package/locales/be.min.js +1 -1
- package/locales/ca.js +287 -1
- package/locales/ca.min.js +1 -1
- package/locales/cs.js +287 -1
- package/locales/cs.min.js +1 -1
- package/locales/da.js +287 -1
- package/locales/da.min.js +1 -1
- package/locales/de.js +287 -1
- package/locales/de.min.js +1 -1
- package/locales/en.js +290 -1
- package/locales/en.min.js +1 -1
- package/locales/es.js +287 -1
- package/locales/es.min.js +1 -1
- package/locales/fa.js +280 -1
- package/locales/fa.min.js +1 -1
- package/locales/fi.js +296 -1
- package/locales/fi.min.js +1 -1
- package/locales/fr.js +290 -1
- package/locales/fr.min.js +1 -1
- package/locales/he.js +274 -1
- package/locales/he.min.js +1 -1
- package/locales/id.js +290 -1
- package/locales/id.min.js +1 -1
- package/locales/it.js +287 -1
- package/locales/it.min.js +1 -1
- package/locales/ja.js +289 -1
- package/locales/ja.min.js +1 -1
- package/locales/ko.js +289 -1
- package/locales/ko.min.js +1 -1
- package/locales/nb.js +287 -1
- package/locales/nb.min.js +1 -1
- package/locales/nl.js +287 -1
- package/locales/nl.min.js +1 -1
- package/locales/pl.js +287 -1
- package/locales/pl.min.js +1 -1
- package/locales/pt_BR.js +287 -1
- package/locales/pt_BR.min.js +1 -1
- package/locales/ro.js +287 -1
- package/locales/ro.min.js +1 -1
- package/locales/ru.js +287 -1
- package/locales/ru.min.js +1 -1
- package/locales/sk.js +287 -1
- package/locales/sk.min.js +1 -1
- package/locales/sl.js +287 -1
- package/locales/sl.min.js +1 -1
- package/locales/sv.js +287 -1
- package/locales/sv.min.js +1 -1
- package/locales/sw.js +288 -1
- package/locales/sw.min.js +1 -1
- package/locales/tr.js +287 -1
- package/locales/tr.min.js +1 -1
- package/locales/uk.js +287 -1
- package/locales/uk.min.js +1 -1
- package/locales/zh_CN.js +292 -1
- package/locales/zh_CN.min.js +1 -1
- package/locales/zh_TW.js +283 -1
- package/locales/zh_TW.min.js +1 -1
- 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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
106
|
-
cronstrue
|
|
107
|
-
```
|
|
109
|
+
// Node / CommonJS
|
|
110
|
+
const cronstrue = require('cronstrue/i18n');
|
|
108
111
|
|
|
109
|
-
|
|
112
|
+
// ESM / webpack / TypeScript
|
|
113
|
+
import cronstrue from 'cronstrue/i18n';
|
|
110
114
|
|
|
111
|
-
|
|
115
|
+
// Browser
|
|
116
|
+
<script src="https://unpkg.com/cronstrue@latest/cronstrue-i18n.min.js" async></script>
|
|
112
117
|
|
|
113
|
-
|
|
114
|
-
|
|
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
|
-
###
|
|
122
|
+
### Individual Locales
|
|
121
123
|
|
|
122
|
-
|
|
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
|
-
|
|
126
|
-
cronstrue
|
|
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.
|
|
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
|
|
package/dist/cronstrue-i18n.js
CHANGED
|
@@ -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;
|