@choice-ui/react 1.6.0 → 1.6.1
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.
|
@@ -1222,54 +1222,71 @@ function parseCompositeFormat(input, format10, locale) {
|
|
|
1222
1222
|
}
|
|
1223
1223
|
}
|
|
1224
1224
|
function removeWeekdayFromFormat(format10) {
|
|
1225
|
-
return format10.replace(/\s*[eEic]{1,4}\s*/g, "").replace(/\s+/g, " ").replace(/\s*([,,、])\s*/g, "$1").trim();
|
|
1225
|
+
return format10.replace(/\s*[eEic]{1,4}\s*/g, "").replace(/MMM(?!M)/g, "M月").replace(/\s+/g, " ").replace(/\s*([,,、])\s*/g, "$1").trim();
|
|
1226
1226
|
}
|
|
1227
1227
|
function removeWeekdayFromInput(input, locale) {
|
|
1228
1228
|
try {
|
|
1229
|
-
const
|
|
1230
|
-
|
|
1231
|
-
|
|
1229
|
+
const { longNames, shortNames } = generateWeekdayNames2(locale);
|
|
1230
|
+
let result = input;
|
|
1231
|
+
if (longNames.length > 0) {
|
|
1232
|
+
const sortedLongNames = longNames.sort((a, b) => b.length - a.length);
|
|
1233
|
+
const longPattern = new RegExp(`\\s*(${sortedLongNames.join("|")})\\s*`, "gi");
|
|
1234
|
+
result = result.replace(longPattern, " ");
|
|
1235
|
+
}
|
|
1236
|
+
if (shortNames.length > 0) {
|
|
1237
|
+
const sortedShortNames = shortNames.sort((a, b) => b.length - a.length);
|
|
1238
|
+
const singleCharNames = sortedShortNames.filter((name) => name.length === 1);
|
|
1239
|
+
const multiCharNames = sortedShortNames.filter((name) => name.length > 1);
|
|
1240
|
+
if (multiCharNames.length > 0) {
|
|
1241
|
+
const multiPattern = new RegExp(`\\s*(${multiCharNames.join("|")})\\s*`, "gi");
|
|
1242
|
+
result = result.replace(multiPattern, " ");
|
|
1243
|
+
}
|
|
1244
|
+
if (singleCharNames.length > 0) {
|
|
1245
|
+
const singlePattern = new RegExp(
|
|
1246
|
+
`([((「【])(${singleCharNames.join("|")})([))」】])`,
|
|
1247
|
+
"gi"
|
|
1248
|
+
);
|
|
1249
|
+
result = result.replace(singlePattern, "$1$3");
|
|
1250
|
+
}
|
|
1232
1251
|
}
|
|
1233
|
-
|
|
1234
|
-
const pattern = new RegExp(`\\s*(${sortedNames.join("|")})\\s*`, "gi");
|
|
1235
|
-
return input.replace(pattern, "").replace(/\s+/g, " ").trim();
|
|
1252
|
+
return result.replace(/\s+/g, " ").trim();
|
|
1236
1253
|
} catch {
|
|
1237
1254
|
return input.replace(/\s*(星期[一二三四五六日天]|周[一二三四五六日天])\s*/g, "").replace(/\s+/g, " ").trim();
|
|
1238
1255
|
}
|
|
1239
1256
|
}
|
|
1240
1257
|
function generateWeekdayNames2(locale) {
|
|
1241
|
-
const
|
|
1258
|
+
const longNames = [];
|
|
1259
|
+
const shortNames = [];
|
|
1242
1260
|
try {
|
|
1243
1261
|
const baseDate = new Date(2024, 0, 7);
|
|
1244
1262
|
for (let i = 0; i < 7; i++) {
|
|
1245
1263
|
const currentDate = new Date(baseDate);
|
|
1246
1264
|
currentDate.setDate(baseDate.getDate() + i);
|
|
1247
1265
|
const fullName = format(currentDate, "eeee", { locale });
|
|
1248
|
-
if (fullName && fullName !== "eeee") {
|
|
1249
|
-
|
|
1266
|
+
if (fullName && fullName !== "eeee" && !fullName.includes("e")) {
|
|
1267
|
+
longNames.push(fullName);
|
|
1250
1268
|
}
|
|
1251
1269
|
const shortName = format(currentDate, "eee", { locale });
|
|
1252
|
-
if (shortName && shortName !== "eee" && shortName !== fullName) {
|
|
1253
|
-
|
|
1254
|
-
}
|
|
1255
|
-
const veryShortName = format(currentDate, "ee", { locale });
|
|
1256
|
-
if (veryShortName && veryShortName !== "ee" && veryShortName !== shortName && veryShortName !== fullName) {
|
|
1257
|
-
names.push(veryShortName);
|
|
1270
|
+
if (shortName && shortName !== "eee" && shortName !== fullName && !shortName.includes("e")) {
|
|
1271
|
+
shortNames.push(shortName);
|
|
1258
1272
|
}
|
|
1259
1273
|
const localeKey = getLocaleKey(locale);
|
|
1260
|
-
if (localeKey === "zh") {
|
|
1261
|
-
const weekFormat =
|
|
1274
|
+
if (localeKey === "zh" && fullName) {
|
|
1275
|
+
const weekFormat = fullName.replace("星期", "周");
|
|
1262
1276
|
if (weekFormat !== fullName) {
|
|
1263
|
-
|
|
1277
|
+
shortNames.push(weekFormat);
|
|
1264
1278
|
}
|
|
1265
1279
|
}
|
|
1266
1280
|
}
|
|
1267
|
-
|
|
1268
|
-
(name) => name && name.length > 0 &&
|
|
1269
|
-
name !== "Invalid Date"
|
|
1281
|
+
const filterNames = (names) => [...new Set(names)].filter(
|
|
1282
|
+
(name) => name && name.length > 0 && !/^\d+$/.test(name) && name !== "Invalid Date"
|
|
1270
1283
|
);
|
|
1284
|
+
return {
|
|
1285
|
+
longNames: filterNames(longNames),
|
|
1286
|
+
shortNames: filterNames(shortNames)
|
|
1287
|
+
};
|
|
1271
1288
|
} catch {
|
|
1272
|
-
return [];
|
|
1289
|
+
return { longNames: [], shortNames: [] };
|
|
1273
1290
|
}
|
|
1274
1291
|
}
|
|
1275
1292
|
function parseInvalidFormattedDate(input, targetFormat, locale) {
|
|
@@ -501,54 +501,71 @@ function parseCompositeFormat(input, format2, locale) {
|
|
|
501
501
|
}
|
|
502
502
|
}
|
|
503
503
|
function removeWeekdayFromFormat(format2) {
|
|
504
|
-
return format2.replace(/\s*[eEic]{1,4}\s*/g, "").replace(/\s+/g, " ").replace(/\s*([,,、])\s*/g, "$1").trim();
|
|
504
|
+
return format2.replace(/\s*[eEic]{1,4}\s*/g, "").replace(/MMM(?!M)/g, "M月").replace(/\s+/g, " ").replace(/\s*([,,、])\s*/g, "$1").trim();
|
|
505
505
|
}
|
|
506
506
|
function removeWeekdayFromInput(input, locale) {
|
|
507
507
|
try {
|
|
508
|
-
const
|
|
509
|
-
|
|
510
|
-
|
|
508
|
+
const { longNames, shortNames } = generateWeekdayNames(locale);
|
|
509
|
+
let result = input;
|
|
510
|
+
if (longNames.length > 0) {
|
|
511
|
+
const sortedLongNames = longNames.sort((a, b) => b.length - a.length);
|
|
512
|
+
const longPattern = new RegExp(`\\s*(${sortedLongNames.join("|")})\\s*`, "gi");
|
|
513
|
+
result = result.replace(longPattern, " ");
|
|
511
514
|
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
+
if (shortNames.length > 0) {
|
|
516
|
+
const sortedShortNames = shortNames.sort((a, b) => b.length - a.length);
|
|
517
|
+
const singleCharNames = sortedShortNames.filter((name) => name.length === 1);
|
|
518
|
+
const multiCharNames = sortedShortNames.filter((name) => name.length > 1);
|
|
519
|
+
if (multiCharNames.length > 0) {
|
|
520
|
+
const multiPattern = new RegExp(`\\s*(${multiCharNames.join("|")})\\s*`, "gi");
|
|
521
|
+
result = result.replace(multiPattern, " ");
|
|
522
|
+
}
|
|
523
|
+
if (singleCharNames.length > 0) {
|
|
524
|
+
const singlePattern = new RegExp(
|
|
525
|
+
`([((「【])(${singleCharNames.join("|")})([))」】])`,
|
|
526
|
+
"gi"
|
|
527
|
+
);
|
|
528
|
+
result = result.replace(singlePattern, "$1$3");
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
return result.replace(/\s+/g, " ").trim();
|
|
515
532
|
} catch {
|
|
516
533
|
return input.replace(/\s*(星期[一二三四五六日天]|周[一二三四五六日天])\s*/g, "").replace(/\s+/g, " ").trim();
|
|
517
534
|
}
|
|
518
535
|
}
|
|
519
536
|
function generateWeekdayNames(locale) {
|
|
520
|
-
const
|
|
537
|
+
const longNames = [];
|
|
538
|
+
const shortNames = [];
|
|
521
539
|
try {
|
|
522
540
|
const baseDate = new Date(2024, 0, 7);
|
|
523
541
|
for (let i = 0; i < 7; i++) {
|
|
524
542
|
const currentDate = new Date(baseDate);
|
|
525
543
|
currentDate.setDate(baseDate.getDate() + i);
|
|
526
544
|
const fullName = format(currentDate, "eeee", { locale });
|
|
527
|
-
if (fullName && fullName !== "eeee") {
|
|
528
|
-
|
|
545
|
+
if (fullName && fullName !== "eeee" && !fullName.includes("e")) {
|
|
546
|
+
longNames.push(fullName);
|
|
529
547
|
}
|
|
530
548
|
const shortName = format(currentDate, "eee", { locale });
|
|
531
|
-
if (shortName && shortName !== "eee" && shortName !== fullName) {
|
|
532
|
-
|
|
533
|
-
}
|
|
534
|
-
const veryShortName = format(currentDate, "ee", { locale });
|
|
535
|
-
if (veryShortName && veryShortName !== "ee" && veryShortName !== shortName && veryShortName !== fullName) {
|
|
536
|
-
names.push(veryShortName);
|
|
549
|
+
if (shortName && shortName !== "eee" && shortName !== fullName && !shortName.includes("e")) {
|
|
550
|
+
shortNames.push(shortName);
|
|
537
551
|
}
|
|
538
552
|
const localeKey = getLocaleKey(locale);
|
|
539
|
-
if (localeKey === "zh") {
|
|
540
|
-
const weekFormat =
|
|
553
|
+
if (localeKey === "zh" && fullName) {
|
|
554
|
+
const weekFormat = fullName.replace("星期", "周");
|
|
541
555
|
if (weekFormat !== fullName) {
|
|
542
|
-
|
|
556
|
+
shortNames.push(weekFormat);
|
|
543
557
|
}
|
|
544
558
|
}
|
|
545
559
|
}
|
|
546
|
-
|
|
547
|
-
(name) => name && name.length > 0 &&
|
|
548
|
-
name !== "Invalid Date"
|
|
560
|
+
const filterNames = (names) => [...new Set(names)].filter(
|
|
561
|
+
(name) => name && name.length > 0 && !/^\d+$/.test(name) && name !== "Invalid Date"
|
|
549
562
|
);
|
|
563
|
+
return {
|
|
564
|
+
longNames: filterNames(longNames),
|
|
565
|
+
shortNames: filterNames(shortNames)
|
|
566
|
+
};
|
|
550
567
|
} catch {
|
|
551
|
-
return [];
|
|
568
|
+
return { longNames: [], shortNames: [] };
|
|
552
569
|
}
|
|
553
570
|
}
|
|
554
571
|
function parseInvalidFormattedDate(input, targetFormat, locale) {
|
package/package.json
CHANGED