rrule-temporal 1.4.5 → 1.4.7
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 +20 -1
- package/dist/{chunk-5IREWES7.js → chunk-Y57KCW63.js} +118 -91
- package/dist/index.cjs +123 -93
- package/dist/index.d.cts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +9 -3
- package/dist/totext.cjs +173 -133
- package/dist/totext.d.cts +5 -2
- package/dist/totext.d.ts +5 -2
- package/dist/totext.js +61 -44
- package/package.json +1 -1
package/dist/totext.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { RRuleTemporal } from './index.js';
|
|
2
2
|
import '@js-temporal/polyfill';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
interface ToTextOptions {
|
|
5
|
+
includeDtstart?: boolean;
|
|
6
|
+
}
|
|
7
|
+
declare function toText(input: RRuleTemporal | string, locale?: string, options?: ToTextOptions): string;
|
|
5
8
|
|
|
6
|
-
export { toText };
|
|
9
|
+
export { type ToTextOptions, toText };
|
package/dist/totext.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
RRuleTemporal
|
|
3
|
-
|
|
2
|
+
RRuleTemporal,
|
|
3
|
+
allowedWeekdays
|
|
4
|
+
} from "./chunk-Y57KCW63.js";
|
|
4
5
|
|
|
5
6
|
// src/totext.ts
|
|
6
7
|
var en = {
|
|
@@ -53,7 +54,8 @@ var en = {
|
|
|
53
54
|
date: "date",
|
|
54
55
|
dates: "dates",
|
|
55
56
|
and: "and",
|
|
56
|
-
last: "last"
|
|
57
|
+
last: "last",
|
|
58
|
+
starting_from: "starting from"
|
|
57
59
|
},
|
|
58
60
|
ordinal: (n) => {
|
|
59
61
|
const abs = Math.abs(n);
|
|
@@ -111,7 +113,8 @@ var de = {
|
|
|
111
113
|
date: "Datum",
|
|
112
114
|
dates: "Daten",
|
|
113
115
|
and: "und",
|
|
114
|
-
last: "letzter"
|
|
116
|
+
last: "letzter",
|
|
117
|
+
starting_from: "beginnend am"
|
|
115
118
|
},
|
|
116
119
|
ordinal: (n) => {
|
|
117
120
|
if (n < 0) return "letzten";
|
|
@@ -168,7 +171,8 @@ var es = {
|
|
|
168
171
|
date: "fecha",
|
|
169
172
|
dates: "fechas",
|
|
170
173
|
and: "y",
|
|
171
|
-
last: "\xFAltimo"
|
|
174
|
+
last: "\xFAltimo",
|
|
175
|
+
starting_from: "a partir de"
|
|
172
176
|
},
|
|
173
177
|
ordinal: (n) => n < 0 ? "\xFAltimo" : `${Math.abs(n)}\xBA`
|
|
174
178
|
};
|
|
@@ -222,7 +226,8 @@ var hi = {
|
|
|
222
226
|
date: "\u0924\u093E\u0930\u0940\u0916",
|
|
223
227
|
dates: "\u0924\u093E\u0930\u0940\u0916\u0947\u0902",
|
|
224
228
|
and: "\u0914\u0930",
|
|
225
|
-
last: "\u0906\u0916\u093F\u0930\u0940"
|
|
229
|
+
last: "\u0906\u0916\u093F\u0930\u0940",
|
|
230
|
+
starting_from: "\u0938\u0947 \u0936\u0941\u0930\u0942"
|
|
226
231
|
},
|
|
227
232
|
ordinal: (n) => n < 0 ? "\u0906\u0916\u093F\u0930\u0940" : `${Math.abs(n)}\u0935\u093E\u0902`
|
|
228
233
|
};
|
|
@@ -263,7 +268,8 @@ var yue = {
|
|
|
263
268
|
date: "\u65E5\u671F",
|
|
264
269
|
dates: "\u65E5\u671F",
|
|
265
270
|
and: "\u548C",
|
|
266
|
-
last: "\u6700\u5F8C"
|
|
271
|
+
last: "\u6700\u5F8C",
|
|
272
|
+
starting_from: "\u7531"
|
|
267
273
|
},
|
|
268
274
|
ordinal: (n) => n < 0 ? "\u6700\u5F8C" : `\u7B2C${Math.abs(n)}`
|
|
269
275
|
};
|
|
@@ -317,7 +323,8 @@ var ar = {
|
|
|
317
323
|
date: "\u062A\u0627\u0631\u064A\u062E",
|
|
318
324
|
dates: "\u062A\u0648\u0627\u0631\u064A\u062E",
|
|
319
325
|
and: "\u0648",
|
|
320
|
-
last: "\u0627\u0644\u0623\u062E\u064A\u0631"
|
|
326
|
+
last: "\u0627\u0644\u0623\u062E\u064A\u0631",
|
|
327
|
+
starting_from: "\u0627\u0628\u062A\u062F\u0627\u0621\u064B \u0645\u0646"
|
|
321
328
|
},
|
|
322
329
|
ordinal: (n) => {
|
|
323
330
|
if (n < 0) return "\u0627\u0644\u0623\u062E\u064A\u0631";
|
|
@@ -390,7 +397,8 @@ var he = {
|
|
|
390
397
|
date: "\u05EA\u05D0\u05E8\u05D9\u05DA",
|
|
391
398
|
dates: "\u05EA\u05D0\u05E8\u05D9\u05DB\u05D9\u05DD",
|
|
392
399
|
and: "\u05D5",
|
|
393
|
-
last: "\u05D0\u05D7\u05E8\u05D5\u05DF"
|
|
400
|
+
last: "\u05D0\u05D7\u05E8\u05D5\u05DF",
|
|
401
|
+
starting_from: "\u05D4\u05D7\u05DC \u05DE"
|
|
394
402
|
},
|
|
395
403
|
ordinal: (n) => {
|
|
396
404
|
if (n < 0) return "\u05D0\u05D7\u05E8\u05D5\u05DF";
|
|
@@ -450,25 +458,26 @@ var zh = {
|
|
|
450
458
|
date: "\u65E5\u671F",
|
|
451
459
|
dates: "\u65E5\u671F",
|
|
452
460
|
and: "\u548C",
|
|
453
|
-
last: "\u6700\u540E"
|
|
461
|
+
last: "\u6700\u540E",
|
|
462
|
+
starting_from: "\u4ECE"
|
|
454
463
|
},
|
|
455
464
|
ordinal: (n) => n < 0 ? "\u6700\u540E" : `\u7B2C${Math.abs(n)}`
|
|
456
465
|
};
|
|
457
466
|
var fr = {
|
|
458
|
-
weekdayNames: ["
|
|
467
|
+
weekdayNames: ["lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi", "dimanche"],
|
|
459
468
|
monthNames: [
|
|
460
|
-
"
|
|
461
|
-
"
|
|
462
|
-
"
|
|
463
|
-
"
|
|
464
|
-
"
|
|
465
|
-
"
|
|
466
|
-
"
|
|
467
|
-
"
|
|
468
|
-
"
|
|
469
|
-
"
|
|
470
|
-
"
|
|
471
|
-
"
|
|
469
|
+
"janvier",
|
|
470
|
+
"f\xE9vrier",
|
|
471
|
+
"mars",
|
|
472
|
+
"avril",
|
|
473
|
+
"mai",
|
|
474
|
+
"juin",
|
|
475
|
+
"juillet",
|
|
476
|
+
"ao\xFBt",
|
|
477
|
+
"septembre",
|
|
478
|
+
"octobre",
|
|
479
|
+
"novembre",
|
|
480
|
+
"d\xE9cembre"
|
|
472
481
|
],
|
|
473
482
|
units: {
|
|
474
483
|
year: { singular: "ann\xE9e", plural: "ans" },
|
|
@@ -491,7 +500,7 @@ var fr = {
|
|
|
491
500
|
at: "\xE0",
|
|
492
501
|
at_minute: "\xE0 la minute",
|
|
493
502
|
at_second: "\xE0 la seconde",
|
|
494
|
-
until: "jusqu'
|
|
503
|
+
until: "jusqu'au",
|
|
495
504
|
for: "pendant",
|
|
496
505
|
time: "fois",
|
|
497
506
|
times: "fois",
|
|
@@ -504,7 +513,8 @@ var fr = {
|
|
|
504
513
|
date: "date",
|
|
505
514
|
dates: "dates",
|
|
506
515
|
and: "et",
|
|
507
|
-
last: "dernier"
|
|
516
|
+
last: "dernier",
|
|
517
|
+
starting_from: "\xE0 partir du"
|
|
508
518
|
},
|
|
509
519
|
ordinal: (n) => {
|
|
510
520
|
const abs = Math.abs(n);
|
|
@@ -520,6 +530,11 @@ var LOCALES = {};
|
|
|
520
530
|
for (const l of active) {
|
|
521
531
|
if (ALL_LOCALES[l]) LOCALES[l] = ALL_LOCALES[l];
|
|
522
532
|
}
|
|
533
|
+
var workweekWeekdays = allowedWeekdays.slice(0, 5);
|
|
534
|
+
var byDayTokenRegex = new RegExp(`^([+-]?\\d+)?(${allowedWeekdays.join("|")})$`);
|
|
535
|
+
var weekdayIndexByToken = Object.fromEntries(
|
|
536
|
+
allowedWeekdays.map((weekday, idx) => [weekday, idx])
|
|
537
|
+
);
|
|
523
538
|
function defaultOrdinal(n) {
|
|
524
539
|
const abs = Math.abs(n);
|
|
525
540
|
const suffix = abs % 10 === 1 && abs % 100 !== 11 ? "st" : abs % 10 === 2 && abs % 100 !== 12 ? "nd" : abs % 10 === 3 && abs % 100 !== 13 ? "rd" : "th";
|
|
@@ -535,19 +550,11 @@ function list(arr, mapFn = (x) => `${x}`, final) {
|
|
|
535
550
|
}
|
|
536
551
|
function formatByDayToken(tok, locale) {
|
|
537
552
|
if (typeof tok === "number") return tok.toString();
|
|
538
|
-
const m = tok.
|
|
553
|
+
const m = tok.toUpperCase().match(byDayTokenRegex);
|
|
539
554
|
if (!m) return tok;
|
|
540
555
|
const ord = m[1] ? parseInt(m[1], 10) : 0;
|
|
541
|
-
const
|
|
542
|
-
|
|
543
|
-
TU: 1,
|
|
544
|
-
WE: 2,
|
|
545
|
-
TH: 3,
|
|
546
|
-
FR: 4,
|
|
547
|
-
SA: 5,
|
|
548
|
-
SU: 6
|
|
549
|
-
};
|
|
550
|
-
const idx = weekdayMap[m[2]];
|
|
556
|
+
const weekday = m[2];
|
|
557
|
+
const idx = weekdayIndexByToken[weekday];
|
|
551
558
|
const name = locale.weekdayNames[idx];
|
|
552
559
|
if (ord === 0) return name;
|
|
553
560
|
if (ord === -1) return `${locale.words.last} ${name}`;
|
|
@@ -567,8 +574,7 @@ function formatTime(hour, minute = 0, second = 0) {
|
|
|
567
574
|
return `${hr12} ${ampm}`;
|
|
568
575
|
}
|
|
569
576
|
function weekdayTokenFromZdt(zdt) {
|
|
570
|
-
|
|
571
|
-
return tokens[zdt.dayOfWeek - 1];
|
|
577
|
+
return allowedWeekdays[zdt.dayOfWeek - 1];
|
|
572
578
|
}
|
|
573
579
|
function tzAbbreviation(zdt) {
|
|
574
580
|
const parts = new Intl.DateTimeFormat("en-US", {
|
|
@@ -579,11 +585,20 @@ function tzAbbreviation(zdt) {
|
|
|
579
585
|
const tzPart = parts.find((p) => p.type === "timeZoneName");
|
|
580
586
|
return (tzPart == null ? void 0 : tzPart.value) || zdt.timeZoneId;
|
|
581
587
|
}
|
|
582
|
-
function
|
|
588
|
+
function formatLocalizedDate(zdt, locale) {
|
|
589
|
+
try {
|
|
590
|
+
return zdt.toLocaleString(locale, { dateStyle: "long" });
|
|
591
|
+
} catch (e) {
|
|
592
|
+
return zdt.toLocaleString("en", { dateStyle: "long" });
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
function toText(input, locale, options = {}) {
|
|
583
596
|
const rule = typeof input === "string" ? new RRuleTemporal({ rruleString: input }) : input;
|
|
584
597
|
const opts = rule.options();
|
|
585
|
-
const
|
|
598
|
+
const resolvedLocale = locale != null ? locale : Intl.DateTimeFormat().resolvedOptions().locale;
|
|
599
|
+
const lang = resolvedLocale.split("-")[0];
|
|
586
600
|
const data = LOCALES[lang] || en;
|
|
601
|
+
const dateLocale = LOCALES[lang] ? resolvedLocale : "en";
|
|
587
602
|
const {
|
|
588
603
|
freq,
|
|
589
604
|
interval = 1,
|
|
@@ -622,8 +637,8 @@ function toText(input, locale) {
|
|
|
622
637
|
}[freq];
|
|
623
638
|
const base = data.units[baseKey];
|
|
624
639
|
const daysNormalized = textByDay == null ? void 0 : textByDay.map((d) => d.toUpperCase());
|
|
625
|
-
const isWeekdays = daysNormalized && daysNormalized.length ===
|
|
626
|
-
const isEveryday = daysNormalized && daysNormalized.length ===
|
|
640
|
+
const isWeekdays = daysNormalized && daysNormalized.length === workweekWeekdays.length && workweekWeekdays.every((d) => daysNormalized.includes(d));
|
|
641
|
+
const isEveryday = daysNormalized && daysNormalized.length === allowedWeekdays.length && allowedWeekdays.every((d) => daysNormalized.includes(d));
|
|
627
642
|
if (freq === "WEEKLY" && interval === 1 && isWeekdays) {
|
|
628
643
|
parts.push(data.words.weekday);
|
|
629
644
|
} else if (freq === "WEEKLY" && interval === 1 && isEveryday) {
|
|
@@ -685,9 +700,11 @@ function toText(input, locale) {
|
|
|
685
700
|
if (!textByHour && !textByMinute && textBySecond) {
|
|
686
701
|
parts.push(data.words.at_second, list(textBySecond, void 0, data.words.and));
|
|
687
702
|
}
|
|
703
|
+
if (options.includeDtstart) {
|
|
704
|
+
parts.push(data.words.starting_from, formatLocalizedDate(opts.dtstart, dateLocale));
|
|
705
|
+
}
|
|
688
706
|
if (until) {
|
|
689
|
-
|
|
690
|
-
parts.push(data.words.until, `${monthName} ${until.day}, ${until.year}`);
|
|
707
|
+
parts.push(data.words.until, formatLocalizedDate(until, dateLocale));
|
|
691
708
|
} else if (count !== void 0) {
|
|
692
709
|
parts.push(data.words.for, count.toString(), count === 1 ? data.words.time : data.words.times);
|
|
693
710
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rrule-temporal",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.7",
|
|
4
4
|
"description": "Recurrence rule (rrule) processing using Temporal PlainDate/PlainDateTime, with cross-timezone and cross-calendar rrule support",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"main": "dist/index.js",
|