musicxml-io 0.5.5 → 0.6.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
@@ -223,13 +223,16 @@ function decodeXmlEntities(s) {
223
223
  (_, named, dec, hex) => named ? _entityMap[named] : dec ? String.fromCharCode(parseInt(dec, 10)) : String.fromCharCode(parseInt(hex, 16))
224
224
  );
225
225
  }
226
+ var INVALID_XML_CHARS_RE = /[\x00-\x08\x0B\x0C\x0E-\x1F\uFFFE\uFFFF]/g;
226
227
  function decodeTree(nodes) {
227
228
  for (let i = 0; i < nodes.length; i++) {
228
229
  const node = nodes[i];
229
230
  if (typeof node === "string") {
230
- if (node.indexOf("&") !== -1) {
231
- nodes[i] = decodeXmlEntities(node);
231
+ let s = node;
232
+ if (s.indexOf("&") !== -1) {
233
+ s = decodeXmlEntities(s);
232
234
  }
235
+ nodes[i] = s.replace(INVALID_XML_CHARS_RE, "");
233
236
  } else {
234
237
  const attrs = node.attributes;
235
238
  for (const key in attrs) {
@@ -257,7 +260,9 @@ function parse(input) {
257
260
  if (typeof input !== "string") {
258
261
  xmlString = decodeXmlBytes(input);
259
262
  } else if (input.includes("\0")) {
260
- xmlString = input.replace(/\x00/g, "");
263
+ throw new Error(
264
+ "parse() received a string containing NUL bytes, which indicates a UTF-16 encoded MusicXML file was read without proper encoding detection. Pass a Buffer or Uint8Array instead so the encoding is handled automatically:\n parse(fs.readFileSync(path)) // Node.js\n parse(new Uint8Array(arrayBuffer)) // Browser"
265
+ );
261
266
  } else {
262
267
  xmlString = input;
263
268
  }
package/dist/index.mjs CHANGED
@@ -223,13 +223,16 @@ function decodeXmlEntities(s) {
223
223
  (_, named, dec, hex) => named ? _entityMap[named] : dec ? String.fromCharCode(parseInt(dec, 10)) : String.fromCharCode(parseInt(hex, 16))
224
224
  );
225
225
  }
226
+ var INVALID_XML_CHARS_RE = /[\x00-\x08\x0B\x0C\x0E-\x1F\uFFFE\uFFFF]/g;
226
227
  function decodeTree(nodes) {
227
228
  for (let i = 0; i < nodes.length; i++) {
228
229
  const node = nodes[i];
229
230
  if (typeof node === "string") {
230
- if (node.indexOf("&") !== -1) {
231
- nodes[i] = decodeXmlEntities(node);
231
+ let s = node;
232
+ if (s.indexOf("&") !== -1) {
233
+ s = decodeXmlEntities(s);
232
234
  }
235
+ nodes[i] = s.replace(INVALID_XML_CHARS_RE, "");
233
236
  } else {
234
237
  const attrs = node.attributes;
235
238
  for (const key in attrs) {
@@ -257,7 +260,9 @@ function parse(input) {
257
260
  if (typeof input !== "string") {
258
261
  xmlString = decodeXmlBytes(input);
259
262
  } else if (input.includes("\0")) {
260
- xmlString = input.replace(/\x00/g, "");
263
+ throw new Error(
264
+ "parse() received a string containing NUL bytes, which indicates a UTF-16 encoded MusicXML file was read without proper encoding detection. Pass a Buffer or Uint8Array instead so the encoding is handled automatically:\n parse(fs.readFileSync(path)) // Node.js\n parse(new Uint8Array(arrayBuffer)) // Browser"
265
+ );
261
266
  } else {
262
267
  xmlString = input;
263
268
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musicxml-io",
3
- "version": "0.5.5",
3
+ "version": "0.6.0",
4
4
  "description": "Parse and serialize MusicXML (.xml/.mxl) and ABC notation with high round-trip fidelity",
5
5
  "author": "tan-z-tan",
6
6
  "license": "MIT",
@@ -13,7 +13,7 @@
13
13
  "url": "https://github.com/tan-z-tan/musicxml-io/issues"
14
14
  },
15
15
  "engines": {
16
- "node": ">=18.0.0"
16
+ "node": ">=20.12.0"
17
17
  },
18
18
  "main": "dist/index.js",
19
19
  "module": "dist/index.mjs",
@@ -70,19 +70,19 @@
70
70
  "abc-notation"
71
71
  ],
72
72
  "devDependencies": {
73
- "@types/node": "^20.10.0",
73
+ "@types/node": "^25.6.0",
74
74
  "@typescript-eslint/eslint-plugin": "^8.57.2",
75
75
  "@typescript-eslint/parser": "^8.57.2",
76
76
  "eslint": "^10.1.0",
77
77
  "tsup": "^8.0.1",
78
78
  "tsx": "^4.21.0",
79
79
  "typescript": "^5.3.3",
80
- "vitest": "^1.1.0"
80
+ "vitest": "^4.1.4"
81
81
  },
82
82
  "dependencies": {
83
83
  "fflate": "^0.8.2",
84
84
  "nanoid": "^5.1.6",
85
- "txml": "^5.2.1"
85
+ "txml": "^6.0.0"
86
86
  },
87
87
  "files": [
88
88
  "dist"