@shbernal/ts-xlsx 1.3.1 → 2.0.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.
Files changed (155) hide show
  1. package/dist/core/address.d.ts +49 -2
  2. package/dist/core/address.js +31 -3
  3. package/dist/core/autofilter.d.ts +2 -2
  4. package/dist/core/cell.d.ts +17 -16
  5. package/dist/core/cell.js +3 -7
  6. package/dist/core/color-resolution.d.ts +7 -7
  7. package/dist/core/column.d.ts +8 -9
  8. package/dist/core/column.js +2 -4
  9. package/dist/core/comment-thread.d.ts +32 -23
  10. package/dist/core/comment-thread.js +4 -4
  11. package/dist/core/conditional-formatting-overlay.d.ts +1 -1
  12. package/dist/core/conditional-formatting.d.ts +3 -3
  13. package/dist/core/data-validation-overlay.d.ts +1 -1
  14. package/dist/core/data-validation.d.ts +3 -3
  15. package/dist/core/date.d.ts +3 -3
  16. package/dist/core/formula.d.ts +6 -6
  17. package/dist/core/grid-edits.js +3 -3
  18. package/dist/core/image.d.ts +37 -2
  19. package/dist/core/image.js +6 -0
  20. package/dist/core/internal.d.ts +9 -1
  21. package/dist/core/limits.d.ts +4 -4
  22. package/dist/core/merge.d.ts +6 -12
  23. package/dist/core/merge.js +0 -3
  24. package/dist/core/page-setup.d.ts +4 -4
  25. package/dist/core/pivot-table.d.ts +2 -4
  26. package/dist/core/pivot-table.js +5 -5
  27. package/dist/core/preserved.d.ts +3 -3
  28. package/dist/core/protection.d.ts +4 -4
  29. package/dist/core/range.d.ts +16 -14
  30. package/dist/core/range.js +5 -5
  31. package/dist/core/row-input.d.ts +2 -8
  32. package/dist/core/row-input.js +2 -2
  33. package/dist/core/row.d.ts +7 -8
  34. package/dist/core/row.js +2 -4
  35. package/dist/core/style.d.ts +14 -14
  36. package/dist/core/table-style.d.ts +9 -9
  37. package/dist/core/table-style.js +1 -1
  38. package/dist/core/table.d.ts +30 -42
  39. package/dist/core/table.js +16 -10
  40. package/dist/core/theme.d.ts +13 -43
  41. package/dist/core/theme.js +2 -148
  42. package/dist/core/value.d.ts +7 -7
  43. package/dist/core/workbook-protection.d.ts +2 -2
  44. package/dist/core/workbook-styles.d.ts +26 -0
  45. package/dist/core/workbook-styles.js +48 -0
  46. package/dist/core/workbook-theme.d.ts +25 -0
  47. package/dist/core/workbook-theme.js +49 -0
  48. package/dist/core/workbook-vba.d.ts +17 -0
  49. package/dist/core/workbook-vba.js +79 -0
  50. package/dist/core/workbook.d.ts +131 -85
  51. package/dist/core/workbook.js +74 -133
  52. package/dist/core/worksheet-comments.d.ts +9 -0
  53. package/dist/core/worksheet-comments.js +52 -0
  54. package/dist/core/worksheet-model.d.ts +4 -4
  55. package/dist/core/worksheet-model.js +1 -0
  56. package/dist/core/worksheet-pictures.d.ts +29 -0
  57. package/dist/core/worksheet-pictures.js +42 -0
  58. package/dist/core/worksheet.d.ts +85 -77
  59. package/dist/core/worksheet.js +36 -95
  60. package/dist/customui/errors.d.ts +1 -1
  61. package/dist/customui/ribbon.d.ts +3 -3
  62. package/dist/entries/core.d.ts +4 -4
  63. package/dist/entries/core.js +1 -1
  64. package/dist/entries/vba.d.ts +1 -1
  65. package/dist/entries/vba.js +1 -1
  66. package/dist/entries/xlsx.d.ts +1 -0
  67. package/dist/entries/xlsx.js +1 -0
  68. package/dist/errors.d.ts +12 -12
  69. package/dist/io/csv/read.js +1 -2
  70. package/dist/io/csv/write.d.ts +8 -3
  71. package/dist/io/csv/write.js +17 -2
  72. package/dist/io/opc/errors.d.ts +6 -6
  73. package/dist/io/opc/inflate.d.ts +1 -1
  74. package/dist/io/opc/namespaces.d.ts +1 -1
  75. package/dist/io/opc/read-opc.d.ts +19 -3
  76. package/dist/io/opc/read-opc.js +14 -8
  77. package/dist/io/opc/read-options.d.ts +2 -2
  78. package/dist/io/opc/sniff-format.d.ts +2 -2
  79. package/dist/io/style/xf-style.d.ts +38 -6
  80. package/dist/io/style/xf-style.js +22 -0
  81. package/dist/io/xlsb/errors.d.ts +1 -1
  82. package/dist/io/xlsb/formula.d.ts +4 -4
  83. package/dist/io/xlsb/primitives.d.ts +8 -8
  84. package/dist/io/xlsb/ptg-functions.d.ts +1 -1
  85. package/dist/io/xlsb/read-styles.js +2 -20
  86. package/dist/io/xlsb/read.d.ts +2 -2
  87. package/dist/io/xlsx/cell-accumulator.d.ts +25 -6
  88. package/dist/io/xlsx/cell-accumulator.js +111 -30
  89. package/dist/io/xlsx/cell-value.d.ts +2 -2
  90. package/dist/io/xlsx/cell-value.js +3 -3
  91. package/dist/io/xlsx/color-xml.js +11 -17
  92. package/dist/io/xlsx/comments.d.ts +5 -5
  93. package/dist/io/xlsx/comments.js +13 -6
  94. package/dist/io/xlsx/conditional-formatting.d.ts +3 -3
  95. package/dist/io/xlsx/conditional-formatting.js +7 -16
  96. package/dist/io/xlsx/data-validation.d.ts +2 -2
  97. package/dist/io/xlsx/data-validation.js +1 -1
  98. package/dist/io/xlsx/errors.d.ts +3 -3
  99. package/dist/io/xlsx/hyperlinks.d.ts +4 -2
  100. package/dist/io/xlsx/hyperlinks.js +5 -5
  101. package/dist/io/xlsx/images.d.ts +1 -1
  102. package/dist/io/xlsx/images.js +8 -8
  103. package/dist/io/xlsx/namespaces.d.ts +2 -2
  104. package/dist/io/xlsx/package-plan.js +5 -2
  105. package/dist/io/xlsx/read-pivot.js +2 -5
  106. package/dist/io/xlsx/read-rows.d.ts +13 -13
  107. package/dist/io/xlsx/read-rows.js +19 -55
  108. package/dist/io/xlsx/read-shared-strings.js +7 -5
  109. package/dist/io/xlsx/read-styles.d.ts +3 -3
  110. package/dist/io/xlsx/read-styles.js +40 -65
  111. package/dist/io/xlsx/read-worksheet.js +61 -115
  112. package/dist/io/xlsx/read.d.ts +3 -5
  113. package/dist/io/xlsx/read.js +61 -69
  114. package/dist/io/xlsx/rich-runs.d.ts +1 -1
  115. package/dist/io/xlsx/rich-runs.js +1 -1
  116. package/dist/io/xlsx/rich-text.d.ts +1 -1
  117. package/dist/io/xlsx/shared-strings.d.ts +2 -2
  118. package/dist/io/xlsx/sheet-properties.js +2 -2
  119. package/dist/io/xlsx/styles.d.ts +8 -9
  120. package/dist/io/xlsx/styles.js +4 -3
  121. package/dist/io/xlsx/tables.d.ts +2 -2
  122. package/dist/io/xlsx/tables.js +8 -13
  123. package/dist/io/xlsx/theme-xml.d.ts +37 -0
  124. package/dist/io/xlsx/theme-xml.js +142 -0
  125. package/dist/io/xlsx/threaded-comments.d.ts +18 -27
  126. package/dist/io/xlsx/threaded-comments.js +9 -21
  127. package/dist/io/xlsx/worksheet-xml.d.ts +2 -2
  128. package/dist/io/xlsx/worksheet-xml.js +7 -12
  129. package/dist/io/xlsx/write-stream.d.ts +15 -15
  130. package/dist/io/xlsx/write-stream.js +3 -3
  131. package/dist/io/xlsx/write.d.ts +8 -7
  132. package/dist/io/xlsx/write.js +6 -3
  133. package/dist/io/xlsx/x14-ext.d.ts +1 -1
  134. package/dist/vba/bytes.d.ts +12 -0
  135. package/dist/vba/bytes.js +40 -0
  136. package/dist/vba/cfb-writer.d.ts +1 -1
  137. package/dist/vba/cfb.d.ts +1 -1
  138. package/dist/vba/cfb.js +15 -51
  139. package/dist/vba/codepage.d.ts +2 -2
  140. package/dist/vba/errors.d.ts +2 -2
  141. package/dist/vba/index.d.ts +2 -2
  142. package/dist/vba/index.js +2 -2
  143. package/dist/vba/ms-ovba.d.ts +1 -1
  144. package/dist/vba/ms-ovba.js +1 -3
  145. package/dist/vba/project-editor.d.ts +9 -9
  146. package/dist/vba/project-editor.js +2 -11
  147. package/dist/vba/project.d.ts +5 -5
  148. package/dist/vba/project.js +1 -10
  149. package/dist/vba/vba-encoding.d.ts +1 -1
  150. package/dist/xml/errors.d.ts +1 -1
  151. package/dist/xml/xml-read.d.ts +38 -9
  152. package/dist/xml/xml-read.js +23 -0
  153. package/dist/xml/xml.d.ts +31 -9
  154. package/dist/xml/xml.js +23 -3
  155. package/package.json +41 -35
