@iobroker/adapter-react-v5 6.0.19 → 6.1.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.
@@ -1,492 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /**
4
- * Given a cronSpec, return the human-readable string.
5
- */
6
- function cronToText(cronSpec, withSeconds, locale) {
7
- // Constant array to convert valid names to values
8
- const NAMES = {
9
- JAN: 1,
10
- FEB: 2,
11
- MAR: 3,
12
- APR: 4,
13
- MAY: 5,
14
- JUN: 6,
15
- JUL: 7,
16
- AUG: 8,
17
- SEP: 9,
18
- OCT: 10,
19
- NOV: 11,
20
- DEC: 12,
21
- SUN: 1,
22
- MON: 2,
23
- TUE: 3,
24
- WED: 4,
25
- THU: 5,
26
- FRI: 6,
27
- SAT: 7,
28
- };
29
- // Parsable replacements for common expressions
30
- const REPLACEMENTS = {
31
- '* * * * * *': '0/1 * * * * *',
32
- '@YEARLY': '0 0 1 1 *',
33
- '@ANNUALLY': '0 0 1 1 *',
34
- '@MONTHLY': '0 0 1 * *',
35
- '@WEEKLY': '0 0 * * 0',
36
- '@DAILY': '0 0 * * *',
37
- '@HOURLY': '0 * * * *',
38
- };
39
- // Contains the index, min, and max for each of the constraints
40
- const FIELDS = {
41
- s: [0, 0, 59], // seconds
42
- m: [1, 0, 59], // minutes
43
- h: [2, 0, 23], // hours
44
- D: [3, 1, 31], // day of month
45
- M: [4, 1, 12], // month
46
- Y: [6, 1970, 2099], // year
47
- d: [5, 1, 7, 1], // day of the week
48
- };
49
- /**
50
- * Returns the value + offset if value is a number, otherwise it
51
- * attempts to look up the value in the NAMES table and returns
52
- * that result instead.
53
- */
54
- function getValue(
55
- /** the value that should be parsed */
56
- value,
57
- /** Any offset that must be added to the value */
58
- offset = 0, max = 9999) {
59
- return Number.isNaN(value) ? NAMES[value] || null : Math.min(+value + offset, max);
60
- }
61
- /**
62
- * Returns a deep clone of a schedule skipping any day of week
63
- * constraints.
64
- */
65
- function cloneSchedule(
66
- /** The schedule that will be cloned */
67
- sched) {
68
- const clone = {};
69
- let field;
70
- for (field in sched) {
71
- if (field !== 'dc' && field !== 'd') {
72
- clone[field] = sched[field].slice(0);
73
- }
74
- }
75
- return clone;
76
- }
77
- /**
78
- * Adds values to the specified constraint in the current schedule.
79
- */
80
- function add(
81
- /** The schedule to add the constraint to */
82
- sched,
83
- /** The name of the constraint to add */
84
- name,
85
- /** The minimum value for this constraint */
86
- min,
87
- /** The maximum value for this constraint */
88
- max,
89
- /** The increment value for this constraint */
90
- inc = 0) {
91
- let i = min;
92
- if (!sched[name]) {
93
- sched[name] = [];
94
- }
95
- while (i <= max) {
96
- if (sched[name].indexOf(i) < 0) {
97
- sched[name].push(i);
98
- }
99
- i += inc || 1;
100
- }
101
- sched[name].sort((a, b) => a - b);
102
- }
103
- /**
104
- * Adds a hash item (of the form x#y or xL) to the schedule.
105
- */
106
- function addHash(
107
- /** The current set of schedules */
108
- schedules,
109
- /** The current schedule to add to */
110
- curSched,
111
- /** The value to add (x of x#y or xL) */
112
- value,
113
- /** The hash value to add (y of x#y) */
114
- hash) {
115
- // if there are any existing days of week constraints that
116
- // aren't equal to the one we're adding, create a new
117
- // composite schedule
118
- if ((curSched.d && !curSched.dc) || (curSched.dc && !curSched.dc.includes(hash))) {
119
- schedules.push(cloneSchedule(curSched));
120
- curSched = schedules[schedules.length - 1];
121
- }
122
- add(curSched, 'd', value, value);
123
- add(curSched, 'dc', hash, hash);
124
- }
125
- function addWeekday(
126
- /** The existing set of schedules */
127
- s,
128
- /** The current schedule to add to */
129
- curSched, value) {
130
- const except1 = {};
131
- const except2 = {};
132
- if (value === 1) {
133
- // cron doesn't pass month boundaries, so if 1st is a
134
- // weekend then we need to use 2nd or 3rd instead
135
- add(curSched, 'D', 1, 3);
136
- add(curSched, 'd', NAMES.MON, NAMES.FRI);
137
- add(except1, 'D', 2, 2);
138
- add(except1, 'd', NAMES.TUE, NAMES.FRI);
139
- add(except2, 'D', 3, 3);
140
- add(except2, 'd', NAMES.TUE, NAMES.FRI);
141
- }
142
- else {
143
- // normally you want the closest day, so if v is a
144
- // Saturday, use the previous Friday. If it's a
145
- // sunday, use the following Monday.
146
- add(curSched, 'D', value - 1, value + 1);
147
- add(curSched, 'd', NAMES.MON, NAMES.FRI);
148
- add(except1, 'D', value - 1, value - 1);
149
- add(except1, 'd', NAMES.MON, NAMES.THU);
150
- add(except2, 'D', value + 1, value + 1);
151
- add(except2, 'd', NAMES.TUE, NAMES.FRI);
152
- }
153
- s.exceptions.push(except1);
154
- s.exceptions.push(except2);
155
- }
156
- /**
157
- * Adds a range item (of the form x-y/z) to the schedule.
158
- */
159
- function addRange(
160
- /** The cron expression item to add */
161
- item,
162
- /** The current schedule to add to */
163
- curSched,
164
- /** The name to use for this constraint */
165
- name,
166
- /** The min value for the constraint */
167
- min,
168
- /** The max value for the constraint */
169
- max,
170
- /** The offset to apply to the cron value */
171
- offset) {
172
- // parse range/x
173
- const incSplit = item.split('/');
174
- const inc = +incSplit[1];
175
- const range = incSplit[0];
176
- // parse x-y or * or 0
177
- if (range !== '*' && range !== '0') {
178
- const rangeSplit = range.split('-');
179
- min = getValue(rangeSplit[0], offset, max) || offset;
180
- // fix for issue #13, range may be a single digit
181
- max = getValue(rangeSplit[1], offset, max) || max;
182
- }
183
- add(curSched, name, min, max, inc);
184
- }
185
- /**
186
- * Parses a particular item within a cron expression.
187
- */
188
- function parse(
189
- /** The cron expression item to parse */
190
- item,
191
- /** The existing set of schedules */
192
- s,
193
- /** The name to use for this constraint */
194
- name,
195
- /** The min value for the constraint */
196
- min,
197
- /** The max value for the constraint */
198
- max,
199
- /** The offset to apply to the cron value */
200
- offset) {
201
- let value;
202
- let split;
203
- const schedules = s.schedules;
204
- const curSched = schedules[schedules.length - 1];
205
- // L just means min - 1 (this also makes it work for any field)
206
- if (item === 'L') {
207
- item = (min - 1).toString(10);
208
- }
209
- // parse x
210
- value = getValue(item, offset, max);
211
- if (value !== null) {
212
- add(curSched, name, value, value);
213
- }
214
- else if ((value = getValue(item.replace('W', ''), offset, max)) !== null) {
215
- // parse xW
216
- addWeekday(s, curSched, value);
217
- }
218
- else if ((value = getValue(item.replace('L', ''), offset, max)) !== null) {
219
- // parse xL
220
- addHash(schedules, curSched, value, min - 1);
221
- }
222
- else if ((split = item.split('#')).length === 2) {
223
- // parse x#y
224
- value = getValue(split[0], offset, max) || offset;
225
- addHash(schedules, curSched, value, getValue(split[1]) || 0);
226
- }
227
- else {
228
- // parse x-y or x-y/z or */z or 0/z
229
- addRange(item, curSched, name, min, max, offset);
230
- }
231
- }
232
- /**
233
- * Returns true if the item is either of the form x#y or xL.
234
- */
235
- function isHash(
236
- /** The expression item to check */
237
- item) {
238
- return item.includes('#') || item.indexOf('L') > 0;
239
- }
240
- function itemSorter(a, b) {
241
- return isHash(a) && !isHash(b) ? 1 : (a > b ? 1 : (a < b ? -1 : 0));
242
- }
243
- /**
244
- * Parses each of the fields in a cron expression. The expression must
245
- * include the second's field, the year field is optional.
246
- *
247
- */
248
- function parseExpr(
249
- /** The cron expression to parse */
250
- expr) {
251
- const schedule = { schedules: [{}], exceptions: [] };
252
- const components = expr.replace(/(\s)+/g, ' ').split(' ');
253
- let field;
254
- let f;
255
- let component;
256
- let items;
257
- for (field in FIELDS) {
258
- f = FIELDS[field];
259
- component = components[f[0]];
260
- if (component && component !== '*' && component !== '?') {
261
- // need to sort so that any #'s come last, otherwise
262
- // schedule clones to handle # won't contain all of the
263
- // other constraints
264
- items = component.split(',').sort(itemSorter);
265
- let i;
266
- const length = items.length;
267
- for (i = 0; i < length; i++) {
268
- parse(items[i], schedule, field, f[1], f[2], f[3]);
269
- }
270
- }
271
- }
272
- return schedule;
273
- }
274
- /**
275
- * Make cron expression parsable.
276
- */
277
- function prepareExpr(
278
- /** The cron expression to prepare */
279
- expr) {
280
- const prepared = expr.toUpperCase();
281
- return REPLACEMENTS[prepared] || prepared;
282
- }
283
- function parseCron(expr, hasSeconds) {
284
- const e = prepareExpr(expr);
285
- return parseExpr(hasSeconds ? e : `0 ${e}`);
286
- }
287
- const schedule = parseCron(cronSpec, withSeconds);
288
- function absFloor(number) {
289
- if (number < 0) {
290
- return Math.ceil(number);
291
- }
292
- return Math.floor(number);
293
- }
294
- function toInt(argumentForCoercion) {
295
- const coercedNumber = +argumentForCoercion;
296
- let value = 0;
297
- if (coercedNumber !== 0 && isFinite(coercedNumber)) {
298
- value = absFloor(coercedNumber);
299
- }
300
- return value;
301
- }
302
- function ordinal(number) {
303
- const b = number % 10;
304
- const output = (toInt((number % 100) / 10) === 1) ? locale.ORDINALS.th :
305
- b === 1 ? locale.ORDINALS.st :
306
- b === 2 ? locale.ORDINALS.nd :
307
- b === 3 ? locale.ORDINALS.rd : locale.ORDINALS.th;
308
- return number + output;
309
- }
310
- /**
311
- * For an array of numbers, e.g., a list of hours in a schedule,
312
- * return a string listing out all of the values (complete with
313
- * "and" plus ordinal text on the last item).
314
- */
315
- function numberList(numbers) {
316
- if (numbers.length < 2) {
317
- return ordinal(numbers[0]);
318
- }
319
- const lastVal = numbers.pop() || 0;
320
- return `${numbers.join(', ')} ${locale.and} ${ordinal(lastVal)}`;
321
- }
322
- /**
323
- * Parse a number into day of week, or a month name;
324
- * used in dateList below.
325
- * @param {Number|String} value
326
- * @param {String} type
327
- * @returns {String}
328
- */
329
- function numberToDateName(value, type) {
330
- if (type === 'dow') {
331
- return locale.DOW[value - 1];
332
- }
333
- if (type === 'mon') {
334
- return locale.MONTH[value - 1];
335
- }
336
- return value;
337
- }
338
- /**
339
- * From an array of numbers corresponding to dates (given in type: either
340
- * days of the week, or months), return a string listing all the values.
341
- * @param {Number[]} numbers
342
- * @param {String} type
343
- * @returns {String}
344
- */
345
- function dateList(numbers, type) {
346
- if (numbers.length < 2) {
347
- return numberToDateName(numbers[0], type);
348
- }
349
- const lastVal = numbers.pop() || 0;
350
- let outputText = '';
351
- for (let i = 0, value; numbers[i]; i++) {
352
- value = numbers[i];
353
- if (outputText.length > 0) {
354
- outputText += ', ';
355
- }
356
- outputText += numberToDateName(value, type);
357
- }
358
- return `${outputText} ${locale.and} ${numberToDateName(lastVal, type)}`;
359
- }
360
- /**
361
- * Pad to the equivalent of sprintf('%02d').
362
- * @param {Number} x
363
- * @returns {string}
364
- */
365
- function zeroPad(x) {
366
- return x < 10 ? `0${x}` : x.toString();
367
- }
368
- //----------------
369
- /**
370
- * Given a schedule, generate a friendly sentence description.
371
- */
372
- function scheduleToSentence(_schedule, _withSeconds) {
373
- let outputText = `${locale.Every} `;
374
- if (_schedule.h && _schedule.m && _schedule.h.length <= 2 && _schedule.m.length <= 2 && _withSeconds && _schedule.s && _schedule.s.length <= 2) {
375
- // If there are only one or two specified values for
376
- // hour or minute, print them in HH:MM:SS format
377
- const hm = [];
378
- for (let i = 0; i < _schedule.h.length; i++) {
379
- for (let j = 0; j < _schedule.m.length; j++) {
380
- for (let k = 0; k < _schedule.s.length; k++) {
381
- hm.push(`${zeroPad(_schedule.h[i])}:${zeroPad(_schedule.m[j])}:${zeroPad(_schedule.s[k])}`);
382
- }
383
- }
384
- }
385
- if (hm.length < 2) {
386
- outputText = `${locale.At} ${hm[0]}`;
387
- }
388
- else {
389
- const lastVal = hm.pop();
390
- outputText = `${locale.At} ${hm.join(', ')} ${locale.and} ${lastVal}`;
391
- }
392
- if (!_schedule.d && !_schedule.D) {
393
- outputText += ` ${locale['every day']} `;
394
- }
395
- }
396
- else if (_schedule.h && _schedule.m && _schedule.h.length <= 2 && _schedule.m.length <= 2) {
397
- // If there are only one or two specified values for
398
- // hour or minute, print them in HH:MM format
399
- const hm = [];
400
- for (let i = 0; i < _schedule.h.length; i++) {
401
- for (let j = 0; j < _schedule.m.length; j++) {
402
- hm.push(`${zeroPad(_schedule.h[i])}:${zeroPad(_schedule.m[j])}`);
403
- }
404
- }
405
- if (hm.length < 2) {
406
- outputText = `${locale.At} ${hm[0]}`;
407
- }
408
- else {
409
- const lastVal = hm.pop();
410
- outputText = `${locale.At} ${hm.join(', ')} ${locale.and} ${lastVal}`;
411
- }
412
- if (!_schedule.d && !_schedule.D) {
413
- outputText += ` ${locale['every day']} `;
414
- }
415
- }
416
- else if (_schedule.h) { // runs only at specific hours
417
- // Otherwise, list out every specified hour/minute value.
418
- if (_schedule.m) { // and only at specific minutes
419
- if (_withSeconds) {
420
- if (!_schedule.s || _schedule.s.length === 60) {
421
- outputText += `${locale['second of every']} ${numberList(_schedule.m)} ${locale['minute past the']} ${numberList(_schedule.h)} ${locale.hour}`;
422
- }
423
- else {
424
- outputText += `${numberList(_schedule.s)} ${locale['second of every']} ${numberList(_schedule.m)} ${locale['minute past the']} ${numberList(_schedule.h)} ${locale.hour}`;
425
- }
426
- }
427
- else {
428
- outputText += `${numberList(_schedule.m)} ${locale['minute past the']} ${numberList(_schedule.h)} ${locale.hour}`;
429
- }
430
- }
431
- else if (_withSeconds) {
432
- // specific hours, but every minute
433
- if (!_schedule.s || _schedule.s.length === 60) {
434
- outputText += `${locale['second of every']} ${locale['minute of']} ${numberList(_schedule.h)} ${locale.hour}`;
435
- }
436
- else {
437
- outputText += `${numberList(_schedule.s)} ${locale['second of every']} ${locale['minute of']} ${numberList(_schedule.h)} ${locale.hour}`;
438
- }
439
- }
440
- else {
441
- outputText += `${locale['minute of']} ${numberList(_schedule.h)} ${locale.hour}`;
442
- }
443
- }
444
- else if (_schedule.m) { // every hour, but specific minutes
445
- if (_withSeconds) {
446
- if (!_schedule.s || _schedule.s.length === 60) {
447
- outputText += `${locale['second of every']} ${numberList(_schedule.m)} ${locale['minute every hour']}`;
448
- }
449
- else {
450
- outputText += `${numberList(_schedule.s)} ${locale['second of every']} ${numberList(_schedule.m)} ${locale['minute every hour']}`;
451
- }
452
- }
453
- else {
454
- outputText += `${numberList(_schedule.m)} ${locale['minute every hour']}`;
455
- }
456
- }
457
- else if (_withSeconds) {
458
- if (!_schedule.s || _schedule.s.length === 60) {
459
- outputText += locale.second;
460
- }
461
- else {
462
- outputText += `${numberList(_schedule.s)} ${locale.second}`;
463
- }
464
- }
465
- else { // cronSpec has "*" for both hour and minute
466
- outputText += locale.minute;
467
- }
468
- if (_schedule.D) { // runs only on specific day(s) of month
469
- outputText += (locale['on the'] ? ` ${locale['on the']} ` : ' ') + numberList(_schedule.D);
470
- if (!_schedule.M) {
471
- outputText += ` ${locale['of every month']}`;
472
- }
473
- }
474
- if (_schedule.d) { // runs only on specific day(s) of week
475
- if (_schedule.D) {
476
- // if both day fields are specified, cron uses both; superuser.com/a/348372
477
- outputText += ` ${locale['and every']} `;
478
- }
479
- else {
480
- outputText += ` ${locale.on} `;
481
- }
482
- outputText += dateList(_schedule.d, 'dow');
483
- }
484
- if (_schedule.M) {
485
- // runs only in specific months; put this output last
486
- outputText += ` ${locale.in} ${dateList(_schedule.M, 'mon')}`;
487
- }
488
- return outputText;
489
- }
490
- return scheduleToSentence(schedule.schedules[0], withSeconds);
491
- }
492
- exports.default = cronToText;
@@ -1,29 +0,0 @@
1
- export type CRON_LOCALE = {
2
- ORDINALS: {
3
- th: string;
4
- st: string;
5
- nd: string;
6
- rd: string;
7
- };
8
- MONTH: string[];
9
- DOW: string[];
10
- Every: string;
11
- and: string;
12
- 'every day': string;
13
- 'minute past the': string;
14
- hour: string;
15
- minute: string;
16
- 'minute of': string;
17
- second: string;
18
- 'second in minute': string;
19
- 'second of every': string;
20
- 'minute every hour': string;
21
- 'on the': string;
22
- 'of every month': string;
23
- 'and every': string;
24
- At: string;
25
- on: string;
26
- in: string;
27
- };
28
- declare const JQUERY_CRON_LOCALE: Record<ioBroker.Languages, CRON_LOCALE>;
29
- export default JQUERY_CRON_LOCALE;