@rowsncolumns/utils 9.2.41 → 9.2.43
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../formatter.ts"],"names":[],"mappings":"AAiBA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,GAAG,SAAS,GAAG,IAAI,KAAG,OASlE,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,SAAS,MAAM,GAAG,SAAS,GAAG,IAAI,KACjC,OAWF,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,GAAG,SAAS,GAAG,IAAI,KAAG,OAWlE,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,GAAG,SAAS,GAAG,IAAI,KAAG,OAOlE,CAAC;AAMF;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,GAAI,SAAS,MAAM,KAAG,OA4B1D,CAAC;
|
|
1
|
+
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../formatter.ts"],"names":[],"mappings":"AAiBA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,GAAG,SAAS,GAAG,IAAI,KAAG,OASlE,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,SAAS,MAAM,GAAG,SAAS,GAAG,IAAI,KACjC,OAWF,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,GAAG,SAAS,GAAG,IAAI,KAAG,OAWlE,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,GAAG,SAAS,GAAG,IAAI,KAAG,OAOlE,CAAC;AAMF;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,GAAI,SAAS,MAAM,KAAG,OA4B1D,CAAC;AA+LF;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAAI,SAAS,MAAM,KAAG,MAAM,GAAG,SA4C9D,CAAC;AAiIF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,sBAAsB,GACjC,SAAS,MAAM,EACf,SAAS,MAAM,KACd,MAAM,GAAG,SAiBX,CAAC;AAiBF,eAAO,MAAM,SAAS,GACpB,SAAS,MAAM,EACf,OAAO,GAAG,EACV,SAAS,MAAM,KACd,MA0CF,CAAC;AAmLF,eAAO,MAAM,cAAc,GACzB,SAAS,MAAM,EACf,OAAO,GAAG,KACT,MAAM,GAAG,SAoBX,CAAC"}
|
package/dist/cjs/formatter.js
CHANGED
|
@@ -144,6 +144,69 @@ var intlMonthNames = function (locale, options) {
|
|
|
144
144
|
.find(function (part) { return part.type === "month"; })) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : "";
|
|
145
145
|
});
|
|
146
146
|
};
|
|
147
|
+
var intlRegisteredLocales = new Set();
|
|
148
|
+
/**
|
|
149
|
+
* numfmt ships name tables for a fixed set of languages; a tag it does not know
|
|
150
|
+
* (et, ms, nn, …) silently renders English month/weekday names and en-US
|
|
151
|
+
* separators. Excel and `Intl.DateTimeFormat` localize every locale, so an
|
|
152
|
+
* unknown tag gets a numfmt locale built from Intl on first use: separators
|
|
153
|
+
* from `Intl.NumberFormat`, the in-date month names (numfmt's single table is
|
|
154
|
+
* the form used beside a day number — see `getStandaloneMonthLocale`), the
|
|
155
|
+
* in-date weekday names (the form `dateStyle: "full"` shows) and the AM/PM
|
|
156
|
+
* designators. Tags Intl itself does not know keep numfmt's fallback.
|
|
157
|
+
*/
|
|
158
|
+
var ensureNumfmtLocale = function (locale) {
|
|
159
|
+
var _a, _b;
|
|
160
|
+
if (intlRegisteredLocales.has(locale))
|
|
161
|
+
return;
|
|
162
|
+
intlRegisteredLocales.add(locale);
|
|
163
|
+
try {
|
|
164
|
+
if ((0, numfmt_1.getLocale)(locale))
|
|
165
|
+
return;
|
|
166
|
+
var canonical = Intl.DateTimeFormat.supportedLocalesOf([locale])[0];
|
|
167
|
+
if (!canonical)
|
|
168
|
+
return;
|
|
169
|
+
var numberParts_1 = new Intl.NumberFormat(locale).formatToParts(1234567.5);
|
|
170
|
+
var part = function (type) { var _a; return (_a = numberParts_1.find(function (p) { return p.type === type; })) === null || _a === void 0 ? void 0 : _a.value; };
|
|
171
|
+
var weekdayNames = function (weekday) {
|
|
172
|
+
// 2024-01-07 was a Sunday; numfmt indexes `dddd[0]` as Sunday.
|
|
173
|
+
var fmt = new Intl.DateTimeFormat(locale, {
|
|
174
|
+
weekday: weekday,
|
|
175
|
+
day: "numeric",
|
|
176
|
+
month: "long",
|
|
177
|
+
year: "numeric",
|
|
178
|
+
timeZone: "UTC",
|
|
179
|
+
});
|
|
180
|
+
return Array.from({ length: 7 }, function (_, i) {
|
|
181
|
+
var _a, _b;
|
|
182
|
+
return (_b = (_a = fmt
|
|
183
|
+
.formatToParts(new Date(Date.UTC(2024, 0, 7 + i)))
|
|
184
|
+
.find(function (p) { return p.type === "weekday"; })) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : "";
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
var dayPeriod = function (hour) {
|
|
188
|
+
var _a;
|
|
189
|
+
return (_a = new Intl.DateTimeFormat(locale, {
|
|
190
|
+
hour: "numeric",
|
|
191
|
+
hour12: true,
|
|
192
|
+
timeZone: "UTC",
|
|
193
|
+
})
|
|
194
|
+
.formatToParts(new Date(Date.UTC(2024, 0, 7, hour)))
|
|
195
|
+
.find(function (p) { return p.type === "dayPeriod"; })) === null || _a === void 0 ? void 0 : _a.value;
|
|
196
|
+
};
|
|
197
|
+
var dateParts = new Intl.DateTimeFormat(locale, {
|
|
198
|
+
timeZone: "UTC",
|
|
199
|
+
}).formatToParts(new Date(Date.UTC(2024, 0, 7)));
|
|
200
|
+
var monthIndex = dateParts.findIndex(function (p) { return p.type === "month"; });
|
|
201
|
+
var dayIndex = dateParts.findIndex(function (p) { return p.type === "day"; });
|
|
202
|
+
var am = dayPeriod(9);
|
|
203
|
+
var pm = dayPeriod(21);
|
|
204
|
+
(0, numfmt_1.addLocale)(tslib_1.__assign(tslib_1.__assign({ group: (_a = part("group")) !== null && _a !== void 0 ? _a : "\u00a0", decimal: (_b = part("decimal")) !== null && _b !== void 0 ? _b : ".", mmmm: intlMonthNames(locale, { day: "numeric", month: "long" }), mmm: intlMonthNames(locale, { day: "numeric", month: "short" }), dddd: weekdayNames("long"), ddd: weekdayNames("short") }, (am && pm && am !== pm ? { ampm: [am, pm] } : {})), { preferMDY: monthIndex >= 0 && dayIndex >= 0 && monthIndex < dayIndex }), locale);
|
|
205
|
+
}
|
|
206
|
+
catch (_c) {
|
|
207
|
+
// Malformed tag: numfmt keeps its own fallback.
|
|
208
|
+
}
|
|
209
|
+
};
|
|
147
210
|
var standaloneMonthLocales = new Map();
|
|
148
211
|
/**
|
|
149
212
|
* numfmt ships one month-name table per locale: the form used beside a day
|
|
@@ -467,6 +530,8 @@ var withWorkbookSeparatorsCached = function (code, locale) {
|
|
|
467
530
|
};
|
|
468
531
|
var ssfFormat = function (pattern, value, locale) {
|
|
469
532
|
try {
|
|
533
|
+
if (locale)
|
|
534
|
+
ensureNumfmtLocale(locale);
|
|
470
535
|
var shortAmPm = shortAmPmPatternCache.get(pattern);
|
|
471
536
|
if (shortAmPm === undefined && !shortAmPmPatternCache.has(pattern)) {
|
|
472
537
|
shortAmPm = (0, exports.withShortAmPmMarker)(pattern);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../formatter.ts"],"names":[],"mappings":"AAiBA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,GAAG,SAAS,GAAG,IAAI,KAAG,OASlE,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,SAAS,MAAM,GAAG,SAAS,GAAG,IAAI,KACjC,OAWF,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,GAAG,SAAS,GAAG,IAAI,KAAG,OAWlE,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,GAAG,SAAS,GAAG,IAAI,KAAG,OAOlE,CAAC;AAMF;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,GAAI,SAAS,MAAM,KAAG,OA4B1D,CAAC;
|
|
1
|
+
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../formatter.ts"],"names":[],"mappings":"AAiBA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,GAAG,SAAS,GAAG,IAAI,KAAG,OASlE,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,SAAS,MAAM,GAAG,SAAS,GAAG,IAAI,KACjC,OAWF,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,GAAG,SAAS,GAAG,IAAI,KAAG,OAWlE,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,GAAG,SAAS,GAAG,IAAI,KAAG,OAOlE,CAAC;AAMF;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,GAAI,SAAS,MAAM,KAAG,OA4B1D,CAAC;AA+LF;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAAI,SAAS,MAAM,KAAG,MAAM,GAAG,SA4C9D,CAAC;AAiIF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,sBAAsB,GACjC,SAAS,MAAM,EACf,SAAS,MAAM,KACd,MAAM,GAAG,SAiBX,CAAC;AAiBF,eAAO,MAAM,SAAS,GACpB,SAAS,MAAM,EACf,OAAO,GAAG,EACV,SAAS,MAAM,KACd,MA0CF,CAAC;AAmLF,eAAO,MAAM,cAAc,GACzB,SAAS,MAAM,EACf,OAAO,GAAG,KACT,MAAM,GAAG,SAoBX,CAAC"}
|
package/dist/esm/formatter.js
CHANGED
|
@@ -132,6 +132,71 @@ const intlMonthNames = (locale, options) => {
|
|
|
132
132
|
.formatToParts(new Date(Date.UTC(2020, month, 1)))
|
|
133
133
|
.find((part) => part.type === "month")?.value ?? "");
|
|
134
134
|
};
|
|
135
|
+
const intlRegisteredLocales = new Set();
|
|
136
|
+
/**
|
|
137
|
+
* numfmt ships name tables for a fixed set of languages; a tag it does not know
|
|
138
|
+
* (et, ms, nn, …) silently renders English month/weekday names and en-US
|
|
139
|
+
* separators. Excel and `Intl.DateTimeFormat` localize every locale, so an
|
|
140
|
+
* unknown tag gets a numfmt locale built from Intl on first use: separators
|
|
141
|
+
* from `Intl.NumberFormat`, the in-date month names (numfmt's single table is
|
|
142
|
+
* the form used beside a day number — see `getStandaloneMonthLocale`), the
|
|
143
|
+
* in-date weekday names (the form `dateStyle: "full"` shows) and the AM/PM
|
|
144
|
+
* designators. Tags Intl itself does not know keep numfmt's fallback.
|
|
145
|
+
*/
|
|
146
|
+
const ensureNumfmtLocale = (locale) => {
|
|
147
|
+
if (intlRegisteredLocales.has(locale))
|
|
148
|
+
return;
|
|
149
|
+
intlRegisteredLocales.add(locale);
|
|
150
|
+
try {
|
|
151
|
+
if (getLocale(locale))
|
|
152
|
+
return;
|
|
153
|
+
const canonical = Intl.DateTimeFormat.supportedLocalesOf([locale])[0];
|
|
154
|
+
if (!canonical)
|
|
155
|
+
return;
|
|
156
|
+
const numberParts = new Intl.NumberFormat(locale).formatToParts(1234567.5);
|
|
157
|
+
const part = (type) => numberParts.find((p) => p.type === type)?.value;
|
|
158
|
+
const weekdayNames = (weekday) => {
|
|
159
|
+
// 2024-01-07 was a Sunday; numfmt indexes `dddd[0]` as Sunday.
|
|
160
|
+
const fmt = new Intl.DateTimeFormat(locale, {
|
|
161
|
+
weekday,
|
|
162
|
+
day: "numeric",
|
|
163
|
+
month: "long",
|
|
164
|
+
year: "numeric",
|
|
165
|
+
timeZone: "UTC",
|
|
166
|
+
});
|
|
167
|
+
return Array.from({ length: 7 }, (_, i) => fmt
|
|
168
|
+
.formatToParts(new Date(Date.UTC(2024, 0, 7 + i)))
|
|
169
|
+
.find((p) => p.type === "weekday")?.value ?? "");
|
|
170
|
+
};
|
|
171
|
+
const dayPeriod = (hour) => new Intl.DateTimeFormat(locale, {
|
|
172
|
+
hour: "numeric",
|
|
173
|
+
hour12: true,
|
|
174
|
+
timeZone: "UTC",
|
|
175
|
+
})
|
|
176
|
+
.formatToParts(new Date(Date.UTC(2024, 0, 7, hour)))
|
|
177
|
+
.find((p) => p.type === "dayPeriod")?.value;
|
|
178
|
+
const dateParts = new Intl.DateTimeFormat(locale, {
|
|
179
|
+
timeZone: "UTC",
|
|
180
|
+
}).formatToParts(new Date(Date.UTC(2024, 0, 7)));
|
|
181
|
+
const monthIndex = dateParts.findIndex((p) => p.type === "month");
|
|
182
|
+
const dayIndex = dateParts.findIndex((p) => p.type === "day");
|
|
183
|
+
const am = dayPeriod(9);
|
|
184
|
+
const pm = dayPeriod(21);
|
|
185
|
+
addLocale({
|
|
186
|
+
group: part("group") ?? "\u00a0",
|
|
187
|
+
decimal: part("decimal") ?? ".",
|
|
188
|
+
mmmm: intlMonthNames(locale, { day: "numeric", month: "long" }),
|
|
189
|
+
mmm: intlMonthNames(locale, { day: "numeric", month: "short" }),
|
|
190
|
+
dddd: weekdayNames("long"),
|
|
191
|
+
ddd: weekdayNames("short"),
|
|
192
|
+
...(am && pm && am !== pm ? { ampm: [am, pm] } : {}),
|
|
193
|
+
preferMDY: monthIndex >= 0 && dayIndex >= 0 && monthIndex < dayIndex,
|
|
194
|
+
}, locale);
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
// Malformed tag: numfmt keeps its own fallback.
|
|
198
|
+
}
|
|
199
|
+
};
|
|
135
200
|
const standaloneMonthLocales = new Map();
|
|
136
201
|
/**
|
|
137
202
|
* numfmt ships one month-name table per locale: the form used beside a day
|
|
@@ -434,6 +499,8 @@ const withWorkbookSeparatorsCached = (code, locale) => {
|
|
|
434
499
|
};
|
|
435
500
|
export const ssfFormat = (pattern, value, locale) => {
|
|
436
501
|
try {
|
|
502
|
+
if (locale)
|
|
503
|
+
ensureNumfmtLocale(locale);
|
|
437
504
|
let shortAmPm = shortAmPmPatternCache.get(pattern);
|
|
438
505
|
if (shortAmPm === undefined && !shortAmPmPatternCache.has(pattern)) {
|
|
439
506
|
shortAmPm = withShortAmPmMarker(pattern);
|