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