@lotics/xlsx 0.1.1 → 0.1.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lotics/xlsx",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./src/index.ts",
@@ -59,6 +59,18 @@ describe("buildDataWorkbook", () => {
59
59
  expect(cellAt(sheet, 2, 4)?.rawValue).toBe(2);
60
60
  });
61
61
 
62
+ it("preserves leading zeros on numeric-looking text (tax IDs, phone numbers)", () => {
63
+ // A text cell whose content looks like a number must round-trip as the exact
64
+ // string — fast-xml-parser's default tag coercion would otherwise read the
65
+ // shared-string `<t>0312345678</t>` as 312345678 and drop the leading zero.
66
+ const sheet = roundTrip<{ mst: string }>({
67
+ columns: [{ header: "MST", type: "text", value: (r) => r.mst }],
68
+ rows: [{ mst: "0312345678" }, { mst: "0001" }],
69
+ });
70
+ expect(cellAt(sheet, 2, 1)?.value).toBe("0312345678");
71
+ expect(cellAt(sheet, 3, 1)?.value).toBe("0001");
72
+ });
73
+
62
74
  it("leaves null cells empty rather than writing zeros or blanks", () => {
63
75
  const sheet = roundTrip<FeeRow>({
64
76
  columns: [
@@ -37,6 +37,12 @@ export interface SharedStringEntry {
37
37
  const xmlParser = new XMLParser({
38
38
  ignoreAttributes: false,
39
39
  attributeNamePrefix: "@_",
40
+ // Shared-string and workbook text is textual BY DEFINITION (tax IDs, phone
41
+ // numbers, account codes, sheet/defined names). fast-xml-parser's default tag
42
+ // coercion would parse `<t>0312345678</t>` as the number 312345678 — silently
43
+ // dropping the leading zero before we can read it. Cell `<v>` numerics are
44
+ // parsed deliberately (parseFloat) in ooxml_sheet.ts, so this never affects them.
45
+ parseTagValue: false,
40
46
  trimValues: false,
41
47
  processEntities: false,
42
48
  isArray: (tagName) =>