javascript-excel 2.0.0-alpha.7 → 2.0.0-beta.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.
package/README.md CHANGED
@@ -2,12 +2,14 @@
2
2
 
3
3
  Read and write `.xlsx` and `.csv` files in browsers, Web Workers and Node.js. TypeScript, no runtime dependencies, tree-shakable entry points.
4
4
 
5
- > **Prerelease.** `2.0.0-alpha.x` is a from-scratch rewrite. Everything listed below ships today, and the API may still change before 2.0.0. The last 1.x release is `javascript-excel@1.0.3`.
5
+ > **Beta.** `2.0.0-beta.x` is a from-scratch rewrite. Everything listed below ships today. The 2.0.0 feature set is complete; changes before 2.0.0 should be limited to fixes found in testing. The last 1.x release is `javascript-excel@1.0.3`.
6
6
 
7
7
  ```sh
8
8
  npm install javascript-excel@next
9
9
  ```
10
10
 
11
+ **Try it in the browser:** the [playground](https://javascript-excel-playground.vercel.app/) writes, reads and previews workbooks with the published package, and shows the code for what you build.
12
+
11
13
  | entry | for |
12
14
  |---|---|
13
15
  | `javascript-excel` | the workbook model, the `.xlsx` writer, dataset builders, dates, addresses, errors |
@@ -3,7 +3,7 @@ import { t as cellText } from "./cells-CrMF8h_t.js";
3
3
  import { t as dateToSerial } from "./dates-BXcSWf9_.js";
4
4
  import { o as ValidationError } from "./errors-CvGlfw0E.js";
5
5
  import { n as parseIsoDate, t as isoDate } from "./iso-date-CXnn-9mT.js";
6
- import { l as textWidth, m as mergeStyles, n as validateSheetName, r as AUTO_WIDTH } from "./sheet-names-7p-joVsG.js";
6
+ import { l as textWidth, m as mergeStyles, n as validateSheetName, r as AUTO_WIDTH } from "./sheet-names-BLrwcn33.js";
7
7
  // src/dataset.ts
8
8
  /**
9
9
  * Dataset builders (docs/api.md §4.3): `{ columns, data }` ↔ Sheet.
@@ -612,7 +612,7 @@ function toDatasetDetailed(sheet, options = {}) {
612
612
  const join = options.join ?? " / ";
613
613
  if (typeof join !== "string") throw new TypeError("join must be a string");
614
614
  const asCell = options.values === "cell";
615
- const titleOf = headerRow === false ? void 0 : headerRows === 1 ? (c) => cellText(s.rows[headerRow]?.[c]).trim() : multiRowTitles(s, headerRow, headerRows, join);
615
+ const titleOf = headerRow === false ? void 0 : headerRows === 1 ? (c) => cellText(s.rows[headerRow]?.[c]).trim() : multiRowTitles(s, headerRow, headerRows, join, rng.start.col);
616
616
  const columns = [];
617
617
  const used = /* @__PURE__ */ new Map();
618
618
  for (let c = rng.start.col; c <= rng.end.col; c++) {
@@ -666,19 +666,41 @@ function toDatasetDetailed(sheet, options = {}) {
666
666
  * Titles of a header spanning several rows: the text of each row joined,
667
667
  * with merged cells expanded (a group title merged across columns prefixes
668
668
  * each of them) and a cell merged down through the rows counted once.
669
+ *
670
+ * Without merges (CSV), a group title is written once, over the first of its
671
+ * columns: "Q1," over "Jan,Feb". So an empty, unmerged cell in an upper header
672
+ * row takes the nearest non-empty cell to its left in that row, as long as
673
+ * the column has text in a lower header row (it is a sub-column). The fill
674
+ * stops at the table's first column and at a merged cell, whose extent the
675
+ * merge already gives.
669
676
  */
670
- function multiRowTitles(s, top, count, join) {
677
+ function multiRowTitles(s, top, count, join, firstCol) {
671
678
  const bottom = top + count - 1;
672
679
  const merges = (s.merges ?? []).map((m) => decodeRange(m)).filter((m) => m.start.row <= bottom && m.end.row >= top);
680
+ const mergeAt = (r, c) => merges.find((x) => r >= x.start.row && r <= x.end.row && c >= x.start.col && c <= x.end.col);
681
+ const textAt = (r, c) => cellText(s.rows[r]?.[c]).trim();
682
+ const filledFromLeft = (r, c) => {
683
+ for (let k = c - 1; k >= firstCol; k--) {
684
+ if (mergeAt(r, k)) return "";
685
+ const t = textAt(r, k);
686
+ if (t !== "") return t;
687
+ }
688
+ return "";
689
+ };
673
690
  return (c) => {
674
691
  const parts = [];
675
692
  let last;
676
693
  for (let r = top; r <= bottom; r++) {
677
- const m = merges.find((x) => r >= x.start.row && r <= x.end.row && c >= x.start.col && c <= x.end.col);
694
+ const m = mergeAt(r, c);
678
695
  const id = m ?? `${r}`;
679
696
  if (id === last) continue;
680
697
  last = id;
681
- const text = cellText(m ? s.rows[m.start.row]?.[m.start.col] : s.rows[r]?.[c]).trim();
698
+ let text = m ? cellText(s.rows[m.start.row]?.[m.start.col]).trim() : textAt(r, c);
699
+ if (text === "" && !m && r < bottom) {
700
+ let subColumn = false;
701
+ for (let q = r + 1; q <= bottom && !subColumn; q++) subColumn = mergeAt(q, c) === void 0 && textAt(q, c) !== "";
702
+ if (subColumn) text = filledFromLeft(r, c);
703
+ }
682
704
  if (text !== "") parts.push(text);
683
705
  }
684
706
  return parts.join(join);
@@ -3,7 +3,7 @@ const require_cells = require("./cells-CPXU722t.cjs");
3
3
  const require_dates = require("./dates-CA1dCizp.cjs");
4
4
  const require_errors = require("./errors-DOPrrGS4.cjs");
5
5
  const require_iso_date = require("./iso-date-3TY1OlGd.cjs");
6
- const require_sheet_names = require("./sheet-names-B8U5RAW0.cjs");
6
+ const require_sheet_names = require("./sheet-names-DDY64-dt.cjs");
7
7
  // src/dataset.ts
8
8
  /**
9
9
  * Dataset builders (docs/api.md §4.3): `{ columns, data }` ↔ Sheet.
@@ -612,7 +612,7 @@ function toDatasetDetailed(sheet, options = {}) {
612
612
  const join = options.join ?? " / ";
613
613
  if (typeof join !== "string") throw new TypeError("join must be a string");
614
614
  const asCell = options.values === "cell";
615
- const titleOf = headerRow === false ? void 0 : headerRows === 1 ? (c) => require_cells.cellText(s.rows[headerRow]?.[c]).trim() : multiRowTitles(s, headerRow, headerRows, join);
615
+ const titleOf = headerRow === false ? void 0 : headerRows === 1 ? (c) => require_cells.cellText(s.rows[headerRow]?.[c]).trim() : multiRowTitles(s, headerRow, headerRows, join, rng.start.col);
616
616
  const columns = [];
617
617
  const used = /* @__PURE__ */ new Map();
618
618
  for (let c = rng.start.col; c <= rng.end.col; c++) {
@@ -666,19 +666,41 @@ function toDatasetDetailed(sheet, options = {}) {
666
666
  * Titles of a header spanning several rows: the text of each row joined,
667
667
  * with merged cells expanded (a group title merged across columns prefixes
668
668
  * each of them) and a cell merged down through the rows counted once.
669
+ *
670
+ * Without merges (CSV), a group title is written once, over the first of its
671
+ * columns: "Q1," over "Jan,Feb". So an empty, unmerged cell in an upper header
672
+ * row takes the nearest non-empty cell to its left in that row, as long as
673
+ * the column has text in a lower header row (it is a sub-column). The fill
674
+ * stops at the table's first column and at a merged cell, whose extent the
675
+ * merge already gives.
669
676
  */
670
- function multiRowTitles(s, top, count, join) {
677
+ function multiRowTitles(s, top, count, join, firstCol) {
671
678
  const bottom = top + count - 1;
672
679
  const merges = (s.merges ?? []).map((m) => require_address.decodeRange(m)).filter((m) => m.start.row <= bottom && m.end.row >= top);
680
+ const mergeAt = (r, c) => merges.find((x) => r >= x.start.row && r <= x.end.row && c >= x.start.col && c <= x.end.col);
681
+ const textAt = (r, c) => require_cells.cellText(s.rows[r]?.[c]).trim();
682
+ const filledFromLeft = (r, c) => {
683
+ for (let k = c - 1; k >= firstCol; k--) {
684
+ if (mergeAt(r, k)) return "";
685
+ const t = textAt(r, k);
686
+ if (t !== "") return t;
687
+ }
688
+ return "";
689
+ };
673
690
  return (c) => {
674
691
  const parts = [];
675
692
  let last;
676
693
  for (let r = top; r <= bottom; r++) {
677
- const m = merges.find((x) => r >= x.start.row && r <= x.end.row && c >= x.start.col && c <= x.end.col);
694
+ const m = mergeAt(r, c);
678
695
  const id = m ?? `${r}`;
679
696
  if (id === last) continue;
680
697
  last = id;
681
- const text = require_cells.cellText(m ? s.rows[m.start.row]?.[m.start.col] : s.rows[r]?.[c]).trim();
698
+ let text = m ? require_cells.cellText(s.rows[m.start.row]?.[m.start.col]).trim() : textAt(r, c);
699
+ if (text === "" && !m && r < bottom) {
700
+ let subColumn = false;
701
+ for (let q = r + 1; q <= bottom && !subColumn; q++) subColumn = mergeAt(q, c) === void 0 && textAt(q, c) !== "";
702
+ if (subColumn) text = filledFromLeft(r, c);
703
+ }
682
704
  if (text !== "") parts.push(text);
683
705
  }
684
706
  return parts.join(join);
package/dist/dom.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_cells = require("./cells-CPXU722t.cjs");
3
- const require_sheet_names = require("./sheet-names-B8U5RAW0.cjs");
3
+ const require_sheet_names = require("./sheet-names-DDY64-dt.cjs");
4
4
  const require_errors = require("./errors-DOPrrGS4.cjs");
5
5
  const require_iso_date = require("./iso-date-3TY1OlGd.cjs");
6
6
  // src/auto-width.ts
package/dist/dom.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as cellText } from "./cells-CrMF8h_t.js";
2
- import { c as hyperlinkSchemes, i as DEFAULT_HYPERLINK_SCHEMES, l as textWidth, m as mergeStyles, n as validateSheetName, r as AUTO_WIDTH } from "./sheet-names-7p-joVsG.js";
2
+ import { c as hyperlinkSchemes, i as DEFAULT_HYPERLINK_SCHEMES, l as textWidth, m as mergeStyles, n as validateSheetName, r as AUTO_WIDTH } from "./sheet-names-BLrwcn33.js";
3
3
  import { n as EnvironmentError, o as ValidationError } from "./errors-CvGlfw0E.js";
4
4
  import { n as parseIsoDate } from "./iso-date-CXnn-9mT.js";
5
5
  // src/auto-width.ts
package/dist/format.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_cells = require("./cells-CPXU722t.cjs");
3
3
  const require_dates = require("./dates-CA1dCizp.cjs");
4
- const require_numfmt = require("./numfmt-BmEbm78Y.cjs");
4
+ const require_numfmt = require("./numfmt-DwsnhZKe.cjs");
5
5
  // src/internal/format/parse.ts
6
6
  const COLOR_NAMES = /* @__PURE__ */ new Set([
7
7
  "black",
package/dist/format.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { t as cellText } from "./cells-CrMF8h_t.js";
2
2
  import { t as dateToSerial } from "./dates-BXcSWf9_.js";
3
- import { t as BUILTIN_NUM_FMTS } from "./numfmt-DCDrX9P1.js";
3
+ import { t as BUILTIN_NUM_FMTS } from "./numfmt-Ci_oW11p.js";
4
4
  // src/internal/format/parse.ts
5
5
  const COLOR_NAMES = /* @__PURE__ */ new Set([
6
6
  "black",
package/dist/import.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_pipeline = require("./pipeline-CwLNDrKo.cjs");
2
+ const require_pipeline = require("./pipeline-DMskqxiU.cjs");
3
3
  exports.applyMapping = require_pipeline.applyMapping;
4
4
  exports.coerceColumns = require_pipeline.coerceColumns;
5
5
  exports.detectHeader = require_pipeline.detectHeader;
package/dist/import.js CHANGED
@@ -1 +1 @@
1
- export { i as applyMapping, n as coerceColumns, o as detectHeader, t as importDataset, r as inferColumnTypes, a as mapColumns, s as parseDate, c as parseNumber } from "./pipeline-B9-qglvn.js";
1
+ export { i as applyMapping, n as coerceColumns, o as detectHeader, t as importDataset, r as inferColumnTypes, a as mapColumns, s as parseDate, c as parseNumber } from "./pipeline-2dw9aehe.js";
package/dist/index.cjs CHANGED
@@ -1,16 +1,16 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_errors = require("./errors-DOPrrGS4.cjs");
3
- const require_write = require("./write-CXnhqht-.cjs");
3
+ const require_write = require("./write-DKXhuvKR.cjs");
4
4
  const require_dates = require("./dates-CA1dCizp.cjs");
5
- const require_sheet_names = require("./sheet-names-B8U5RAW0.cjs");
5
+ const require_sheet_names = require("./sheet-names-DDY64-dt.cjs");
6
6
  const require_colors = require("./colors-oBpjx97l.cjs");
7
7
  const require_cells = require("./cells-CPXU722t.cjs");
8
- const require_dataset = require("./dataset-CLc6y5j8.cjs");
9
- const require_numfmt = require("./numfmt-BmEbm78Y.cjs");
8
+ const require_dataset = require("./dataset-DzoMeOG1.cjs");
9
+ const require_numfmt = require("./numfmt-DwsnhZKe.cjs");
10
10
  const require_address = require("./address-DZBHchLv.cjs");
11
11
  // src/index.ts
12
12
  /** Package version. Set from package.json by `npm run version-packages` (scripts/sync-version.mjs); a unit test checks it. */
13
- const VERSION = "2.0.0-alpha.7";
13
+ const VERSION = "2.0.0-beta.1";
14
14
  exports.BUILTIN_NUM_FMTS = require_numfmt.BUILTIN_NUM_FMTS;
15
15
  exports.CsvError = require_errors.CsvError;
16
16
  exports.EnvironmentError = require_errors.EnvironmentError;
package/dist/index.d.cts CHANGED
@@ -236,9 +236,11 @@ export declare function toDataset(sheet: Sheet<Cell> | Sheet, options?: ToDatase
236
236
  /**
237
237
  * Sheet-name rules (docs/api.md §3.3, §4.6).
238
238
  *
239
- * Excel rejects names that are empty, longer than 31 characters, contain any
239
+ * Excel rejects names that are empty, longer than 31 characters (code points,
240
+ * not UTF-16 units: 30 x's and an emoji are accepted), contain any
240
241
  * of \ / ? * [ ] :, or start or end with an apostrophe. It reserves 'History'
241
- * [to verify]. Names are unique case-insensitively (checked by the writer).
242
+ * (Excel for Mac: "History is a reserve word"); the check here ignores case.
243
+ * Names are unique case-insensitively (checked by the writer).
242
244
  */
243
245
  /** Why a sheet name is invalid. */
244
246
  type SheetNameProblem = "empty" | "too-long" | "forbidden-char" | "apostrophe" | "reserved";
@@ -247,11 +249,15 @@ export declare function validateSheetName(name: string): SheetNameProblem | null
247
249
  /**
248
250
  * Makes any string a valid sheet name: forbidden characters become '_',
249
251
  * leading and trailing apostrophes are removed, the result is cut to 31
250
- * characters (without splitting a surrogate pair), and an empty or reserved
251
- * result becomes 'Sheet'. Uniqueness is the caller's job.
252
+ * code points (never splitting a surrogate pair), and an empty or reserved
253
+ * result ('History' in any case) becomes 'Sheet'. Uniqueness is the caller's job.
252
254
  */
253
255
  export declare function sanitizeSheetName(name: string): string;
254
- /** The built-in number formats ECMA-376 §18.8.30 defines (§11.2). Ids 14–17 and 22 render in the user's locale in Excel. */
256
+ /**
257
+ * The built-in number formats ECMA-376 §18.8.30 defines (§11.2), with the codes
258
+ * Excel itself uses for 37–40 and 47, which differ from the spec's table
259
+ * (checked in Excel for Mac). Ids 14–17 and 22 render in the user's locale in Excel.
260
+ */
255
261
  export declare const BUILTIN_NUM_FMTS: Readonly<Record<number, string>>;
256
262
  /**
257
263
  * True when a number format shows a date or a time of day (§3.4.1): built-in
@@ -287,5 +293,5 @@ export declare function encodeRange(r: RangeAddress): string;
287
293
  /** 'A1:C3' or 'A1' → range, normalised so start is top-left. */
288
294
  export declare function decodeRange(ref: string): RangeAddress;
289
295
  /** Package version. Set from package.json by `npm run version-packages` (scripts/sync-version.mjs); a unit test checks it. */
290
- export declare const VERSION = "2.0.0-alpha.7";
296
+ export declare const VERSION = "2.0.0-beta.1";
291
297
  export { type AbortSignalLike, type Alignment, type AutoWidthOptions, type BinaryInput, type BlobLike, type BlobType, type Border, type BorderSide, type BorderStyle, type Cell, type CellAddress, type CellErrorValue, type CellInput, type CellTextOptions, type CellType, type CellValue, type Color, type ColorContext, type ColumnDef, type ColumnProps, type ColumnTotal, type ColumnWidth, type Dataset, type DatasetBlock, type DatasetOptions, type DatasetResult, type DateOptions, type DefinedName, type DocProperties, type ErrorCode, type ExcelErrorCode, type ExcelErrorOptions, type ExcelWarning, type ExcelWarningCode, type Fill, type Font, type GradientFill, type GroupColumn, type Hyperlink, type LeafColumn, type NumFmt, type PatternFill, type PatternType, type PrintSetup, type Progress, type RangeAddress, type RichText, type RichTextRun, type RowProps, type Sheet, type SheetNameProblem, type SheetView, type Style, type Theme, type ToDatasetOptions, type Workbook, type WriteOptions, XLSX_MIME, toBlob, toUint8Array };
package/dist/index.d.ts CHANGED
@@ -236,9 +236,11 @@ export declare function toDataset(sheet: Sheet<Cell> | Sheet, options?: ToDatase
236
236
  /**
237
237
  * Sheet-name rules (docs/api.md §3.3, §4.6).
238
238
  *
239
- * Excel rejects names that are empty, longer than 31 characters, contain any
239
+ * Excel rejects names that are empty, longer than 31 characters (code points,
240
+ * not UTF-16 units: 30 x's and an emoji are accepted), contain any
240
241
  * of \ / ? * [ ] :, or start or end with an apostrophe. It reserves 'History'
241
- * [to verify]. Names are unique case-insensitively (checked by the writer).
242
+ * (Excel for Mac: "History is a reserve word"); the check here ignores case.
243
+ * Names are unique case-insensitively (checked by the writer).
242
244
  */
243
245
  /** Why a sheet name is invalid. */
244
246
  type SheetNameProblem = "empty" | "too-long" | "forbidden-char" | "apostrophe" | "reserved";
@@ -247,11 +249,15 @@ export declare function validateSheetName(name: string): SheetNameProblem | null
247
249
  /**
248
250
  * Makes any string a valid sheet name: forbidden characters become '_',
249
251
  * leading and trailing apostrophes are removed, the result is cut to 31
250
- * characters (without splitting a surrogate pair), and an empty or reserved
251
- * result becomes 'Sheet'. Uniqueness is the caller's job.
252
+ * code points (never splitting a surrogate pair), and an empty or reserved
253
+ * result ('History' in any case) becomes 'Sheet'. Uniqueness is the caller's job.
252
254
  */
253
255
  export declare function sanitizeSheetName(name: string): string;
254
- /** The built-in number formats ECMA-376 §18.8.30 defines (§11.2). Ids 14–17 and 22 render in the user's locale in Excel. */
256
+ /**
257
+ * The built-in number formats ECMA-376 §18.8.30 defines (§11.2), with the codes
258
+ * Excel itself uses for 37–40 and 47, which differ from the spec's table
259
+ * (checked in Excel for Mac). Ids 14–17 and 22 render in the user's locale in Excel.
260
+ */
255
261
  export declare const BUILTIN_NUM_FMTS: Readonly<Record<number, string>>;
256
262
  /**
257
263
  * True when a number format shows a date or a time of day (§3.4.1): built-in
@@ -287,5 +293,5 @@ export declare function encodeRange(r: RangeAddress): string;
287
293
  /** 'A1:C3' or 'A1' → range, normalised so start is top-left. */
288
294
  export declare function decodeRange(ref: string): RangeAddress;
289
295
  /** Package version. Set from package.json by `npm run version-packages` (scripts/sync-version.mjs); a unit test checks it. */
290
- export declare const VERSION = "2.0.0-alpha.7";
296
+ export declare const VERSION = "2.0.0-beta.1";
291
297
  export { type AbortSignalLike, type Alignment, type AutoWidthOptions, type BinaryInput, type BlobLike, type BlobType, type Border, type BorderSide, type BorderStyle, type Cell, type CellAddress, type CellErrorValue, type CellInput, type CellTextOptions, type CellType, type CellValue, type Color, type ColorContext, type ColumnDef, type ColumnProps, type ColumnTotal, type ColumnWidth, type Dataset, type DatasetBlock, type DatasetOptions, type DatasetResult, type DateOptions, type DefinedName, type DocProperties, type ErrorCode, type ExcelErrorCode, type ExcelErrorOptions, type ExcelWarning, type ExcelWarningCode, type Fill, type Font, type GradientFill, type GroupColumn, type Hyperlink, type LeafColumn, type NumFmt, type PatternFill, type PatternType, type PrintSetup, type Progress, type RangeAddress, type RichText, type RichTextRun, type RowProps, type Sheet, type SheetNameProblem, type SheetView, type Style, type Theme, type ToDatasetOptions, type Workbook, type WriteOptions, XLSX_MIME, toBlob, toUint8Array };
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import { a as LimitError, i as FormatError, n as EnvironmentError, o as ValidationError, r as ExcelError, s as isExcelError, t as CsvError } from "./errors-CvGlfw0E.js";
2
- import { n as toBlob, r as toUint8Array, t as XLSX_MIME } from "./write-DyOq-Efq.js";
2
+ import { n as toBlob, r as toUint8Array, t as XLSX_MIME } from "./write-BVXB2_2C.js";
3
3
  import { n as serialToDate, t as dateToSerial } from "./dates-BXcSWf9_.js";
4
- import { m as mergeStyles, n as validateSheetName, t as sanitizeSheetName } from "./sheet-names-7p-joVsG.js";
4
+ import { m as mergeStyles, n as validateSheetName, t as sanitizeSheetName } from "./sheet-names-BLrwcn33.js";
5
5
  import { t as resolveColor } from "./colors-B8Nf_xTx.js";
6
6
  import { t as cellText } from "./cells-CrMF8h_t.js";
7
- import { n as fromDatasets, r as toDataset, t as fromDataset } from "./dataset-GVrEbJwI.js";
8
- import { n as isDateFormat, t as BUILTIN_NUM_FMTS } from "./numfmt-DCDrX9P1.js";
7
+ import { n as fromDatasets, r as toDataset, t as fromDataset } from "./dataset-BLo9CwB-.js";
8
+ import { n as isDateFormat, t as BUILTIN_NUM_FMTS } from "./numfmt-Ci_oW11p.js";
9
9
  import { a as decodeRange, c as encodeRange, i as decodeCol, n as MAX_ROWS, o as encodeCell, r as decodeCell, s as encodeCol, t as MAX_COLS } from "./address-DUn7-5OS.js";
10
10
  // src/index.ts
11
11
  /** Package version. Set from package.json by `npm run version-packages` (scripts/sync-version.mjs); a unit test checks it. */
12
- const VERSION = "2.0.0-alpha.7";
12
+ const VERSION = "2.0.0-beta.1";
13
13
  export { BUILTIN_NUM_FMTS, CsvError, EnvironmentError, ExcelError, FormatError, LimitError, MAX_COLS, MAX_ROWS, VERSION, ValidationError, XLSX_MIME, cellText, dateToSerial, decodeCell, decodeCol, decodeRange, encodeCell, encodeCol, encodeRange, fromDataset, fromDatasets, isDateFormat, isExcelError, mergeStyles, resolveColor, sanitizeSheetName, serialToDate, toBlob, toDataset, toUint8Array, validateSheetName };
@@ -1,5 +1,9 @@
1
1
  // src/numfmt.ts
2
- /** The built-in number formats ECMA-376 §18.8.30 defines (§11.2). Ids 14–17 and 22 render in the user's locale in Excel. */
2
+ /**
3
+ * The built-in number formats ECMA-376 §18.8.30 defines (§11.2), with the codes
4
+ * Excel itself uses for 37–40 and 47, which differ from the spec's table
5
+ * (checked in Excel for Mac). Ids 14–17 and 22 render in the user's locale in Excel.
6
+ */
3
7
  const BUILTIN_NUM_FMTS = Object.freeze({
4
8
  0: "General",
5
9
  1: "0",
@@ -20,13 +24,13 @@ const BUILTIN_NUM_FMTS = Object.freeze({
20
24
  20: "h:mm",
21
25
  21: "h:mm:ss",
22
26
  22: "m/d/yy h:mm",
23
- 37: "#,##0 ;(#,##0)",
24
- 38: "#,##0 ;[Red](#,##0)",
25
- 39: "#,##0.00;(#,##0.00)",
26
- 40: "#,##0.00;[Red](#,##0.00)",
27
+ 37: "#,##0_);(#,##0)",
28
+ 38: "#,##0_);[Red](#,##0)",
29
+ 39: "#,##0.00_);(#,##0.00)",
30
+ 40: "#,##0.00_);[Red](#,##0.00)",
27
31
  45: "mm:ss",
28
32
  46: "[h]:mm:ss",
29
- 47: "mmss.0",
33
+ 47: "mm:ss.0",
30
34
  48: "##0.0E+0",
31
35
  49: "@"
32
36
  });
@@ -1,5 +1,9 @@
1
1
  // src/numfmt.ts
2
- /** The built-in number formats ECMA-376 §18.8.30 defines (§11.2). Ids 14–17 and 22 render in the user's locale in Excel. */
2
+ /**
3
+ * The built-in number formats ECMA-376 §18.8.30 defines (§11.2), with the codes
4
+ * Excel itself uses for 37–40 and 47, which differ from the spec's table
5
+ * (checked in Excel for Mac). Ids 14–17 and 22 render in the user's locale in Excel.
6
+ */
3
7
  const BUILTIN_NUM_FMTS = Object.freeze({
4
8
  0: "General",
5
9
  1: "0",
@@ -20,13 +24,13 @@ const BUILTIN_NUM_FMTS = Object.freeze({
20
24
  20: "h:mm",
21
25
  21: "h:mm:ss",
22
26
  22: "m/d/yy h:mm",
23
- 37: "#,##0 ;(#,##0)",
24
- 38: "#,##0 ;[Red](#,##0)",
25
- 39: "#,##0.00;(#,##0.00)",
26
- 40: "#,##0.00;[Red](#,##0.00)",
27
+ 37: "#,##0_);(#,##0)",
28
+ 38: "#,##0_);[Red](#,##0)",
29
+ 39: "#,##0.00_);(#,##0.00)",
30
+ 40: "#,##0.00_);[Red](#,##0.00)",
27
31
  45: "mm:ss",
28
32
  46: "[h]:mm:ss",
29
- 47: "mmss.0",
33
+ 47: "mm:ss.0",
30
34
  48: "##0.0E+0",
31
35
  49: "@"
32
36
  });
@@ -1,7 +1,7 @@
1
1
  import { r as readCsv } from "./csv-pXfaputs.js";
2
- import { i as toDatasetDetailed } from "./dataset-GVrEbJwI.js";
2
+ import { i as toDatasetDetailed } from "./dataset-BLo9CwB-.js";
3
3
  import { a as LimitError, i as FormatError, o as ValidationError } from "./errors-CvGlfw0E.js";
4
- import { i as readSheetNames, n as detectFormat, r as read } from "./read-DK5URBoq.js";
4
+ import { i as readSheetNames, n as detectFormat, r as read } from "./read-ClszMDAE.js";
5
5
  import { n as parseIsoDate, r as toBytes } from "./infer-BR-J9BZa.js";
6
6
  import { a as decodeRange } from "./address-DUn7-5OS.js";
7
7
  import { t as isoDate } from "./iso-date-CXnn-9mT.js";
@@ -304,6 +304,28 @@ function detectHeader(sheet, options = {}) {
304
304
  }
305
305
  return false;
306
306
  };
307
+ const typedBelow = (idx, k) => {
308
+ let seen = 0;
309
+ for (let j = idx + 1; j < rows.length && seen < LOOKAHEAD; j++) {
310
+ const kind = rows[j].kinds[k];
311
+ if (kind === 0) continue;
312
+ if (kind === 1) return false;
313
+ seen++;
314
+ }
315
+ return seen > 0;
316
+ };
317
+ const stacksBelow = (idx) => {
318
+ const y = rows[idx + 1];
319
+ if (!y || y.r !== rows[idx].r + 1 || !y.allText) return false;
320
+ for (let k = 0; k < width; k++) if (y.kinds[k] === 1 && !typedBelow(idx + 1, k)) return false;
321
+ return true;
322
+ };
323
+ const textOnTypedBelow = (idx) => {
324
+ const y = rows[idx + 1];
325
+ if (!y || y.r !== rows[idx].r + 1 || !y.allText) return false;
326
+ for (let k = 0; k < width; k++) if (y.kinds[k] === 1 && typedBelow(idx + 1, k)) return true;
327
+ return false;
328
+ };
307
329
  let header;
308
330
  let confidence = "low";
309
331
  for (const x of candidates) if (x.allText && x.filled >= tableWidth && hasOtherBelow(rows.indexOf(x))) {
@@ -311,6 +333,17 @@ function detectHeader(sheet, options = {}) {
311
333
  confidence = "high";
312
334
  break;
313
335
  }
336
+ if (!header) for (const x of candidates) {
337
+ const i = rows.indexOf(x);
338
+ const y = rows[i + 1];
339
+ if (!x.allText || !y || isTitle(y) || !stacksBelow(i)) continue;
340
+ let union = 0;
341
+ for (let k = 0; k < width; k++) if (x.kinds[k] !== 0 || y.kinds[k] !== 0) union++;
342
+ if (union >= tableWidth) return {
343
+ rows: [x.r, y.r],
344
+ confidence: "high"
345
+ };
346
+ }
314
347
  if (!header) header = candidates.find((x) => x.allText && x.filled >= tableWidth);
315
348
  if (!header) return {
316
349
  rows: [top],
@@ -323,6 +356,10 @@ function detectHeader(sheet, options = {}) {
323
356
  at++;
324
357
  result.push(rows[at].r);
325
358
  }
359
+ if (confidence === "high" && result.length === 1) {
360
+ if (stacksBelow(at)) result.push(rows[at + 1].r);
361
+ else if (textOnTypedBelow(at)) confidence = "low";
362
+ }
326
363
  for (let i = rows.indexOf(header) - 1; i >= 0; i--) {
327
364
  const x = rows[i];
328
365
  if (!x.allText || x.fullWidthMerge || !joinsBelow(x)) break;
@@ -1,7 +1,7 @@
1
1
  const require_csv = require("./csv-DyVH9y7S.cjs");
2
- const require_dataset = require("./dataset-CLc6y5j8.cjs");
2
+ const require_dataset = require("./dataset-DzoMeOG1.cjs");
3
3
  const require_errors = require("./errors-DOPrrGS4.cjs");
4
- const require_read = require("./read-tIwYuXES.cjs");
4
+ const require_read = require("./read-ByceXfiL.cjs");
5
5
  const require_infer = require("./infer-D9EC9vJ-.cjs");
6
6
  const require_address = require("./address-DZBHchLv.cjs");
7
7
  const require_iso_date = require("./iso-date-3TY1OlGd.cjs");
@@ -304,6 +304,28 @@ function detectHeader(sheet, options = {}) {
304
304
  }
305
305
  return false;
306
306
  };
307
+ const typedBelow = (idx, k) => {
308
+ let seen = 0;
309
+ for (let j = idx + 1; j < rows.length && seen < LOOKAHEAD; j++) {
310
+ const kind = rows[j].kinds[k];
311
+ if (kind === 0) continue;
312
+ if (kind === 1) return false;
313
+ seen++;
314
+ }
315
+ return seen > 0;
316
+ };
317
+ const stacksBelow = (idx) => {
318
+ const y = rows[idx + 1];
319
+ if (!y || y.r !== rows[idx].r + 1 || !y.allText) return false;
320
+ for (let k = 0; k < width; k++) if (y.kinds[k] === 1 && !typedBelow(idx + 1, k)) return false;
321
+ return true;
322
+ };
323
+ const textOnTypedBelow = (idx) => {
324
+ const y = rows[idx + 1];
325
+ if (!y || y.r !== rows[idx].r + 1 || !y.allText) return false;
326
+ for (let k = 0; k < width; k++) if (y.kinds[k] === 1 && typedBelow(idx + 1, k)) return true;
327
+ return false;
328
+ };
307
329
  let header;
308
330
  let confidence = "low";
309
331
  for (const x of candidates) if (x.allText && x.filled >= tableWidth && hasOtherBelow(rows.indexOf(x))) {
@@ -311,6 +333,17 @@ function detectHeader(sheet, options = {}) {
311
333
  confidence = "high";
312
334
  break;
313
335
  }
336
+ if (!header) for (const x of candidates) {
337
+ const i = rows.indexOf(x);
338
+ const y = rows[i + 1];
339
+ if (!x.allText || !y || isTitle(y) || !stacksBelow(i)) continue;
340
+ let union = 0;
341
+ for (let k = 0; k < width; k++) if (x.kinds[k] !== 0 || y.kinds[k] !== 0) union++;
342
+ if (union >= tableWidth) return {
343
+ rows: [x.r, y.r],
344
+ confidence: "high"
345
+ };
346
+ }
314
347
  if (!header) header = candidates.find((x) => x.allText && x.filled >= tableWidth);
315
348
  if (!header) return {
316
349
  rows: [top],
@@ -323,6 +356,10 @@ function detectHeader(sheet, options = {}) {
323
356
  at++;
324
357
  result.push(rows[at].r);
325
358
  }
359
+ if (confidence === "high" && result.length === 1) {
360
+ if (stacksBelow(at)) result.push(rows[at + 1].r);
361
+ else if (textOnTypedBelow(at)) confidence = "low";
362
+ }
326
363
  for (let i = rows.indexOf(header) - 1; i >= 0; i--) {
327
364
  const x = rows[i];
328
365
  if (!x.allText || x.fullWidthMerge || !joinsBelow(x)) break;
@@ -1,7 +1,7 @@
1
1
  const require_infer = require("./infer-D9EC9vJ-.cjs");
2
2
  const require_errors = require("./errors-DOPrrGS4.cjs");
3
3
  const require_dos_time = require("./dos-time-CxEs--rI.cjs");
4
- const require_numfmt = require("./numfmt-BmEbm78Y.cjs");
4
+ const require_numfmt = require("./numfmt-DwsnhZKe.cjs");
5
5
  const require_dates = require("./dates-CA1dCizp.cjs");
6
6
  // src/internal/read/limits.ts
7
7
  /** Default limits (docs/api.md §5.2; the measurements behind each value are listed there). */
@@ -1,7 +1,7 @@
1
1
  import { n as parseIsoDate, r as toBytes } from "./infer-BR-J9BZa.js";
2
2
  import { a as LimitError, i as FormatError } from "./errors-CvGlfw0E.js";
3
3
  import { a as decodeUtf8Strict, c as throttleProgress, d as throwIfAborted$1, i as nativeCodec, r as crc32, s as createYielder, t as fromDosDateTime, u as concatBytes } from "./dos-time-BsH7f0ef.js";
4
- import { n as isDateFormat } from "./numfmt-DCDrX9P1.js";
4
+ import { n as isDateFormat } from "./numfmt-Ci_oW11p.js";
5
5
  import { n as serialToDate } from "./dates-BXcSWf9_.js";
6
6
  // src/internal/read/limits.ts
7
7
  /** Default limits (docs/api.md §5.2; the measurements behind each value are listed there). */
package/dist/read.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_read = require("./read-tIwYuXES.cjs");
2
+ const require_read = require("./read-ByceXfiL.cjs");
3
3
  exports.DEFAULT_READ_LIMITS = require_read.DEFAULT_READ_LIMITS;
4
4
  exports.detectFormat = require_read.detectFormat;
5
5
  exports.read = require_read.read;
package/dist/read.js CHANGED
@@ -1 +1 @@
1
- export { t as DEFAULT_READ_LIMITS, n as detectFormat, r as read, i as readSheetNames } from "./read-DK5URBoq.js";
1
+ export { t as DEFAULT_READ_LIMITS, n as detectFormat, r as read, i as readSheetNames } from "./read-ClszMDAE.js";
@@ -706,10 +706,17 @@ function hyperlinkOf(input) {
706
706
  // src/sheet-names.ts
707
707
  const FORBIDDEN = /[\\/?*[\]:]/;
708
708
  const FORBIDDEN_ALL = /[\\/?*[\]:]/g;
709
+ const MAX_LENGTH = 31;
710
+ /** Length in code points, as Excel counts sheet names (a surrogate pair is one). */
711
+ function codePoints(s) {
712
+ let n = 0;
713
+ for (const _ of s) n++;
714
+ return n;
715
+ }
709
716
  /** Returns null when `name` is a valid sheet name, or the reason it is not. */
710
717
  function validateSheetName(name) {
711
718
  if (typeof name !== "string" || name.length === 0) return "empty";
712
- if (name.length > 31) return "too-long";
719
+ if (codePoints(name) > MAX_LENGTH) return "too-long";
713
720
  if (FORBIDDEN.test(name)) return "forbidden-char";
714
721
  if (name.startsWith("'") || name.endsWith("'")) return "apostrophe";
715
722
  if (name.toLowerCase() === "history") return "reserved";
@@ -718,16 +725,12 @@ function validateSheetName(name) {
718
725
  /**
719
726
  * Makes any string a valid sheet name: forbidden characters become '_',
720
727
  * leading and trailing apostrophes are removed, the result is cut to 31
721
- * characters (without splitting a surrogate pair), and an empty or reserved
722
- * result becomes 'Sheet'. Uniqueness is the caller's job.
728
+ * code points (never splitting a surrogate pair), and an empty or reserved
729
+ * result ('History' in any case) becomes 'Sheet'. Uniqueness is the caller's job.
723
730
  */
724
731
  function sanitizeSheetName(name) {
725
732
  let s = String(name ?? "").replace(FORBIDDEN_ALL, "_").replace(/^'+|'+$/g, "");
726
- if (s.length > 31) {
727
- s = s.slice(0, 31);
728
- if (/[\uD800-\uDBFF]$/.test(s)) s = s.slice(0, 30);
729
- s = s.replace(/'+$/, "");
730
- }
733
+ if (codePoints(s) > MAX_LENGTH) s = Array.from(s).slice(0, MAX_LENGTH).join("").replace(/'+$/, "");
731
734
  return s.length === 0 || s.toLowerCase() === "history" ? "Sheet" : s;
732
735
  }
733
736
  export { num as _, SheetFeatures as a, xstring as b, hyperlinkSchemes as c, PackageParts as d, REL_TYPE as f, needsPreserve as g, XML_DECL as h, DEFAULT_HYPERLINK_SCHEMES as i, textWidth as l, mergeStyles as m, validateSheetName as n, SheetLinks as o, Rels as p, AUTO_WIDTH as r, hyperlinkOf as s, sanitizeSheetName as t, CONTENT_TYPE as u, xmlAttr as v, xmlText as y };
@@ -706,10 +706,17 @@ function hyperlinkOf(input) {
706
706
  // src/sheet-names.ts
707
707
  const FORBIDDEN = /[\\/?*[\]:]/;
708
708
  const FORBIDDEN_ALL = /[\\/?*[\]:]/g;
709
+ const MAX_LENGTH = 31;
710
+ /** Length in code points, as Excel counts sheet names (a surrogate pair is one). */
711
+ function codePoints(s) {
712
+ let n = 0;
713
+ for (const _ of s) n++;
714
+ return n;
715
+ }
709
716
  /** Returns null when `name` is a valid sheet name, or the reason it is not. */
710
717
  function validateSheetName(name) {
711
718
  if (typeof name !== "string" || name.length === 0) return "empty";
712
- if (name.length > 31) return "too-long";
719
+ if (codePoints(name) > MAX_LENGTH) return "too-long";
713
720
  if (FORBIDDEN.test(name)) return "forbidden-char";
714
721
  if (name.startsWith("'") || name.endsWith("'")) return "apostrophe";
715
722
  if (name.toLowerCase() === "history") return "reserved";
@@ -718,16 +725,12 @@ function validateSheetName(name) {
718
725
  /**
719
726
  * Makes any string a valid sheet name: forbidden characters become '_',
720
727
  * leading and trailing apostrophes are removed, the result is cut to 31
721
- * characters (without splitting a surrogate pair), and an empty or reserved
722
- * result becomes 'Sheet'. Uniqueness is the caller's job.
728
+ * code points (never splitting a surrogate pair), and an empty or reserved
729
+ * result ('History' in any case) becomes 'Sheet'. Uniqueness is the caller's job.
723
730
  */
724
731
  function sanitizeSheetName(name) {
725
732
  let s = String(name ?? "").replace(FORBIDDEN_ALL, "_").replace(/^'+|'+$/g, "");
726
- if (s.length > 31) {
727
- s = s.slice(0, 31);
728
- if (/[\uD800-\uDBFF]$/.test(s)) s = s.slice(0, 30);
729
- s = s.replace(/'+$/, "");
730
- }
733
+ if (codePoints(s) > MAX_LENGTH) s = Array.from(s).slice(0, MAX_LENGTH).join("").replace(/'+$/, "");
731
734
  return s.length === 0 || s.toLowerCase() === "history" ? "Sheet" : s;
732
735
  }
733
736
  Object.defineProperty(exports, "AUTO_WIDTH", {
package/dist/worker.cjs CHANGED
@@ -1,9 +1,9 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_csv = require("./csv-DyVH9y7S.cjs");
3
3
  const require_errors = require("./errors-DOPrrGS4.cjs");
4
- const require_read = require("./read-tIwYuXES.cjs");
5
- const require_pipeline = require("./pipeline-CwLNDrKo.cjs");
6
- const require_write = require("./write-CXnhqht-.cjs");
4
+ const require_read = require("./read-ByceXfiL.cjs");
5
+ const require_pipeline = require("./pipeline-DMskqxiU.cjs");
6
+ const require_write = require("./write-DKXhuvKR.cjs");
7
7
  // src/worker.ts
8
8
  /** Marks the library's messages, so an app can use the same worker for its own messages too. */
9
9
  const TAG = "javascript-excel/worker@1";
package/dist/worker.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { i as toCsv, r as readCsv } from "./csv-pXfaputs.js";
2
2
  import { a as LimitError, i as FormatError, n as EnvironmentError, o as ValidationError, r as ExcelError, s as isExcelError, t as CsvError } from "./errors-CvGlfw0E.js";
3
- import { r as read } from "./read-DK5URBoq.js";
4
- import { t as importDataset } from "./pipeline-B9-qglvn.js";
5
- import { r as toUint8Array } from "./write-DyOq-Efq.js";
3
+ import { r as read } from "./read-ClszMDAE.js";
4
+ import { t as importDataset } from "./pipeline-2dw9aehe.js";
5
+ import { r as toUint8Array } from "./write-BVXB2_2C.js";
6
6
  // src/worker.ts
7
7
  /** Marks the library's messages, so an app can use the same worker for its own messages too. */
8
8
  const TAG = "javascript-excel/worker@1";
@@ -1,6 +1,6 @@
1
1
  import { n as EnvironmentError, o as ValidationError } from "./errors-CvGlfw0E.js";
2
2
  import { c as throttleProgress, d as throwIfAborted, i as nativeCodec, l as ByteWriter, n as toDosDateTime, o as encodeUtf8, r as crc32, s as createYielder, u as concatBytes } from "./dos-time-BsH7f0ef.js";
3
- import { _ as num, a as SheetFeatures, b as xstring, c as hyperlinkSchemes, d as PackageParts, f as REL_TYPE, g as needsPreserve, h as XML_DECL, m as mergeStyles, n as validateSheetName, o as SheetLinks, p as Rels, s as hyperlinkOf, u as CONTENT_TYPE, v as xmlAttr, y as xmlText } from "./sheet-names-7p-joVsG.js";
3
+ import { _ as num, a as SheetFeatures, b as xstring, c as hyperlinkSchemes, d as PackageParts, f as REL_TYPE, g as needsPreserve, h as XML_DECL, m as mergeStyles, n as validateSheetName, o as SheetLinks, p as Rels, s as hyperlinkOf, u as CONTENT_TYPE, v as xmlAttr, y as xmlText } from "./sheet-names-BLrwcn33.js";
4
4
  import { a as decodeRange, n as MAX_ROWS, s as encodeCol } from "./address-DUn7-5OS.js";
5
5
  import { t as dateToSerial } from "./dates-BXcSWf9_.js";
6
6
  import { t as cellText } from "./cells-CrMF8h_t.js";
@@ -1,6 +1,6 @@
1
1
  const require_errors = require("./errors-DOPrrGS4.cjs");
2
2
  const require_dos_time = require("./dos-time-CxEs--rI.cjs");
3
- const require_sheet_names = require("./sheet-names-B8U5RAW0.cjs");
3
+ const require_sheet_names = require("./sheet-names-DDY64-dt.cjs");
4
4
  const require_address = require("./address-DZBHchLv.cjs");
5
5
  const require_dates = require("./dates-CA1dCizp.cjs");
6
6
  const require_cells = require("./cells-CPXU722t.cjs");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "javascript-excel",
3
- "version": "2.0.0-alpha.7",
3
+ "version": "2.0.0-beta.1",
4
4
  "private": false,
5
5
  "description": "Read and write .xlsx and .csv files in browsers, Web Workers and Node. 2.0 is a from-scratch rewrite in progress.",
6
6
  "keywords": [