@particle-academy/holy-sheet 2.0.2 → 2.2.0

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/index.cjs CHANGED
@@ -7,11 +7,12 @@ function isNumericString(v) {
7
7
  return /^\s*[+-]?(\d+(\.\d+)?|\.\d+)([eE][+-]?\d+)?$/.test(v);
8
8
  }
9
9
  function numericStringToNumber(v) {
10
- return v.includes(".") ? parseFloat(v) : parseInt(v, 10);
10
+ return Number(v);
11
11
  }
12
12
  function formatFloat(v) {
13
- let s = v.toFixed(14);
14
- s = s.replace(/0+$/, "").replace(/\.$/, "");
13
+ if (!Number.isFinite(v)) return "0";
14
+ let s = Math.abs(v) >= 1e21 ? BigInt(v).toString() : v.toFixed(14);
15
+ if (s.includes(".")) s = s.replace(/0+$/, "").replace(/\.$/, "");
15
16
  return s === "" || s === "-0" ? "0" : s;
16
17
  }
17
18
  function typeOf(value) {
@@ -510,16 +511,6 @@ var Normalizer = class {
510
511
  }
511
512
  normalizeSheet(sheet) {
512
513
  const name = String(sheet.name);
513
- if (sheet.cells != null) {
514
- return new Sheet(
515
- name,
516
- this.normalizeCellMap(sheet.cells),
517
- this.normalizeMerges(sheet.mergedRegions ?? []),
518
- this.normalizeColumnWidths(sheet.columnWidths ?? {}),
519
- toInt(sheet.frozenRows ?? 0),
520
- toInt(sheet.frozenCols ?? 0)
521
- );
522
- }
523
514
  const cells = /* @__PURE__ */ new Map();
524
515
  const columns = sheet.columns ?? [];
525
516
  const rows = sheet.rows ?? [];
@@ -571,6 +562,22 @@ var Normalizer = class {
571
562
  cells.set(address, new Cell(address, null, `${excelFunc}(${rangeStart}:${rangeEnd})`, combined));
572
563
  }
573
564
  }
565
+ if (sheet.cells != null) {
566
+ for (const [address, cell] of this.normalizeCellMap(sheet.cells)) {
567
+ const beneath = cells.get(address);
568
+ cells.set(
569
+ address,
570
+ beneath?.format ? new Cell(
571
+ cell.address,
572
+ cell.value,
573
+ cell.formula,
574
+ beneath.format.mergeWith(cell.format),
575
+ cell.comment,
576
+ cell.cachedValue
577
+ ) : cell
578
+ );
579
+ }
580
+ }
574
581
  return new Sheet(
575
582
  name,
576
583
  cells,
@@ -583,12 +590,20 @@ var Normalizer = class {
583
590
  normalizeCellMap(map) {
584
591
  const cells = /* @__PURE__ */ new Map();
585
592
  for (const [address, cellData] of Object.entries(map)) {
586
- const format = cellData && isPlainObject(cellData.format) ? CellFormat.fromInput(cellData.format) : null;
587
- const comment = cellData && isPlainObject(cellData.comment) ? new CellComment(
593
+ if (!isPlainObject(cellData)) {
594
+ const [bare, formula] = promoteFormula(cellData);
595
+ cells.set(
596
+ address,
597
+ new Cell(address, formula !== null ? null : this.coerceValue(bare, null), formula)
598
+ );
599
+ continue;
600
+ }
601
+ const format = isPlainObject(cellData.format) ? CellFormat.fromInput(cellData.format) : null;
602
+ const comment = isPlainObject(cellData.comment) ? new CellComment(
588
603
  String(cellData.comment.text ?? ""),
589
604
  cellData.comment.author ?? null,
590
605
  cellData.comment.color ?? null
591
- ) : null;
606
+ ) : typeof cellData.comment === "string" ? new CellComment(cellData.comment) : null;
592
607
  const rawValue = cellData?.value ?? null;
593
608
  cells.set(
594
609
  address,
@@ -661,7 +676,13 @@ var Normalizer = class {
661
676
  value.computedValue ?? null
662
677
  );
663
678
  }
664
- return new Cell(address, this.coerceValue(value, columnFormat), null, columnFormat);
679
+ const [bare, formula] = promoteFormula(value);
680
+ return new Cell(
681
+ address,
682
+ formula !== null ? null : this.coerceValue(bare, columnFormat),
683
+ formula,
684
+ columnFormat
685
+ );
665
686
  }
666
687
  coerceValue(value, format) {
667
688
  if (value === null || value === void 0) return null;
@@ -683,6 +704,12 @@ var Normalizer = class {
683
704
  return value;
684
705
  }
685
706
  };
707
+ function promoteFormula(value) {
708
+ if (typeof value === "string" && value.length > 1 && value[0] === "=") {
709
+ return [null, value.slice(1)];
710
+ }
711
+ return [value, null];
712
+ }
686
713
  function toInt(v) {
687
714
  const n = Math.trunc(Number(v));
688
715
  return Number.isFinite(n) ? n : 0;
@@ -2876,7 +2903,7 @@ var XlsxWriter = class {
2876
2903
  }
2877
2904
  let v;
2878
2905
  if (typeof cell.value === "number") {
2879
- v = Number.isInteger(cell.value) ? String(cell.value) : formatFloat(cell.value);
2906
+ v = Number.isInteger(cell.value) && Math.abs(cell.value) < 1e21 ? String(cell.value) : formatFloat(cell.value);
2880
2907
  } else {
2881
2908
  v = String(cell.value);
2882
2909
  }