package/dist/xml/xml.js CHANGED
@@ -14,18 +14,38 @@ const ATTR_ESCAPES = {
14
14
  '\r': '
',
15
15
  '\t': '	',
16
16
  };
17
+ const UNREPRESENTABLE = /[\u{0}-\u{8}\u{B}\u{C}\u{E}-\u{1F}\u{FFFE}\u{FFFF}\u{D800}-\u{DFFF}]/u;
18
+ const UNREPRESENTABLE_GLOBAL = new RegExp(UNREPRESENTABLE.source, 'gu');
19
+ function codePointHex(codePoint) {
20
+ return codePoint.toString(16).toUpperCase().padStart(4, '0');
21
+ }
22
+ export function assertRepresentable(value) {
23
+ const found = UNREPRESENTABLE.exec(value);
24
+ if (found === null)
25
+ return;
26
+ throw new AuthoringError(`cannot write U+${codePointHex(value.codePointAt(found.index))} at offset ${found.index}: ` +
27
+ 'XML 1.0 has no representation for it, and the _xHHHH_ escape that would carry it is a ' +
28
+ 'convention of cell values only');
29
+ }
17
30
  export function escapeText(value) {
31
+ assertRepresentable(value);
18
32
  return value.replace(/[&<>]/g, (ch) => TEXT_ESCAPES[ch]);
19
33
  }
