@telia/teddy 0.0.37 → 0.0.39
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/dist/components/card/card-button.cjs +42 -0
- package/dist/components/card/card-button.d.ts +35 -0
- package/dist/components/card/card-button.js +42 -0
- package/dist/components/card/card-content.cjs +15 -0
- package/dist/components/card/card-content.d.ts +6 -0
- package/dist/components/card/card-content.js +15 -0
- package/dist/components/card/card-footer.cjs +15 -0
- package/dist/components/card/card-footer.d.ts +6 -0
- package/dist/components/card/card-footer.js +15 -0
- package/dist/components/card/card-heading.cjs +25 -0
- package/dist/components/card/card-heading.d.ts +6 -0
- package/dist/components/card/card-heading.js +25 -0
- package/dist/components/card/card-illustration.cjs +22 -0
- package/dist/components/card/card-illustration.d.ts +15 -0
- package/dist/components/card/card-illustration.js +22 -0
- package/dist/components/card/card-line.cjs +13 -0
- package/dist/components/card/card-line.d.ts +5 -0
- package/dist/components/card/card-line.js +13 -0
- package/dist/components/card/card-link.cjs +18 -0
- package/dist/components/card/card-link.d.ts +11 -0
- package/dist/components/card/card-link.js +18 -0
- package/dist/components/card/card-slot.cjs +36 -0
- package/dist/components/card/card-slot.d.ts +8 -0
- package/dist/components/card/card-slot.js +36 -0
- package/dist/components/card/card.cjs +38 -171
- package/dist/components/card/card.d.ts +15 -99
- package/dist/components/card/card.js +39 -172
- package/dist/components/card/index.cjs +28 -1
- package/dist/components/card/index.d.ts +64 -2
- package/dist/components/card/index.js +28 -1
- package/dist/components/card/utils.cjs +4 -0
- package/dist/components/card/utils.d.ts +2 -0
- package/dist/components/card/utils.js +4 -0
- package/dist/components/date-picker/css.cjs +59 -0
- package/dist/components/date-picker/css.d.ts +1 -0
- package/dist/components/date-picker/css.js +59 -0
- package/dist/components/date-picker/date-picker-day.cjs +67 -0
- package/dist/components/date-picker/date-picker-day.d.ts +13 -0
- package/dist/components/date-picker/date-picker-day.js +67 -0
- package/dist/components/date-picker/date-picker-input.cjs +89 -0
- package/dist/components/date-picker/date-picker-input.d.ts +27 -0
- package/dist/components/date-picker/date-picker-input.js +90 -0
- package/dist/components/date-picker/date-picker-localization.cjs +31 -0
- package/dist/components/date-picker/date-picker-localization.d.ts +20 -0
- package/dist/components/date-picker/date-picker-localization.js +32 -0
- package/dist/components/date-picker/date-picker-month.cjs +42 -0
- package/dist/components/date-picker/date-picker-month.d.ts +20 -0
- package/dist/components/date-picker/date-picker-month.js +43 -0
- package/dist/components/date-picker/date-picker-navigation-key.cjs +15 -0
- package/dist/components/date-picker/date-picker-navigation-key.d.ts +14 -0
- package/dist/components/date-picker/date-picker-navigation-key.js +16 -0
- package/dist/components/date-picker/date-picker-props.cjs +1 -0
- package/dist/components/date-picker/date-picker-props.d.ts +23 -0
- package/dist/components/date-picker/date-picker-props.js +1 -0
- package/dist/components/date-picker/date-picker-unique-id.cjs +4 -0
- package/dist/components/date-picker/date-picker-unique-id.d.ts +1 -0
- package/dist/components/date-picker/date-picker-unique-id.js +4 -0
- package/dist/components/date-picker/date-picker-year-print.cjs +61 -0
- package/dist/components/date-picker/date-picker-year-print.d.ts +12 -0
- package/dist/components/date-picker/date-picker-year-print.js +61 -0
- package/dist/components/date-picker/date-picker-year.cjs +36 -0
- package/dist/components/date-picker/date-picker-year.d.ts +16 -0
- package/dist/components/date-picker/date-picker-year.js +37 -0
- package/dist/components/date-picker/date-picker.cjs +597 -0
- package/dist/components/date-picker/date-picker.d.ts +5 -0
- package/dist/components/date-picker/date-picker.js +597 -0
- package/dist/components/date-picker/date-utils.cjs +340 -0
- package/dist/components/date-picker/date-utils.d.ts +29 -0
- package/dist/components/date-picker/date-utils.js +340 -0
- package/dist/components/date-picker/date-year-range.cjs +1 -0
- package/dist/components/date-picker/date-year-range.d.ts +4 -0
- package/dist/components/date-picker/date-year-range.js +1 -0
- package/dist/components/date-picker/dialog-utils.cjs +36 -0
- package/dist/components/date-picker/dialog-utils.d.ts +3 -0
- package/dist/components/date-picker/dialog-utils.js +36 -0
- package/dist/components/date-picker/index.cjs +4 -0
- package/dist/components/date-picker/index.d.ts +2 -0
- package/dist/components/date-picker/index.js +4 -0
- package/dist/components/expandable-card/expandable-card-root.cjs +15 -15
- package/dist/components/expandable-card/expandable-card-root.js +15 -15
- package/dist/components/image/image.cjs +1 -1
- package/dist/components/image/image.js +1 -1
- package/dist/components/index.cjs +4 -2
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +3 -1
- package/dist/components/modal/modal.cjs +4 -4
- package/dist/components/modal/modal.js +4 -4
- package/dist/components/navigation-menu/global-navigation/global-navigation-my-pages.cjs +33 -18
- package/dist/components/navigation-menu/global-navigation/global-navigation-my-pages.js +34 -19
- package/dist/components/navigation-menu/global-navigation/global-navigation-root.d.ts +3 -1
- package/dist/components/navigation-menu/global-navigation/utils.cjs +152 -125
- package/dist/components/navigation-menu/global-navigation/utils.d.ts +229 -219
- package/dist/components/navigation-menu/global-navigation/utils.js +152 -125
- package/dist/components/notification/notification.cjs +2 -2
- package/dist/components/notification/notification.d.ts +7 -7
- package/dist/components/notification/notification.js +1 -1
- package/dist/main.cjs +4 -2
- package/dist/main.js +3 -1
- package/dist/style.css +637 -187
- package/package.json +1 -1
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const DIGIT_DATE_FORMAT = /^\d{6}$/;
|
|
4
|
+
const ISO_DATE_FORMAT = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
5
|
+
const NOR_DATE_FORMAT = /^(\d{2}).(\d{2}).(\d{4})$/;
|
|
6
|
+
const NOR_DATE_FORMAT2 = /^(\d{2})\s(\d{2})\s(\d{4})$/;
|
|
7
|
+
const NOR_DATE_FORMAT3 = /^(\d{2})(\d{2})(\d{4})$/;
|
|
8
|
+
const EU_DATE_FORMAT = /^(\d{2})-(\d{2})-(\d{4})$/;
|
|
9
|
+
const US_DATE_FORMAT = /^(\d{2})\/(\d{2})\/(\d{4})$/;
|
|
10
|
+
const US_DATE_FORMAT2 = /^(\d{2})\/(\d{2})\/(\d{2})$/;
|
|
11
|
+
const replaceAll = (str, old, replacement) => {
|
|
12
|
+
return str.split(old).join(replacement);
|
|
13
|
+
};
|
|
14
|
+
var DaysOfWeek = /* @__PURE__ */ ((DaysOfWeek2) => {
|
|
15
|
+
DaysOfWeek2[DaysOfWeek2["Sunday"] = 0] = "Sunday";
|
|
16
|
+
DaysOfWeek2[DaysOfWeek2["Monday"] = 1] = "Monday";
|
|
17
|
+
DaysOfWeek2[DaysOfWeek2["Tuesday"] = 2] = "Tuesday";
|
|
18
|
+
DaysOfWeek2[DaysOfWeek2["Wednesday"] = 3] = "Wednesday";
|
|
19
|
+
DaysOfWeek2[DaysOfWeek2["Thursday"] = 4] = "Thursday";
|
|
20
|
+
DaysOfWeek2[DaysOfWeek2["Friday"] = 5] = "Friday";
|
|
21
|
+
DaysOfWeek2[DaysOfWeek2["Saturday"] = 6] = "Saturday";
|
|
22
|
+
return DaysOfWeek2;
|
|
23
|
+
})(DaysOfWeek || {});
|
|
24
|
+
function createDate(year, month, day) {
|
|
25
|
+
const dayInt = parseInt(day, 10);
|
|
26
|
+
const monthInt = parseInt(month, 10);
|
|
27
|
+
let yearInt = parseInt(year, 10);
|
|
28
|
+
if (yearInt < 100) {
|
|
29
|
+
yearInt = yearInt + 2e3;
|
|
30
|
+
}
|
|
31
|
+
const isValid = Number.isInteger(yearInt) && Number.isInteger(monthInt) && Number.isInteger(dayInt) && monthInt > 0 && monthInt <= 12 && dayInt > 0 && dayInt <= 31 && yearInt > 0 && yearInt < 1e4;
|
|
32
|
+
if (isValid) {
|
|
33
|
+
try {
|
|
34
|
+
const test = new Date(yearInt, monthInt - 1, dayInt);
|
|
35
|
+
test.getMonth();
|
|
36
|
+
return test;
|
|
37
|
+
} catch {
|
|
38
|
+
console.warn("Silently continuing, but could not create date: " + year + ", " + month + ", " + day);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function cleanDateValue(value) {
|
|
43
|
+
value = value.trim();
|
|
44
|
+
value = replaceAll(value, " ", ".");
|
|
45
|
+
value = replaceAll(value, "-", ".");
|
|
46
|
+
value = replaceAll(value, "..", ".");
|
|
47
|
+
if (value.includes("/") && value.includes(".")) {
|
|
48
|
+
return replaceAll(value, "/", ".");
|
|
49
|
+
}
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
function isDayMonthYearValid(day, month, year) {
|
|
53
|
+
try {
|
|
54
|
+
return Number.parseInt(day) > 0 && Number.parseInt(month) > 0 && Number.parseInt(year) >= 0 && Number.parseInt(year) <= 9999;
|
|
55
|
+
} catch {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function splitDate(value) {
|
|
60
|
+
let [day, month, year] = value.split(".");
|
|
61
|
+
if (day.length === 4) {
|
|
62
|
+
const tmp = day;
|
|
63
|
+
day = year;
|
|
64
|
+
year = tmp;
|
|
65
|
+
month = month.trim();
|
|
66
|
+
}
|
|
67
|
+
if (isDayMonthYearValid(day, month, year))
|
|
68
|
+
return [day, month, year];
|
|
69
|
+
return ["", "", ""];
|
|
70
|
+
}
|
|
71
|
+
function calculateYear(year) {
|
|
72
|
+
if (year.length !== 2)
|
|
73
|
+
return year;
|
|
74
|
+
let inputYear = Number(year);
|
|
75
|
+
const currYear = (/* @__PURE__ */ new Date()).getFullYear();
|
|
76
|
+
const hundredYearPart = Number(currYear.toString().slice(-2));
|
|
77
|
+
if (inputYear > hundredYearPart + 5) {
|
|
78
|
+
inputYear = Number((currYear - 100).toString().slice(0, 2) + inputYear.toString());
|
|
79
|
+
}
|
|
80
|
+
return inputYear.toString();
|
|
81
|
+
}
|
|
82
|
+
function parseDate6Digits(value) {
|
|
83
|
+
if (value.includes("."))
|
|
84
|
+
return void 0;
|
|
85
|
+
if (value.endsWith("19") || value.endsWith("20"))
|
|
86
|
+
return void 0;
|
|
87
|
+
const matches = value.match(DIGIT_DATE_FORMAT);
|
|
88
|
+
if (matches === null || matches.length === 0)
|
|
89
|
+
return void 0;
|
|
90
|
+
const match = matches[0];
|
|
91
|
+
if (!match)
|
|
92
|
+
return void 0;
|
|
93
|
+
const y = calculateYear(match[4] + match[5]);
|
|
94
|
+
return createDate(y, match[2] + match[3], match[0] + match[1]);
|
|
95
|
+
}
|
|
96
|
+
function formatDate8To6Or10(value) {
|
|
97
|
+
if (value.includes("/")) {
|
|
98
|
+
return value;
|
|
99
|
+
}
|
|
100
|
+
if (value.includes(".")) {
|
|
101
|
+
const [day2, month2, year2] = splitDate(value);
|
|
102
|
+
if (!day2 || !month2)
|
|
103
|
+
return value;
|
|
104
|
+
const yearNumber = Number.parseInt(year2);
|
|
105
|
+
if (yearNumber === 19 || yearNumber === 20) {
|
|
106
|
+
return value;
|
|
107
|
+
}
|
|
108
|
+
return replaceAll(value, ".", "");
|
|
109
|
+
}
|
|
110
|
+
const [day, month, year] = [value.substring(0, 2), value.substring(2, 4), value.substring(4, 8)];
|
|
111
|
+
if (isDayMonthYearValid(day, month, year)) {
|
|
112
|
+
return `${day.padStart(2, "0")}.${month.padStart(2, "0")}.${year}`;
|
|
113
|
+
}
|
|
114
|
+
return value;
|
|
115
|
+
}
|
|
116
|
+
function formatDateTo10(value) {
|
|
117
|
+
let delimiter = ".";
|
|
118
|
+
if (value.includes("/"))
|
|
119
|
+
delimiter = "/";
|
|
120
|
+
let [day, month, year] = value.split(delimiter);
|
|
121
|
+
if (day.length === 4) {
|
|
122
|
+
const tmp = day;
|
|
123
|
+
day = year;
|
|
124
|
+
year = tmp;
|
|
125
|
+
month = month.trim();
|
|
126
|
+
}
|
|
127
|
+
year = calculateYear(year);
|
|
128
|
+
return day + delimiter + month + delimiter + year;
|
|
129
|
+
}
|
|
130
|
+
function parseDate(value) {
|
|
131
|
+
if (!value) {
|
|
132
|
+
return void 0;
|
|
133
|
+
}
|
|
134
|
+
if (value.length < 6)
|
|
135
|
+
return void 0;
|
|
136
|
+
value = cleanDateValue(value);
|
|
137
|
+
if (value.length === 8) {
|
|
138
|
+
value = formatDate8To6Or10(value);
|
|
139
|
+
}
|
|
140
|
+
if (value.length === 6)
|
|
141
|
+
return parseDate6Digits(value);
|
|
142
|
+
if (value.length !== 10 && value.length !== 8)
|
|
143
|
+
return void 0;
|
|
144
|
+
value = formatDateTo10(value);
|
|
145
|
+
let date = void 0;
|
|
146
|
+
const isoFormats = [ISO_DATE_FORMAT];
|
|
147
|
+
const norFormats = [NOR_DATE_FORMAT, NOR_DATE_FORMAT2, NOR_DATE_FORMAT3, EU_DATE_FORMAT];
|
|
148
|
+
const usFormats = [US_DATE_FORMAT, US_DATE_FORMAT2];
|
|
149
|
+
isoFormats.forEach((format) => {
|
|
150
|
+
if (date === void 0) {
|
|
151
|
+
const matches = value.match(format);
|
|
152
|
+
if (matches !== null && matches.length > 1) {
|
|
153
|
+
date = createDate(matches[1], matches[2], matches[3]);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
usFormats.forEach((format) => {
|
|
158
|
+
if (date === void 0) {
|
|
159
|
+
const matches = value.match(format);
|
|
160
|
+
if (matches !== null && matches.length > 1) {
|
|
161
|
+
date = createDate(matches[3], matches[1], matches[2]);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
norFormats.forEach((format) => {
|
|
166
|
+
if (date === void 0) {
|
|
167
|
+
const matches = value.match(format);
|
|
168
|
+
if (matches !== null && matches.length > 1) {
|
|
169
|
+
date = createDate(matches[3], matches[2], matches[1]);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
if (date === void 0) {
|
|
174
|
+
console.warn("Date not supported in any regex formats: " + value);
|
|
175
|
+
}
|
|
176
|
+
return date;
|
|
177
|
+
}
|
|
178
|
+
function printISODate(date) {
|
|
179
|
+
if (date === void 0) {
|
|
180
|
+
return "";
|
|
181
|
+
}
|
|
182
|
+
let d = date.getDate().toString(10);
|
|
183
|
+
let m = (date.getMonth() + 1).toString(10);
|
|
184
|
+
const y = date.getFullYear().toString(10);
|
|
185
|
+
if (date.getDate() < 10) {
|
|
186
|
+
d = `0${d}`;
|
|
187
|
+
}
|
|
188
|
+
if (date.getMonth() < 9) {
|
|
189
|
+
m = `0${m}`;
|
|
190
|
+
}
|
|
191
|
+
return `${y}-${m}-${d}`;
|
|
192
|
+
}
|
|
193
|
+
function printDate(isoDate) {
|
|
194
|
+
if (isoDate === void 0 || isoDate == null || isoDate === "") {
|
|
195
|
+
return "";
|
|
196
|
+
}
|
|
197
|
+
if (isoDate.length !== 10) {
|
|
198
|
+
return isoDate;
|
|
199
|
+
}
|
|
200
|
+
const date = parseDate(isoDate);
|
|
201
|
+
if (date === void 0) {
|
|
202
|
+
return isoDate;
|
|
203
|
+
}
|
|
204
|
+
let d = date.getDate().toString(10);
|
|
205
|
+
let m = (date.getMonth() + 1).toString(10);
|
|
206
|
+
const y = date.getFullYear().toString(10);
|
|
207
|
+
if (date.getDate() < 10) {
|
|
208
|
+
d = `0${d}`;
|
|
209
|
+
}
|
|
210
|
+
if (date.getMonth() < 9) {
|
|
211
|
+
m = `0${m}`;
|
|
212
|
+
}
|
|
213
|
+
return `${d}.${m}.${y}`;
|
|
214
|
+
}
|
|
215
|
+
function isEqual(a, b) {
|
|
216
|
+
if (typeof b === "undefined")
|
|
217
|
+
return false;
|
|
218
|
+
if (a == null || b == null)
|
|
219
|
+
return false;
|
|
220
|
+
return isEqualMonth(a, b) && a.getDate() === b.getDate();
|
|
221
|
+
}
|
|
222
|
+
function isEqualMonth(a, b) {
|
|
223
|
+
if (a == null || b == null) {
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth();
|
|
227
|
+
}
|
|
228
|
+
function addDays(date, days) {
|
|
229
|
+
const d = new Date(date);
|
|
230
|
+
d.setDate(d.getDate() + days);
|
|
231
|
+
return d;
|
|
232
|
+
}
|
|
233
|
+
function addMonths(date, months) {
|
|
234
|
+
const d = new Date(date);
|
|
235
|
+
d.setMonth(date.getMonth() + months);
|
|
236
|
+
return d;
|
|
237
|
+
}
|
|
238
|
+
function addYears(date, years) {
|
|
239
|
+
const d = new Date(date);
|
|
240
|
+
d.setFullYear(date.getFullYear() + years);
|
|
241
|
+
return d;
|
|
242
|
+
}
|
|
243
|
+
function startOfWeek(date, firstDayOfWeek = 1) {
|
|
244
|
+
const d = new Date(date);
|
|
245
|
+
const day = d.getDay();
|
|
246
|
+
const diff = (day < firstDayOfWeek ? 7 : 0) + day - firstDayOfWeek;
|
|
247
|
+
d.setDate(d.getDate() - diff);
|
|
248
|
+
return d;
|
|
249
|
+
}
|
|
250
|
+
function endOfWeek(date, firstDayOfWeek = 1) {
|
|
251
|
+
const d = new Date(date);
|
|
252
|
+
const day = d.getDay();
|
|
253
|
+
const diff = (day < firstDayOfWeek ? -7 : 0) + 6 - (day - firstDayOfWeek);
|
|
254
|
+
d.setDate(d.getDate() + diff);
|
|
255
|
+
return d;
|
|
256
|
+
}
|
|
257
|
+
function startOfMonth(date) {
|
|
258
|
+
return new Date(date.getFullYear(), date.getMonth(), 1);
|
|
259
|
+
}
|
|
260
|
+
function endOfMonth(date) {
|
|
261
|
+
return new Date(date.getFullYear(), date.getMonth() + 1, 0);
|
|
262
|
+
}
|
|
263
|
+
function setMonth(date, month) {
|
|
264
|
+
const d = new Date(date);
|
|
265
|
+
d.setMonth(month);
|
|
266
|
+
return d;
|
|
267
|
+
}
|
|
268
|
+
function setYear(date, year) {
|
|
269
|
+
const d = new Date(date);
|
|
270
|
+
d.setFullYear(year);
|
|
271
|
+
return d;
|
|
272
|
+
}
|
|
273
|
+
function inRange(date, min, max) {
|
|
274
|
+
return clamp(date, min, max) === date;
|
|
275
|
+
}
|
|
276
|
+
function inYearRange(year, min, max) {
|
|
277
|
+
return clampYear(year, min, max) === year;
|
|
278
|
+
}
|
|
279
|
+
function clamp(date, min, max) {
|
|
280
|
+
const time = date.getTime();
|
|
281
|
+
if (min && min instanceof Date && time < min.getTime()) {
|
|
282
|
+
return min;
|
|
283
|
+
}
|
|
284
|
+
if (max && max instanceof Date && time > max.getTime()) {
|
|
285
|
+
return max;
|
|
286
|
+
}
|
|
287
|
+
return date;
|
|
288
|
+
}
|
|
289
|
+
function clampYear(year, min, max) {
|
|
290
|
+
if (typeof min === "number" && year < min) {
|
|
291
|
+
return min;
|
|
292
|
+
}
|
|
293
|
+
if (typeof max === "number" && year > max) {
|
|
294
|
+
return max;
|
|
295
|
+
}
|
|
296
|
+
return year;
|
|
297
|
+
}
|
|
298
|
+
function getDaysInRange(start, end) {
|
|
299
|
+
const days = [];
|
|
300
|
+
let current = start;
|
|
301
|
+
while (!isEqual(current, end)) {
|
|
302
|
+
days.push(current);
|
|
303
|
+
current = addDays(current, 1);
|
|
304
|
+
}
|
|
305
|
+
days.push(current);
|
|
306
|
+
return days;
|
|
307
|
+
}
|
|
308
|
+
function getViewOfMonth(date, firstDayOfWeek = 1) {
|
|
309
|
+
const start = startOfWeek(startOfMonth(date), firstDayOfWeek);
|
|
310
|
+
const end = endOfWeek(endOfMonth(date), firstDayOfWeek);
|
|
311
|
+
return getDaysInRange(start, end);
|
|
312
|
+
}
|
|
313
|
+
function getViewOfYears(start, end) {
|
|
314
|
+
const years = [];
|
|
315
|
+
for (let i = start; i <= end; i++) {
|
|
316
|
+
years.push(i);
|
|
317
|
+
}
|
|
318
|
+
return years;
|
|
319
|
+
}
|
|
320
|
+
exports.DaysOfWeek = DaysOfWeek;
|
|
321
|
+
exports.addDays = addDays;
|
|
322
|
+
exports.addMonths = addMonths;
|
|
323
|
+
exports.addYears = addYears;
|
|
324
|
+
exports.clamp = clamp;
|
|
325
|
+
exports.clampYear = clampYear;
|
|
326
|
+
exports.endOfMonth = endOfMonth;
|
|
327
|
+
exports.endOfWeek = endOfWeek;
|
|
328
|
+
exports.getViewOfMonth = getViewOfMonth;
|
|
329
|
+
exports.getViewOfYears = getViewOfYears;
|
|
330
|
+
exports.inRange = inRange;
|
|
331
|
+
exports.inYearRange = inYearRange;
|
|
332
|
+
exports.isEqual = isEqual;
|
|
333
|
+
exports.isEqualMonth = isEqualMonth;
|
|
334
|
+
exports.parseDate = parseDate;
|
|
335
|
+
exports.printDate = printDate;
|
|
336
|
+
exports.printISODate = printISODate;
|
|
337
|
+
exports.setMonth = setMonth;
|
|
338
|
+
exports.setYear = setYear;
|
|
339
|
+
exports.startOfMonth = startOfMonth;
|
|
340
|
+
exports.startOfWeek = startOfWeek;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare enum DaysOfWeek {
|
|
2
|
+
Sunday = 0,
|
|
3
|
+
Monday = 1,
|
|
4
|
+
Tuesday = 2,
|
|
5
|
+
Wednesday = 3,
|
|
6
|
+
Thursday = 4,
|
|
7
|
+
Friday = 5,
|
|
8
|
+
Saturday = 6
|
|
9
|
+
}
|
|
10
|
+
export declare function parseDate(value: string): Date | undefined;
|
|
11
|
+
export declare function printISODate(date: Date): string;
|
|
12
|
+
export declare function printDate(isoDate: string): string;
|
|
13
|
+
export declare function isEqual(a: Date, b?: Date): boolean;
|
|
14
|
+
export declare function isEqualMonth(a: Date, b: Date): boolean;
|
|
15
|
+
export declare function addDays(date: Date, days: number): Date;
|
|
16
|
+
export declare function addMonths(date: Date, months: number): Date;
|
|
17
|
+
export declare function addYears(date: Date, years: number): Date;
|
|
18
|
+
export declare function startOfWeek(date: Date, firstDayOfWeek?: DaysOfWeek): Date;
|
|
19
|
+
export declare function endOfWeek(date: Date, firstDayOfWeek?: DaysOfWeek): Date;
|
|
20
|
+
export declare function startOfMonth(date: Date): Date;
|
|
21
|
+
export declare function endOfMonth(date: Date): Date;
|
|
22
|
+
export declare function setMonth(date: Date, month: number): Date;
|
|
23
|
+
export declare function setYear(date: Date, year: number): Date;
|
|
24
|
+
export declare function inRange(date: Date, min?: Date, max?: Date): boolean;
|
|
25
|
+
export declare function inYearRange(year: number, min?: number, max?: number): boolean;
|
|
26
|
+
export declare function clamp(date: Date, min?: Date, max?: Date): Date;
|
|
27
|
+
export declare function clampYear(year: number, min?: number, max?: number): number;
|
|
28
|
+
export declare function getViewOfMonth(date: Date, firstDayOfWeek?: DaysOfWeek): Date[];
|
|
29
|
+
export declare function getViewOfYears(start: number, end: number): number[];
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
const DIGIT_DATE_FORMAT = /^\d{6}$/;
|
|
2
|
+
const ISO_DATE_FORMAT = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
3
|
+
const NOR_DATE_FORMAT = /^(\d{2}).(\d{2}).(\d{4})$/;
|
|
4
|
+
const NOR_DATE_FORMAT2 = /^(\d{2})\s(\d{2})\s(\d{4})$/;
|
|
5
|
+
const NOR_DATE_FORMAT3 = /^(\d{2})(\d{2})(\d{4})$/;
|
|
6
|
+
const EU_DATE_FORMAT = /^(\d{2})-(\d{2})-(\d{4})$/;
|
|
7
|
+
const US_DATE_FORMAT = /^(\d{2})\/(\d{2})\/(\d{4})$/;
|
|
8
|
+
const US_DATE_FORMAT2 = /^(\d{2})\/(\d{2})\/(\d{2})$/;
|
|
9
|
+
const replaceAll = (str, old, replacement) => {
|
|
10
|
+
return str.split(old).join(replacement);
|
|
11
|
+
};
|
|
12
|
+
var DaysOfWeek = /* @__PURE__ */ ((DaysOfWeek2) => {
|
|
13
|
+
DaysOfWeek2[DaysOfWeek2["Sunday"] = 0] = "Sunday";
|
|
14
|
+
DaysOfWeek2[DaysOfWeek2["Monday"] = 1] = "Monday";
|
|
15
|
+
DaysOfWeek2[DaysOfWeek2["Tuesday"] = 2] = "Tuesday";
|
|
16
|
+
DaysOfWeek2[DaysOfWeek2["Wednesday"] = 3] = "Wednesday";
|
|
17
|
+
DaysOfWeek2[DaysOfWeek2["Thursday"] = 4] = "Thursday";
|
|
18
|
+
DaysOfWeek2[DaysOfWeek2["Friday"] = 5] = "Friday";
|
|
19
|
+
DaysOfWeek2[DaysOfWeek2["Saturday"] = 6] = "Saturday";
|
|
20
|
+
return DaysOfWeek2;
|
|
21
|
+
})(DaysOfWeek || {});
|
|
22
|
+
function createDate(year, month, day) {
|
|
23
|
+
const dayInt = parseInt(day, 10);
|
|
24
|
+
const monthInt = parseInt(month, 10);
|
|
25
|
+
let yearInt = parseInt(year, 10);
|
|
26
|
+
if (yearInt < 100) {
|
|
27
|
+
yearInt = yearInt + 2e3;
|
|
28
|
+
}
|
|
29
|
+
const isValid = Number.isInteger(yearInt) && Number.isInteger(monthInt) && Number.isInteger(dayInt) && monthInt > 0 && monthInt <= 12 && dayInt > 0 && dayInt <= 31 && yearInt > 0 && yearInt < 1e4;
|
|
30
|
+
if (isValid) {
|
|
31
|
+
try {
|
|
32
|
+
const test = new Date(yearInt, monthInt - 1, dayInt);
|
|
33
|
+
test.getMonth();
|
|
34
|
+
return test;
|
|
35
|
+
} catch {
|
|
36
|
+
console.warn("Silently continuing, but could not create date: " + year + ", " + month + ", " + day);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function cleanDateValue(value) {
|
|
41
|
+
value = value.trim();
|
|
42
|
+
value = replaceAll(value, " ", ".");
|
|
43
|
+
value = replaceAll(value, "-", ".");
|
|
44
|
+
value = replaceAll(value, "..", ".");
|
|
45
|
+
if (value.includes("/") && value.includes(".")) {
|
|
46
|
+
return replaceAll(value, "/", ".");
|
|
47
|
+
}
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
function isDayMonthYearValid(day, month, year) {
|
|
51
|
+
try {
|
|
52
|
+
return Number.parseInt(day) > 0 && Number.parseInt(month) > 0 && Number.parseInt(year) >= 0 && Number.parseInt(year) <= 9999;
|
|
53
|
+
} catch {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function splitDate(value) {
|
|
58
|
+
let [day, month, year] = value.split(".");
|
|
59
|
+
if (day.length === 4) {
|
|
60
|
+
const tmp = day;
|
|
61
|
+
day = year;
|
|
62
|
+
year = tmp;
|
|
63
|
+
month = month.trim();
|
|
64
|
+
}
|
|
65
|
+
if (isDayMonthYearValid(day, month, year))
|
|
66
|
+
return [day, month, year];
|
|
67
|
+
return ["", "", ""];
|
|
68
|
+
}
|
|
69
|
+
function calculateYear(year) {
|
|
70
|
+
if (year.length !== 2)
|
|
71
|
+
return year;
|
|
72
|
+
let inputYear = Number(year);
|
|
73
|
+
const currYear = (/* @__PURE__ */ new Date()).getFullYear();
|
|
74
|
+
const hundredYearPart = Number(currYear.toString().slice(-2));
|
|
75
|
+
if (inputYear > hundredYearPart + 5) {
|
|
76
|
+
inputYear = Number((currYear - 100).toString().slice(0, 2) + inputYear.toString());
|
|
77
|
+
}
|
|
78
|
+
return inputYear.toString();
|
|
79
|
+
}
|
|
80
|
+
function parseDate6Digits(value) {
|
|
81
|
+
if (value.includes("."))
|
|
82
|
+
return void 0;
|
|
83
|
+
if (value.endsWith("19") || value.endsWith("20"))
|
|
84
|
+
return void 0;
|
|
85
|
+
const matches = value.match(DIGIT_DATE_FORMAT);
|
|
86
|
+
if (matches === null || matches.length === 0)
|
|
87
|
+
return void 0;
|
|
88
|
+
const match = matches[0];
|
|
89
|
+
if (!match)
|
|
90
|
+
return void 0;
|
|
91
|
+
const y = calculateYear(match[4] + match[5]);
|
|
92
|
+
return createDate(y, match[2] + match[3], match[0] + match[1]);
|
|
93
|
+
}
|
|
94
|
+
function formatDate8To6Or10(value) {
|
|
95
|
+
if (value.includes("/")) {
|
|
96
|
+
return value;
|
|
97
|
+
}
|
|
98
|
+
if (value.includes(".")) {
|
|
99
|
+
const [day2, month2, year2] = splitDate(value);
|
|
100
|
+
if (!day2 || !month2)
|
|
101
|
+
return value;
|
|
102
|
+
const yearNumber = Number.parseInt(year2);
|
|
103
|
+
if (yearNumber === 19 || yearNumber === 20) {
|
|
104
|
+
return value;
|
|
105
|
+
}
|
|
106
|
+
return replaceAll(value, ".", "");
|
|
107
|
+
}
|
|
108
|
+
const [day, month, year] = [value.substring(0, 2), value.substring(2, 4), value.substring(4, 8)];
|
|
109
|
+
if (isDayMonthYearValid(day, month, year)) {
|
|
110
|
+
return `${day.padStart(2, "0")}.${month.padStart(2, "0")}.${year}`;
|
|
111
|
+
}
|
|
112
|
+
return value;
|
|
113
|
+
}
|
|
114
|
+
function formatDateTo10(value) {
|
|
115
|
+
let delimiter = ".";
|
|
116
|
+
if (value.includes("/"))
|
|
117
|
+
delimiter = "/";
|
|
118
|
+
let [day, month, year] = value.split(delimiter);
|
|
119
|
+
if (day.length === 4) {
|
|
120
|
+
const tmp = day;
|
|
121
|
+
day = year;
|
|
122
|
+
year = tmp;
|
|
123
|
+
month = month.trim();
|
|
124
|
+
}
|
|
125
|
+
year = calculateYear(year);
|
|
126
|
+
return day + delimiter + month + delimiter + year;
|
|
127
|
+
}
|
|
128
|
+
function parseDate(value) {
|
|
129
|
+
if (!value) {
|
|
130
|
+
return void 0;
|
|
131
|
+
}
|
|
132
|
+
if (value.length < 6)
|
|
133
|
+
return void 0;
|
|
134
|
+
value = cleanDateValue(value);
|
|
135
|
+
if (value.length === 8) {
|
|
136
|
+
value = formatDate8To6Or10(value);
|
|
137
|
+
}
|
|
138
|
+
if (value.length === 6)
|
|
139
|
+
return parseDate6Digits(value);
|
|
140
|
+
if (value.length !== 10 && value.length !== 8)
|
|
141
|
+
return void 0;
|
|
142
|
+
value = formatDateTo10(value);
|
|
143
|
+
let date = void 0;
|
|
144
|
+
const isoFormats = [ISO_DATE_FORMAT];
|
|
145
|
+
const norFormats = [NOR_DATE_FORMAT, NOR_DATE_FORMAT2, NOR_DATE_FORMAT3, EU_DATE_FORMAT];
|
|
146
|
+
const usFormats = [US_DATE_FORMAT, US_DATE_FORMAT2];
|
|
147
|
+
isoFormats.forEach((format) => {
|
|
148
|
+
if (date === void 0) {
|
|
149
|
+
const matches = value.match(format);
|
|
150
|
+
if (matches !== null && matches.length > 1) {
|
|
151
|
+
date = createDate(matches[1], matches[2], matches[3]);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
usFormats.forEach((format) => {
|
|
156
|
+
if (date === void 0) {
|
|
157
|
+
const matches = value.match(format);
|
|
158
|
+
if (matches !== null && matches.length > 1) {
|
|
159
|
+
date = createDate(matches[3], matches[1], matches[2]);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
norFormats.forEach((format) => {
|
|
164
|
+
if (date === void 0) {
|
|
165
|
+
const matches = value.match(format);
|
|
166
|
+
if (matches !== null && matches.length > 1) {
|
|
167
|
+
date = createDate(matches[3], matches[2], matches[1]);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
if (date === void 0) {
|
|
172
|
+
console.warn("Date not supported in any regex formats: " + value);
|
|
173
|
+
}
|
|
174
|
+
return date;
|
|
175
|
+
}
|
|
176
|
+
function printISODate(date) {
|
|
177
|
+
if (date === void 0) {
|
|
178
|
+
return "";
|
|
179
|
+
}
|
|
180
|
+
let d = date.getDate().toString(10);
|
|
181
|
+
let m = (date.getMonth() + 1).toString(10);
|
|
182
|
+
const y = date.getFullYear().toString(10);
|
|
183
|
+
if (date.getDate() < 10) {
|
|
184
|
+
d = `0${d}`;
|
|
185
|
+
}
|
|
186
|
+
if (date.getMonth() < 9) {
|
|
187
|
+
m = `0${m}`;
|
|
188
|
+
}
|
|
189
|
+
return `${y}-${m}-${d}`;
|
|
190
|
+
}
|
|
191
|
+
function printDate(isoDate) {
|
|
192
|
+
if (isoDate === void 0 || isoDate == null || isoDate === "") {
|
|
193
|
+
return "";
|
|
194
|
+
}
|
|
195
|
+
if (isoDate.length !== 10) {
|
|
196
|
+
return isoDate;
|
|
197
|
+
}
|
|
198
|
+
const date = parseDate(isoDate);
|
|
199
|
+
if (date === void 0) {
|
|
200
|
+
return isoDate;
|
|
201
|
+
}
|
|
202
|
+
let d = date.getDate().toString(10);
|
|
203
|
+
let m = (date.getMonth() + 1).toString(10);
|
|
204
|
+
const y = date.getFullYear().toString(10);
|
|
205
|
+
if (date.getDate() < 10) {
|
|
206
|
+
d = `0${d}`;
|
|
207
|
+
}
|
|
208
|
+
if (date.getMonth() < 9) {
|
|
209
|
+
m = `0${m}`;
|
|
210
|
+
}
|
|
211
|
+
return `${d}.${m}.${y}`;
|
|
212
|
+
}
|
|
213
|
+
function isEqual(a, b) {
|
|
214
|
+
if (typeof b === "undefined")
|
|
215
|
+
return false;
|
|
216
|
+
if (a == null || b == null)
|
|
217
|
+
return false;
|
|
218
|
+
return isEqualMonth(a, b) && a.getDate() === b.getDate();
|
|
219
|
+
}
|
|
220
|
+
function isEqualMonth(a, b) {
|
|
221
|
+
if (a == null || b == null) {
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth();
|
|
225
|
+
}
|
|
226
|
+
function addDays(date, days) {
|
|
227
|
+
const d = new Date(date);
|
|
228
|
+
d.setDate(d.getDate() + days);
|
|
229
|
+
return d;
|
|
230
|
+
}
|
|
231
|
+
function addMonths(date, months) {
|
|
232
|
+
const d = new Date(date);
|
|
233
|
+
d.setMonth(date.getMonth() + months);
|
|
234
|
+
return d;
|
|
235
|
+
}
|
|
236
|
+
function addYears(date, years) {
|
|
237
|
+
const d = new Date(date);
|
|
238
|
+
d.setFullYear(date.getFullYear() + years);
|
|
239
|
+
return d;
|
|
240
|
+
}
|
|
241
|
+
function startOfWeek(date, firstDayOfWeek = 1) {
|
|
242
|
+
const d = new Date(date);
|
|
243
|
+
const day = d.getDay();
|
|
244
|
+
const diff = (day < firstDayOfWeek ? 7 : 0) + day - firstDayOfWeek;
|
|
245
|
+
d.setDate(d.getDate() - diff);
|
|
246
|
+
return d;
|
|
247
|
+
}
|
|
248
|
+
function endOfWeek(date, firstDayOfWeek = 1) {
|
|
249
|
+
const d = new Date(date);
|
|
250
|
+
const day = d.getDay();
|
|
251
|
+
const diff = (day < firstDayOfWeek ? -7 : 0) + 6 - (day - firstDayOfWeek);
|
|
252
|
+
d.setDate(d.getDate() + diff);
|
|
253
|
+
return d;
|
|
254
|
+
}
|
|
255
|
+
function startOfMonth(date) {
|
|
256
|
+
return new Date(date.getFullYear(), date.getMonth(), 1);
|
|
257
|
+
}
|
|
258
|
+
function endOfMonth(date) {
|
|
259
|
+
return new Date(date.getFullYear(), date.getMonth() + 1, 0);
|
|
260
|
+
}
|
|
261
|
+
function setMonth(date, month) {
|
|
262
|
+
const d = new Date(date);
|
|
263
|
+
d.setMonth(month);
|
|
264
|
+
return d;
|
|
265
|
+
}
|
|
266
|
+
function setYear(date, year) {
|
|
267
|
+
const d = new Date(date);
|
|
268
|
+
d.setFullYear(year);
|
|
269
|
+
return d;
|
|
270
|
+
}
|
|
271
|
+
function inRange(date, min, max) {
|
|
272
|
+
return clamp(date, min, max) === date;
|
|
273
|
+
}
|
|
274
|
+
function inYearRange(year, min, max) {
|
|
275
|
+
return clampYear(year, min, max) === year;
|
|
276
|
+
}
|
|
277
|
+
function clamp(date, min, max) {
|
|
278
|
+
const time = date.getTime();
|
|
279
|
+
if (min && min instanceof Date && time < min.getTime()) {
|
|
280
|
+
return min;
|
|
281
|
+
}
|
|
282
|
+
if (max && max instanceof Date && time > max.getTime()) {
|
|
283
|
+
return max;
|
|
284
|
+
}
|
|
285
|
+
return date;
|
|
286
|
+
}
|
|
287
|
+
function clampYear(year, min, max) {
|
|
288
|
+
if (typeof min === "number" && year < min) {
|
|
289
|
+
return min;
|
|
290
|
+
}
|
|
291
|
+
if (typeof max === "number" && year > max) {
|
|
292
|
+
return max;
|
|
293
|
+
}
|
|
294
|
+
return year;
|
|
295
|
+
}
|
|
296
|
+
function getDaysInRange(start, end) {
|
|
297
|
+
const days = [];
|
|
298
|
+
let current = start;
|
|
299
|
+
while (!isEqual(current, end)) {
|
|
300
|
+
days.push(current);
|
|
301
|
+
current = addDays(current, 1);
|
|
302
|
+
}
|
|
303
|
+
days.push(current);
|
|
304
|
+
return days;
|
|
305
|
+
}
|
|
306
|
+
function getViewOfMonth(date, firstDayOfWeek = 1) {
|
|
307
|
+
const start = startOfWeek(startOfMonth(date), firstDayOfWeek);
|
|
308
|
+
const end = endOfWeek(endOfMonth(date), firstDayOfWeek);
|
|
309
|
+
return getDaysInRange(start, end);
|
|
310
|
+
}
|
|
311
|
+
function getViewOfYears(start, end) {
|
|
312
|
+
const years = [];
|
|
313
|
+
for (let i = start; i <= end; i++) {
|
|
314
|
+
years.push(i);
|
|
315
|
+
}
|
|
316
|
+
return years;
|
|
317
|
+
}
|
|
318
|
+
export {
|
|
319
|
+
DaysOfWeek,
|
|
320
|
+
addDays,
|
|
321
|
+
addMonths,
|
|
322
|
+
addYears,
|
|
323
|
+
clamp,
|
|
324
|
+
clampYear,
|
|
325
|
+
endOfMonth,
|
|
326
|
+
endOfWeek,
|
|
327
|
+
getViewOfMonth,
|
|
328
|
+
getViewOfYears,
|
|
329
|
+
inRange,
|
|
330
|
+
inYearRange,
|
|
331
|
+
isEqual,
|
|
332
|
+
isEqualMonth,
|
|
333
|
+
parseDate,
|
|
334
|
+
printDate,
|
|
335
|
+
printISODate,
|
|
336
|
+
setMonth,
|
|
337
|
+
setYear,
|
|
338
|
+
startOfMonth,
|
|
339
|
+
startOfWeek
|
|
340
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|