@rowsncolumns/utils 9.2.38 → 9.2.40
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/cjs/excel-number-format.d.ts +128 -0
- package/dist/cjs/excel-number-format.d.ts.map +1 -0
- package/dist/cjs/excel-number-format.js +659 -0
- package/dist/cjs/formatter.d.ts +8 -0
- package/dist/cjs/formatter.d.ts.map +1 -1
- package/dist/cjs/formatter.js +151 -2
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +3 -0
- package/dist/cjs/keyboard.d.ts +28 -0
- package/dist/cjs/keyboard.d.ts.map +1 -0
- package/dist/cjs/keyboard.js +67 -0
- package/dist/cjs/sheet-span.d.ts +13 -0
- package/dist/cjs/sheet-span.d.ts.map +1 -0
- package/dist/cjs/sheet-span.js +24 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/excel-number-format.d.ts +128 -0
- package/dist/esm/excel-number-format.d.ts.map +1 -0
- package/dist/esm/excel-number-format.js +640 -0
- package/dist/esm/formatter.d.ts +8 -0
- package/dist/esm/formatter.d.ts.map +1 -1
- package/dist/esm/formatter.js +135 -1
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +3 -0
- package/dist/esm/keyboard.d.ts +28 -0
- package/dist/esm/keyboard.d.ts.map +1 -0
- package/dist/esm/keyboard.js +62 -0
- package/dist/esm/sheet-span.d.ts +13 -0
- package/dist/esm/sheet-span.d.ts.map +1 -0
- package/dist/esm/sheet-span.js +20 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +2 -2
package/dist/cjs/formatter.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ssfFormatColor = exports.ssfFormat = exports.isStandaloneMonthPattern = exports.isTextPattern = exports.isTimePattern = exports.isDateTimePattern = exports.isDatePattern = void 0;
|
|
3
|
+
exports.ssfFormatColor = exports.ssfFormat = exports.withShortAmPmMarker = exports.isStandaloneMonthPattern = exports.isTextPattern = exports.isTimePattern = exports.isDateTimePattern = exports.isDatePattern = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var numfmt_1 = require("numfmt");
|
|
6
6
|
var colors_1 = require("./colors");
|
|
7
|
+
var excel_number_format_1 = require("./excel-number-format");
|
|
7
8
|
/**
|
|
8
9
|
* Pattern-based type inference (Excel parity). xlsx files routinely carry
|
|
9
10
|
* a `numberFormat.pattern` without an accompanying `type` field — these
|
|
@@ -188,12 +189,160 @@ var localeForPattern = function (pattern, locale) {
|
|
|
188
189
|
}
|
|
189
190
|
return standalone ? ((_a = getStandaloneMonthLocale(locale)) !== null && _a !== void 0 ? _a : locale) : locale;
|
|
190
191
|
};
|
|
192
|
+
var shortAmPmLocales = new Map();
|
|
193
|
+
/**
|
|
194
|
+
* Excel's `A/P` renders one letter (`6:00 P`) in every locale, but numfmt
|
|
195
|
+
* honours the short form only when no locale is passed — under a locale it
|
|
196
|
+
* emits that locale's full designator (`6:00 PM`). Patterns with `A/P` render
|
|
197
|
+
* under a companion locale whose AM/PM designators are `A`/`P`. `locale` is a
|
|
198
|
+
* BCP 47 tag or an Excel LCID (`409`), as numfmt accepts both.
|
|
199
|
+
*/
|
|
200
|
+
var getShortAmPmLocale = function (locale) {
|
|
201
|
+
var _a;
|
|
202
|
+
var cached = shortAmPmLocales.get(locale);
|
|
203
|
+
if (cached !== undefined)
|
|
204
|
+
return cached;
|
|
205
|
+
var overlay = locale;
|
|
206
|
+
try {
|
|
207
|
+
overlay = "ampm_".concat(locale.replace(/[^a-z\d]/gi, ""));
|
|
208
|
+
(0, numfmt_1.addLocale)(tslib_1.__assign(tslib_1.__assign({}, ((_a = (0, numfmt_1.getLocale)(locale)) !== null && _a !== void 0 ? _a : {})), { ampm: ["A", "P"] }), overlay);
|
|
209
|
+
}
|
|
210
|
+
catch (_b) {
|
|
211
|
+
overlay = locale;
|
|
212
|
+
}
|
|
213
|
+
shortAmPmLocales.set(locale, overlay);
|
|
214
|
+
return overlay;
|
|
215
|
+
};
|
|
216
|
+
/**
|
|
217
|
+
* An Excel `[$-LCID]` / `[$symbol-LCID]` token pins the section's locale, and
|
|
218
|
+
* numfmt resolves it to that LCID's own table — ahead of the companion locale
|
|
219
|
+
* `ssfFormat` passes, so `[$-409]h:mm A/P` would still render `6:00 PM`.
|
|
220
|
+
* Re-point a known LCID or tag at its companion (`$-409` → `$-ampm_409`); an
|
|
221
|
+
* LCID numfmt does not know (`F400`) or one carrying calendar bits stays as
|
|
222
|
+
* written.
|
|
223
|
+
*/
|
|
224
|
+
var shortAmPmLocaleToken = function (token) {
|
|
225
|
+
var dash = token.indexOf("-");
|
|
226
|
+
if (dash < 0)
|
|
227
|
+
return token;
|
|
228
|
+
var code = token.slice(dash + 1);
|
|
229
|
+
var wincode = Number.parseInt(code, 16);
|
|
230
|
+
if (Number.isFinite(wincode) && wincode & 0xff0000)
|
|
231
|
+
return token;
|
|
232
|
+
if (!(0, numfmt_1.getLocale)(code))
|
|
233
|
+
return token;
|
|
234
|
+
return "".concat(token.slice(0, dash + 1)).concat(getShortAmPmLocale(code));
|
|
235
|
+
};
|
|
236
|
+
/**
|
|
237
|
+
* Does the pattern carry Excel's short `A/P` marker outside quoted literals,
|
|
238
|
+
* bracket directives and escapes? Returns the pattern with the marker
|
|
239
|
+
* upper-cased (Excel accepts `a/p` and renders it `A`/`P`; numfmt only
|
|
240
|
+
* tokenizes `A/P`) and its `[$-LCID]` tokens re-pointed at the companion
|
|
241
|
+
* `A`/`P` locale, or `undefined` when there is none.
|
|
242
|
+
*/
|
|
243
|
+
var withShortAmPmMarker = function (pattern) {
|
|
244
|
+
var e_1, _a;
|
|
245
|
+
var _b;
|
|
246
|
+
var chunks = [];
|
|
247
|
+
var localeChunks = [];
|
|
248
|
+
var found = false;
|
|
249
|
+
var inQuotes = false;
|
|
250
|
+
var inBrackets = false;
|
|
251
|
+
for (var i = 0; i < pattern.length; i++) {
|
|
252
|
+
var char = pattern[i];
|
|
253
|
+
if (inQuotes) {
|
|
254
|
+
inQuotes = char !== '"';
|
|
255
|
+
}
|
|
256
|
+
else if (inBrackets) {
|
|
257
|
+
inBrackets = char !== "]";
|
|
258
|
+
}
|
|
259
|
+
else if (char === '"') {
|
|
260
|
+
inQuotes = true;
|
|
261
|
+
}
|
|
262
|
+
else if (char === "[") {
|
|
263
|
+
var end = pattern[i + 1] === "$" ? pattern.indexOf("]", i) : -1;
|
|
264
|
+
if (end > 0) {
|
|
265
|
+
localeChunks.push(chunks.length);
|
|
266
|
+
chunks.push(pattern.slice(i + 1, end));
|
|
267
|
+
i = end;
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
inBrackets = true;
|
|
271
|
+
}
|
|
272
|
+
else if (char === "\\" || char === "_" || char === "*") {
|
|
273
|
+
chunks.push(char + ((_b = pattern[i + 1]) !== null && _b !== void 0 ? _b : ""));
|
|
274
|
+
i++;
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
else if ((char === "A" || char === "a") &&
|
|
278
|
+
pattern[i + 1] === "/" &&
|
|
279
|
+
(pattern[i + 2] === "P" || pattern[i + 2] === "p")) {
|
|
280
|
+
chunks.push("A/P");
|
|
281
|
+
found = true;
|
|
282
|
+
i += 2;
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
chunks.push(char);
|
|
286
|
+
}
|
|
287
|
+
if (!found)
|
|
288
|
+
return undefined;
|
|
289
|
+
try {
|
|
290
|
+
for (var localeChunks_1 = tslib_1.__values(localeChunks), localeChunks_1_1 = localeChunks_1.next(); !localeChunks_1_1.done; localeChunks_1_1 = localeChunks_1.next()) {
|
|
291
|
+
var index = localeChunks_1_1.value;
|
|
292
|
+
chunks[index] = "[".concat(shortAmPmLocaleToken(chunks[index]), "]");
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
296
|
+
finally {
|
|
297
|
+
try {
|
|
298
|
+
if (localeChunks_1_1 && !localeChunks_1_1.done && (_a = localeChunks_1.return)) _a.call(localeChunks_1);
|
|
299
|
+
}
|
|
300
|
+
finally { if (e_1) throw e_1.error; }
|
|
301
|
+
}
|
|
302
|
+
return chunks.join("");
|
|
303
|
+
};
|
|
304
|
+
exports.withShortAmPmMarker = withShortAmPmMarker;
|
|
305
|
+
var shortAmPmPatternCache = new Map();
|
|
306
|
+
var DEFAULT_SEPARATORS = { decimal: ".", group: "," };
|
|
307
|
+
var separatorsFor = function (locale) {
|
|
308
|
+
var _a, _b;
|
|
309
|
+
if (!locale)
|
|
310
|
+
return DEFAULT_SEPARATORS;
|
|
311
|
+
var l10n = (0, numfmt_1.getLocale)(locale);
|
|
312
|
+
if (!l10n)
|
|
313
|
+
return DEFAULT_SEPARATORS;
|
|
314
|
+
return {
|
|
315
|
+
decimal: (_a = l10n.decimal) !== null && _a !== void 0 ? _a : ".",
|
|
316
|
+
group: (_b = l10n.group) !== null && _b !== void 0 ? _b : ",",
|
|
317
|
+
};
|
|
318
|
+
};
|
|
191
319
|
var ssfFormat = function (pattern, value, locale) {
|
|
192
320
|
try {
|
|
321
|
+
var shortAmPm = shortAmPmPatternCache.get(pattern);
|
|
322
|
+
if (shortAmPm === undefined && !shortAmPmPatternCache.has(pattern)) {
|
|
323
|
+
shortAmPm = (0, exports.withShortAmPmMarker)(pattern);
|
|
324
|
+
shortAmPmPatternCache.set(pattern, shortAmPm);
|
|
325
|
+
}
|
|
326
|
+
var code = shortAmPm !== null && shortAmPm !== void 0 ? shortAmPm : pattern;
|
|
327
|
+
var patternLocale = localeForPattern(pattern, locale);
|
|
328
|
+
if (shortAmPm !== undefined && patternLocale) {
|
|
329
|
+
patternLocale = getShortAmPmLocale(patternLocale);
|
|
330
|
+
}
|
|
331
|
+
var options_1 = { locale: patternLocale };
|
|
332
|
+
if (typeof value === "number") {
|
|
333
|
+
// Excel decides rounding, `General`, huge magnitudes and conditional
|
|
334
|
+
// sections from the 15-significant-digit decimal, not the binary
|
|
335
|
+
// double (#546 U8 / U21).
|
|
336
|
+
var pre = (0, excel_number_format_1.excelNumberPrePass)(code, value, separatorsFor(locale), function (section, sectionValue) { return (0, numfmt_1.format)(section, sectionValue, options_1); });
|
|
337
|
+
if (pre.text !== undefined) {
|
|
338
|
+
return pre.text;
|
|
339
|
+
}
|
|
340
|
+
value = pre.value;
|
|
341
|
+
}
|
|
193
342
|
var isNegativeElapsedTime = typeof value === "number" &&
|
|
194
343
|
value < 0 &&
|
|
195
344
|
isSingleSectionElapsedTimePattern(pattern);
|
|
196
|
-
var formatted = (0, numfmt_1.format)(
|
|
345
|
+
var formatted = (0, numfmt_1.format)(code, isNegativeElapsedTime ? Math.abs(value) : value, options_1);
|
|
197
346
|
return isNegativeElapsedTime ? "-".concat(formatted) : formatted;
|
|
198
347
|
}
|
|
199
348
|
catch (err) {
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export * from "./locale";
|
|
|
9
9
|
export * from "./date";
|
|
10
10
|
export * from "./log";
|
|
11
11
|
export * from "./array";
|
|
12
|
+
export * from "./excel-number-format";
|
|
12
13
|
export * from "./formatter";
|
|
13
14
|
export * from "./memoize";
|
|
14
15
|
export * from "./cell-data-helpers";
|
|
@@ -21,4 +22,6 @@ export * from "./conditional-format";
|
|
|
21
22
|
export * from "./data-validation";
|
|
22
23
|
export * from "./content-hash";
|
|
23
24
|
export * from "./shared-string-canonical";
|
|
25
|
+
export * from "./keyboard";
|
|
26
|
+
export * from "./sheet-span";
|
|
24
27
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,cAAc,WAA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,cAAc,2BAA2B,CAAC;AAC1C,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -12,6 +12,7 @@ tslib_1.__exportStar(require("./locale"), exports);
|
|
|
12
12
|
tslib_1.__exportStar(require("./date"), exports);
|
|
13
13
|
tslib_1.__exportStar(require("./log"), exports);
|
|
14
14
|
tslib_1.__exportStar(require("./array"), exports);
|
|
15
|
+
tslib_1.__exportStar(require("./excel-number-format"), exports);
|
|
15
16
|
tslib_1.__exportStar(require("./formatter"), exports);
|
|
16
17
|
tslib_1.__exportStar(require("./memoize"), exports);
|
|
17
18
|
tslib_1.__exportStar(require("./cell-data-helpers"), exports);
|
|
@@ -24,3 +25,5 @@ tslib_1.__exportStar(require("./conditional-format"), exports);
|
|
|
24
25
|
tslib_1.__exportStar(require("./data-validation"), exports);
|
|
25
26
|
tslib_1.__exportStar(require("./content-hash"), exports);
|
|
26
27
|
tslib_1.__exportStar(require("./shared-string-canonical"), exports);
|
|
28
|
+
tslib_1.__exportStar(require("./keyboard"), exports);
|
|
29
|
+
tslib_1.__exportStar(require("./sheet-span"), exports);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
type HotkeyEventLike = {
|
|
2
|
+
key: string;
|
|
3
|
+
code?: string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Map a physical key code (`KeyboardEvent.code`) to the character that key
|
|
7
|
+
* produces on a US layout: `KeyB` → `b`, `Digit1` → `1`, `Semicolon` → `;`.
|
|
8
|
+
* Returns undefined for codes that are not a letter, digit or punctuation key.
|
|
9
|
+
* @param code
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export declare const hotkeyKeyFromCode: (code: string | undefined) => string | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Layout-independent key to match keyboard shortcuts against.
|
|
15
|
+
*
|
|
16
|
+
* - A printable ASCII `event.key` wins, lowercased, so Dvorak/AZERTY users
|
|
17
|
+
* keep the shortcut printed on their keys (Excel / Google Sheets parity)
|
|
18
|
+
* and Shift no longer changes the letter (`Ctrl+Shift+X` → `x`).
|
|
19
|
+
* - When the layout produces a non-ASCII character (Cyrillic `и`, Greek `β`,
|
|
20
|
+
* Hebrew, or a macOS Option dead character such as `†`), the character is
|
|
21
|
+
* derived from the physical key instead: `event.code` `KeyB` → `b`.
|
|
22
|
+
* - Named keys (`Enter`, `Escape`, `F4`, `ArrowUp`, …) are returned as-is.
|
|
23
|
+
* @param event
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
export declare const getHotkeyKey: (event: HotkeyEventLike) => string;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=keyboard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyboard.d.ts","sourceRoot":"","sources":["../../keyboard.ts"],"names":[],"mappings":"AAAA,KAAK,eAAe,GAAG;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAqBF;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,GAAG,SAAS,uBAWzD,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,eAAe,WAYlD,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getHotkeyKey = exports.hotkeyKeyFromCode = void 0;
|
|
4
|
+
var PUNCTUATION_BY_CODE = {
|
|
5
|
+
Backquote: "`",
|
|
6
|
+
Backslash: "\\",
|
|
7
|
+
BracketLeft: "[",
|
|
8
|
+
BracketRight: "]",
|
|
9
|
+
Comma: ",",
|
|
10
|
+
Equal: "=",
|
|
11
|
+
Minus: "-",
|
|
12
|
+
Period: ".",
|
|
13
|
+
Quote: "'",
|
|
14
|
+
Semicolon: ";",
|
|
15
|
+
Slash: "/",
|
|
16
|
+
};
|
|
17
|
+
var isPrintableAscii = function (key) {
|
|
18
|
+
var charCode = key.charCodeAt(0);
|
|
19
|
+
return charCode >= 0x20 && charCode <= 0x7e;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Map a physical key code (`KeyboardEvent.code`) to the character that key
|
|
23
|
+
* produces on a US layout: `KeyB` → `b`, `Digit1` → `1`, `Semicolon` → `;`.
|
|
24
|
+
* Returns undefined for codes that are not a letter, digit or punctuation key.
|
|
25
|
+
* @param code
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
var hotkeyKeyFromCode = function (code) {
|
|
29
|
+
if (!code) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
if (/^Key[A-Z]$/.test(code)) {
|
|
33
|
+
return code.charAt(3).toLowerCase();
|
|
34
|
+
}
|
|
35
|
+
if (/^Digit[0-9]$/.test(code)) {
|
|
36
|
+
return code.charAt(5);
|
|
37
|
+
}
|
|
38
|
+
return PUNCTUATION_BY_CODE[code];
|
|
39
|
+
};
|
|
40
|
+
exports.hotkeyKeyFromCode = hotkeyKeyFromCode;
|
|
41
|
+
/**
|
|
42
|
+
* Layout-independent key to match keyboard shortcuts against.
|
|
43
|
+
*
|
|
44
|
+
* - A printable ASCII `event.key` wins, lowercased, so Dvorak/AZERTY users
|
|
45
|
+
* keep the shortcut printed on their keys (Excel / Google Sheets parity)
|
|
46
|
+
* and Shift no longer changes the letter (`Ctrl+Shift+X` → `x`).
|
|
47
|
+
* - When the layout produces a non-ASCII character (Cyrillic `и`, Greek `β`,
|
|
48
|
+
* Hebrew, or a macOS Option dead character such as `†`), the character is
|
|
49
|
+
* derived from the physical key instead: `event.code` `KeyB` → `b`.
|
|
50
|
+
* - Named keys (`Enter`, `Escape`, `F4`, `ArrowUp`, …) are returned as-is.
|
|
51
|
+
* @param event
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
54
|
+
var getHotkeyKey = function (event) {
|
|
55
|
+
var key = event.key, code = event.code;
|
|
56
|
+
if (key.length === 1) {
|
|
57
|
+
if (isPrintableAscii(key)) {
|
|
58
|
+
return key.toLowerCase();
|
|
59
|
+
}
|
|
60
|
+
var keyFromCode = (0, exports.hotkeyKeyFromCode)(code);
|
|
61
|
+
if (keyFromCode !== undefined) {
|
|
62
|
+
return keyFromCode;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return key;
|
|
66
|
+
};
|
|
67
|
+
exports.getHotkeyKey = getHotkeyKey;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sheets covered by a 3-D reference span `first:last` (`Sheet1:Sheet3!A1`):
|
|
3
|
+
* every name between the two endpoints in tab order, inclusive. Excel spans
|
|
4
|
+
* the tabs between the endpoints whichever one is written first and matches
|
|
5
|
+
* sheet names case-insensitively. Returns undefined when an endpoint is not a
|
|
6
|
+
* sheet (the caller reports #REF!).
|
|
7
|
+
* @param sheetNames sheet names in tab order
|
|
8
|
+
* @param first
|
|
9
|
+
* @param last
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export declare const resolveSheetSpan: (sheetNames: readonly string[], first: string, last: string) => string[] | undefined;
|
|
13
|
+
//# sourceMappingURL=sheet-span.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sheet-span.d.ts","sourceRoot":"","sources":["../../sheet-span.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,gBAAgB,GAC3B,YAAY,SAAS,MAAM,EAAE,EAC7B,OAAO,MAAM,EACb,MAAM,MAAM,KACX,MAAM,EAAE,GAAG,SAQb,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveSheetSpan = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Sheets covered by a 3-D reference span `first:last` (`Sheet1:Sheet3!A1`):
|
|
6
|
+
* every name between the two endpoints in tab order, inclusive. Excel spans
|
|
7
|
+
* the tabs between the endpoints whichever one is written first and matches
|
|
8
|
+
* sheet names case-insensitively. Returns undefined when an endpoint is not a
|
|
9
|
+
* sheet (the caller reports #REF!).
|
|
10
|
+
* @param sheetNames sheet names in tab order
|
|
11
|
+
* @param first
|
|
12
|
+
* @param last
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
var resolveSheetSpan = function (sheetNames, first, last) {
|
|
16
|
+
var lower = sheetNames.map(function (name) { return name.toLowerCase(); });
|
|
17
|
+
var start = lower.indexOf(first.toLowerCase());
|
|
18
|
+
var end = lower.indexOf(last.toLowerCase());
|
|
19
|
+
if (start === -1 || end === -1) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
return sheetNames.slice(Math.min(start, end), Math.max(start, end) + 1);
|
|
23
|
+
};
|
|
24
|
+
exports.resolveSheetSpan = resolveSheetSpan;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../../array.ts","../../cell-data-helpers.ts","../../color.ts","../../colors.ts","../../conditional-format.ts","../../content-hash.ts","../../data-validation.ts","../../date.ts","../../dom.ts","../../formatter.ts","../../formula-refs.ts","../../formula.ts","../../index.ts","../../locale.ts","../../log.ts","../../memoize.ts","../../numbers.ts","../../selection.ts","../../shared-string-canonical.ts","../../sort.ts","../../string.ts","../../table-styles.ts","../../typeguards.ts","../../uuid.ts","../../vitest.config.ts"],"version":"5.8.3"}
|
|
1
|
+
{"root":["../../array.ts","../../cell-data-helpers.ts","../../color.ts","../../colors.ts","../../conditional-format.ts","../../content-hash.ts","../../data-validation.ts","../../date.ts","../../dom.ts","../../excel-number-format.ts","../../formatter.ts","../../formula-refs.ts","../../formula.ts","../../index.ts","../../keyboard.ts","../../locale.ts","../../log.ts","../../memoize.ts","../../numbers.ts","../../selection.ts","../../shared-string-canonical.ts","../../sheet-span.ts","../../sort.ts","../../string.ts","../../table-styles.ts","../../typeguards.ts","../../uuid.ts","../../vitest.config.ts"],"version":"5.8.3"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Excel-parity pre-pass for number formatting.
|
|
3
|
+
*
|
|
4
|
+
* `numfmt` renders the bulk of Excel's format language, but it decides three
|
|
5
|
+
* things from the binary double where Excel decides them from the number's
|
|
6
|
+
* 15-significant-digit decimal representation:
|
|
7
|
+
*
|
|
8
|
+
* - rounding to a fixed number of decimals (`0.00` of `1.005` is `1.01`, not
|
|
9
|
+
* the `1.00` the double `1.00499999999999989…` rounds to);
|
|
10
|
+
* - `General`, which switches to scientific notation below 1E-4 and above
|
|
11
|
+
* 11 digits and rounds (never truncates) the 11th digit;
|
|
12
|
+
* - magnitudes ≥ 1E15, where Excel pads the 15 significant digits with
|
|
13
|
+
* zeros (`0.00` of `1E21` is `1000000000000000000000.00`).
|
|
14
|
+
*
|
|
15
|
+
* It also renders a date/time format for a serial outside Excel's calendar
|
|
16
|
+
* (negative, or ≥ 10000-01-01) as `#######`, as Excel does in the cell.
|
|
17
|
+
*
|
|
18
|
+
* Everything here works on the pattern's SECTION the value selects, so
|
|
19
|
+
* multi-section formats (`0.00;(0.00);"-"`) keep their Excel section rules.
|
|
20
|
+
* A format with `[>100]`-style conditions is resolved here too — which
|
|
21
|
+
* section matches, and whether the value's sign is shown — so the matched
|
|
22
|
+
* section gets the same decimal rules; the library then renders that one
|
|
23
|
+
* section on its own.
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* What Excel shows when a value cannot be rendered by its format: a
|
|
27
|
+
* date/time outside the calendar, or a number no conditional section takes.
|
|
28
|
+
*/
|
|
29
|
+
export declare const DATE_OVERFLOW_DISPLAY = "#######";
|
|
30
|
+
export type FormatSectionKind = "general" | "empty" | "number" | "date" | "text" | "other";
|
|
31
|
+
export type FormatConditionOperator = "<" | "<=" | ">" | ">=" | "=" | "<>";
|
|
32
|
+
/** A `[>100]`-style section condition. */
|
|
33
|
+
export interface FormatCondition {
|
|
34
|
+
op: FormatConditionOperator;
|
|
35
|
+
operand: number;
|
|
36
|
+
}
|
|
37
|
+
export interface FormatSectionInfo {
|
|
38
|
+
kind: FormatSectionKind;
|
|
39
|
+
/** The section body with color / locale / condition tokens removed. */
|
|
40
|
+
body: string;
|
|
41
|
+
/** `[>100]`-style condition on this section. */
|
|
42
|
+
hasCondition: boolean;
|
|
43
|
+
condition?: FormatCondition;
|
|
44
|
+
/** Elapsed-time token (`[h]`, `[mm]`, `[s]`) — negative values are legal. */
|
|
45
|
+
isElapsed: boolean;
|
|
46
|
+
/** Literal text before a `General` token (`-General` → `"-"`). */
|
|
47
|
+
generalPrefix: string;
|
|
48
|
+
/** Digit placeholders after the decimal point. */
|
|
49
|
+
decimals: number;
|
|
50
|
+
/** Number of `%` signs (each scales by 100). */
|
|
51
|
+
percent: number;
|
|
52
|
+
/** Trailing scaling commas (each divides by 1000). */
|
|
53
|
+
commaScale: number;
|
|
54
|
+
/** A grouping comma between digit placeholders. */
|
|
55
|
+
grouping: boolean;
|
|
56
|
+
/** Only placeholders / separators — safe to render without the library. */
|
|
57
|
+
isPlainNumber: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Digit placeholders outside a fraction: a `-` prefixed to this section is
|
|
60
|
+
* dropped when every digit it renders is zero (`0.00` of -0.001 → `0.00`).
|
|
61
|
+
*/
|
|
62
|
+
volatileSign: boolean;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Split a format code into its `;` sections, honouring quotes, bracket
|
|
66
|
+
* tokens and backslash escapes.
|
|
67
|
+
*/
|
|
68
|
+
export declare const splitFormatSections: (code: string) => string[];
|
|
69
|
+
/** Classify one section of a format code. */
|
|
70
|
+
export declare const analyzeFormatSection: (section: string) => FormatSectionInfo;
|
|
71
|
+
/**
|
|
72
|
+
* Which section Excel applies to a numeric value: one section covers every
|
|
73
|
+
* number; two sections split positive-or-zero / negative; three add a zero
|
|
74
|
+
* section. Returns the index and whether the section's sign is implicit.
|
|
75
|
+
*/
|
|
76
|
+
export declare const pickNumberSection: (sectionCount: number, value: number) => {
|
|
77
|
+
index: number;
|
|
78
|
+
implicitSign: boolean;
|
|
79
|
+
};
|
|
80
|
+
export interface ResolvedConditionalSection {
|
|
81
|
+
index: number;
|
|
82
|
+
/** The implicit `General` fallback Excel adds to a one-section conditional format. */
|
|
83
|
+
generated: boolean;
|
|
84
|
+
/** A negative value's rendering is prefixed with `-`. */
|
|
85
|
+
minus: boolean;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Excel's section selection for a format with `[>100]`-style conditions:
|
|
89
|
+
* the first of the (up to three) numeric sections whose condition holds —
|
|
90
|
+
* an unconditional section always holds — or `undefined` when none does.
|
|
91
|
+
* `conditions[i]` is section i's condition (or `undefined`).
|
|
92
|
+
*/
|
|
93
|
+
export declare const resolveConditionalSection: (conditions: readonly (FormatCondition | undefined)[], value: number) => ResolvedConditionalSection | undefined;
|
|
94
|
+
/** Remove the `[>100]`-style condition tokens from one section. */
|
|
95
|
+
export declare const stripConditionTokens: (section: string) => string;
|
|
96
|
+
/**
|
|
97
|
+
* Round |x|·10^shift half away from zero to `decimals` places using its
|
|
98
|
+
* 15-significant-digit decimal representation, and return the rounded value
|
|
99
|
+
* scaled back (÷10^shift). Returns `x` unchanged when no digit is dropped.
|
|
100
|
+
*/
|
|
101
|
+
export declare const roundDecimal15: (x: number, decimals: number, shift?: number) => number;
|
|
102
|
+
/** Excel `General` for a finite number, using `.`/`E` (caller localizes). */
|
|
103
|
+
export declare const excelGeneral: (value: number) => string;
|
|
104
|
+
/**
|
|
105
|
+
* Digits of |x| for |x| ≥ 1E15 as Excel shows them: the 15 significant
|
|
106
|
+
* digits followed by zeros (Excel stores nothing beyond 15 digits).
|
|
107
|
+
*/
|
|
108
|
+
export declare const hugeIntegerDigits: (x: number) => string;
|
|
109
|
+
export declare const groupDigits: (digits: string, separator: string) => string;
|
|
110
|
+
export interface ExcelPrePassResult {
|
|
111
|
+
/** A final rendering; the library is not consulted. */
|
|
112
|
+
text?: string;
|
|
113
|
+
/** The (possibly pre-rounded) value to hand to the library. */
|
|
114
|
+
value: number;
|
|
115
|
+
}
|
|
116
|
+
export interface ExcelPrePassLocale {
|
|
117
|
+
decimal: string;
|
|
118
|
+
group: string;
|
|
119
|
+
}
|
|
120
|
+
/** Renders one section of a format code with the formatting library. */
|
|
121
|
+
export type RenderFormatSection = (code: string, value: number) => string;
|
|
122
|
+
/**
|
|
123
|
+
* Apply Excel's decimal rules before handing a numeric value to `numfmt`.
|
|
124
|
+
* `render` formats one section of the pattern with the library; it is used
|
|
125
|
+
* when the pre-pass has to resolve a conditional format itself.
|
|
126
|
+
*/
|
|
127
|
+
export declare const excelNumberPrePass: (pattern: string, value: number, l10n: ExcelPrePassLocale, render: RenderFormatSection) => ExcelPrePassResult;
|
|
128
|
+
//# sourceMappingURL=excel-number-format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"excel-number-format.d.ts","sourceRoot":"","sources":["../../excel-number-format.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAKH;;;GAGG;AACH,eAAO,MAAM,qBAAqB,YAAY,CAAC;AAE/C,MAAM,MAAM,iBAAiB,GACzB,SAAS,GACT,OAAO,GACP,QAAQ,GACR,MAAM,GACN,MAAM,GACN,OAAO,CAAC;AAEZ,MAAM,MAAM,uBAAuB,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC;AAE3E,0CAA0C;AAC1C,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,uBAAuB,CAAC;IAC5B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,iBAAiB,CAAC;IACxB,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAC;IACb,gDAAgD;IAChD,YAAY,EAAE,OAA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