20
34
  export function escapeAttr(value) {
35
+ assertRepresentable(value);
21
36
  return value.replace(/[&<>"'\n\r\t]/g, (ch) => ATTR_ESCAPES[ch]);
22
37
  }
23
- export function needsSpacePreserve(value) {
38
+ export function escapeSpreadsheetText(value) {
39
+ return escapeText(value
40
+ .replace(/_(x[0-9A-Fa-f]{4}_)/g, '_x005F_$1')
41
+ .replace(UNREPRESENTABLE_GLOBAL, (ch) => `_x${codePointHex(ch.codePointAt(0))}_`));
42
+ }
43
+ function needsSpacePreserve(value) {
24
44
  return value.length > 0 && (value !== value.trim() || /[\n\r\t]/.test(value));
25
45
  }
26
46
  export function textElement(value) {
27
47
  const space = needsSpacePreserve(value) ? ' xml:space="preserve"' : '';
28
- return `<t${space}>${escapeText(value)}</t>`;
48
+ return `<t${space}>${escapeSpreadsheetText(value)}</t>`;
29
49
  }
30
50
  export function stripFormulaEquals(value) {
31
51
  if (typeof value === 'number')
@@ -40,7 +60,7 @@ export function attr(name, value) {
40
60
  }
41
61
  export function numberText(value) {
42
62
  if (!Number.isFinite(value)) {
43
- throw new AuthoringError(`cannot write a non-finite number (${value}) it has no OOXML representation`);
63
+ throw new AuthoringError(`cannot write a non-finite number (${value}): it has no OOXML representation`);
44
64
  }
45
65
  return String(value);
46
66
  }
package/package.json CHANGED
@@ -1,23 +1,37 @@
1
1
  {
2
2
  "name": "@shbernal/ts-xlsx",
3
- "version": "1.3.1",
3
+ "version": "2.0.0",
4
4
  "description": "A TypeScript-first library for reading and writing xlsx (OOXML) spreadsheets.",
5
+ "keywords": [
6
+ "csv",
7
+ "excel",
8
+ "ooxml",
9
+ "spreadsheet",
10
+ "streaming",
11
+ "typescript",
12
+ "workbook",
13
+ "xlsx"
14
+ ],
15
+ "homepage": "https://github.com/shbernal/ts-xlsx#readme",
16
+ "bugs": {
17
+ "url": "https://github.com/shbernal/ts-xlsx/issues"
18
+ },
5
19
  "license": "MIT",
6
20
  "author": "shbernal",
7
- "type": "module",
8
21
  "repository": {
9
22
  "type": "git",
10
23
  "url": "https://github.com/shbernal/ts-xlsx.git"
11
24
  },
12
- "homepage": "https://github.com/shbernal/ts-xlsx#readme",
13
- "bugs": {
14
- "url": "https://github.com/shbernal/ts-xlsx/issues"
15
- },
16
- "engines": {
17
- "node": ">=24"
18
- },
19
- "packageManager": "pnpm@11.11.0",
25
+ "files": [
26
+ "dist",
27
+ "skills",
28
+ "LICENSE",
29
+ "README.md"
30
+ ],
31
+ "type": "module",
20
32
  "sideEffects": false,
33
+ "main": "./dist/index.js",
34
+ "types": "./dist/index.d.ts",
21
35
  "exports": {
22
36
  ".": {
23
37
  "types": "./dist/index.d.ts",
@@ -53,17 +67,9 @@
53
67
  },
54
68
  "./package.json": "./package.json"
55
69
  },
56
- "main": "./dist/index.js",
57
- "types": "./dist/index.d.ts",
58
70
  "publishConfig": {
59
71
  "access": "public"
60
72
  },
61
- "files": [
62
- "dist",
63
- "skills",
64
- "LICENSE",
65
- "README.md"
66
- ],
67
73
  "scripts": {
68
74
  "prepare": "node scripts/install-hooks.ts",
69
75
  "clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
@@ -76,42 +82,42 @@
76
82
  "layering:check": "node scripts/check-layering.ts",
77
83
  "entries:check": "node scripts/check-entries.ts",
78
84
  "source-text:check": "node scripts/check-source-text.ts",
79
- "lint": "biome check --error-on-warnings src scripts test tools",
80
- "lint:fix": "biome check --write --error-on-warnings src scripts test tools",
81
- "format": "biome format --write src scripts test tools",
85
+ "chars:check": "charcheck",
86
+ "lint": "node node_modules/oxlint/bin/oxlint src scripts test tools charcheck.config.ts --type-aware --deny-warnings --report-unused-disable-directives",
87
+ "lint:fix": "pnpm run lint --fix",
88
+ "format": "node scripts/format.ts --write",
89
+ "format:check": "node scripts/format.ts --check",
82
90
  "typecheck": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.test.json",
83
91
  "typecheck:src": "tsc --noEmit -p tsconfig.json",
84
92
  "typecheck:test": "tsc --noEmit -p tsconfig.test.json",
85
93
  "typecheck:dist": "tsc --noEmit -p tsconfig.dist.json",
86
94
  "test:src": "node --test \"src/**/*.test.ts\"",
87
- "test:coverage": "node --test --experimental-test-coverage \"src/**/*.test.ts\"",
95
+ "coverage": "node scripts/coverage.ts",
88
96
  "corpus": "node test/corpus/run.ts",
89
97
  "corpus:dist": "node test/corpus/run.ts --target dist",
90
98
  "verify": "node scripts/verify.ts --full",
91
99
  "verify:quick": "node scripts/verify.ts --quick",
92
100
  "test": "node scripts/verify.ts --full",
93
101
  "prepublishOnly": "pnpm run build && pnpm run test && pnpm run smoke:dist && pnpm run size",
94
- "validate:ooxml": "node scripts/ooxml-validator.ts",
102
+ "validate:ooxml": "ooxml-validate",
95
103
  "test:ooxml": "node test/ooxml-validation/run.ts"
96
104
  },
97
- "keywords": [
98
- "xlsx",
99
- "ooxml",
100
- "excel",
101
- "spreadsheet",
102
- "csv",
103
- "typescript",
104
- "workbook",
105
- "streaming"
106
- ],
107
105
  "dependencies": {
108
106
  "fflate": "^0.8.3"
109
107
  },
110
108
  "devDependencies": {
111
- "@biomejs/biome": "2.5.7",
112
109
  "@types/node": "^24.13.3",
110
+ "charcheck": "^0.3.0",
113
111
  "jszip": "^3.10.1",
114
112
  "lefthook": "^2.1.10",
113
+ "ooxml-validate": "^0.0.3",
114
+ "oxfmt": "^0.64.0",
115
+ "oxlint": "^1.80.0",
116
+ "oxlint-tsgolint": "7.0.2001",
115
117
  "typescript": "^7.0.2"
116
- }
118
+ },
119
+ "engines": {
120
+ "node": ">=24"
121
+ },
122
+ "packageManager": "pnpm@11.11.0"
117
123
  }