musicxml-io 0.5.2 → 0.5.4

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
@@ -244,7 +244,8 @@ function decodeTree(nodes) {
244
244
  }
245
245
  var TXML_OPTIONS = { noChildNodes: [] };
246
246
  function parse(xmlString) {
247
- const parsed = _txml.parse.call(void 0, xmlString, TXML_OPTIONS);
247
+ const cleanedXml = xmlString.replace(/<\?(?!xml\s)[^?]*\?>/g, "");
248
+ const parsed = _txml.parse.call(void 0, cleanedXml, TXML_OPTIONS);
248
249
  decodeTree(parsed);
249
250
  let scorePartwiseVersion;
250
251
  let scorePartwise;
@@ -2759,6 +2760,15 @@ function parseCompressed(data) {
2759
2760
  function isCompressed(data) {
2760
2761
  return data.length >= 2 && data[0] === 80 && data[1] === 75;
2761
2762
  }
2763
+ function decodeXmlBytes(data) {
2764
+ if (data.length >= 2 && data[0] === 254 && data[1] === 255) {
2765
+ return new TextDecoder("utf-16be").decode(data);
2766
+ }
2767
+ if (data.length >= 2 && data[0] === 255 && data[1] === 254) {
2768
+ return new TextDecoder("utf-16le").decode(data);
2769
+ }
2770
+ return new TextDecoder("utf-8").decode(data);
2771
+ }
2762
2772
  function parseAuto(data) {
2763
2773
  if (typeof data === "string") {
2764
2774
  return parse(data);
@@ -2766,7 +2776,7 @@ function parseAuto(data) {
2766
2776
  if (isCompressed(data)) {
2767
2777
  return parseCompressed(data);
2768
2778
  }
2769
- const xmlString = _fflate.strFromU8.call(void 0, data);
2779
+ const xmlString = decodeXmlBytes(data);
2770
2780
  return parse(xmlString);
2771
2781
  }
2772
2782
 
@@ -7874,10 +7884,10 @@ async function parseFile(filePath) {
7874
7884
  }
7875
7885
  function decodeBuffer(buffer) {
7876
7886
  if (buffer.length >= 2 && buffer[0] === 254 && buffer[1] === 255) {
7877
- return buffer.swap16().toString("utf-16le");
7887
+ return new TextDecoder("utf-16be").decode(buffer);
7878
7888
  }
7879
7889
  if (buffer.length >= 2 && buffer[0] === 255 && buffer[1] === 254) {
7880
- return buffer.toString("utf16le");
7890
+ return new TextDecoder("utf-16le").decode(buffer);
7881
7891
  }
7882
7892
  if (buffer.length >= 3 && buffer[0] === 239 && buffer[1] === 187 && buffer[2] === 191) {
7883
7893
  return buffer.toString("utf8", 3);
package/dist/index.mjs CHANGED
@@ -244,7 +244,8 @@ function decodeTree(nodes) {
244
244
  }
245
245
  var TXML_OPTIONS = { noChildNodes: [] };
246
246
  function parse(xmlString) {
247
- const parsed = txmlParse(xmlString, TXML_OPTIONS);
247
+ const cleanedXml = xmlString.replace(/<\?(?!xml\s)[^?]*\?>/g, "");
248
+ const parsed = txmlParse(cleanedXml, TXML_OPTIONS);
248
249
  decodeTree(parsed);
249
250
  let scorePartwiseVersion;
250
251
  let scorePartwise;
@@ -2759,6 +2760,15 @@ function parseCompressed(data) {
2759
2760
  function isCompressed(data) {
2760
2761
  return data.length >= 2 && data[0] === 80 && data[1] === 75;
2761
2762
  }
2763
+ function decodeXmlBytes(data) {
2764
+ if (data.length >= 2 && data[0] === 254 && data[1] === 255) {
2765
+ return new TextDecoder("utf-16be").decode(data);
2766
+ }
2767
+ if (data.length >= 2 && data[0] === 255 && data[1] === 254) {
2768
+ return new TextDecoder("utf-16le").decode(data);
2769
+ }
2770
+ return new TextDecoder("utf-8").decode(data);
2771
+ }
2762
2772
  function parseAuto(data) {
2763
2773
  if (typeof data === "string") {
2764
2774
  return parse(data);
@@ -2766,7 +2776,7 @@ function parseAuto(data) {
2766
2776
  if (isCompressed(data)) {
2767
2777
  return parseCompressed(data);
2768
2778
  }
2769
- const xmlString = strFromU8(data);
2779
+ const xmlString = decodeXmlBytes(data);
2770
2780
  return parse(xmlString);
2771
2781
  }
2772
2782
 
@@ -7874,10 +7884,10 @@ async function parseFile(filePath) {
7874
7884
  }
7875
7885
  function decodeBuffer(buffer) {
7876
7886
  if (buffer.length >= 2 && buffer[0] === 254 && buffer[1] === 255) {
7877
- return buffer.swap16().toString("utf-16le");
7887
+ return new TextDecoder("utf-16be").decode(buffer);
7878
7888
  }
7879
7889
  if (buffer.length >= 2 && buffer[0] === 255 && buffer[1] === 254) {
7880
- return buffer.toString("utf16le");
7890
+ return new TextDecoder("utf-16le").decode(buffer);
7881
7891
  }
7882
7892
  if (buffer.length >= 3 && buffer[0] === 239 && buffer[1] === 187 && buffer[2] === 191) {
7883
7893
  return buffer.toString("utf8", 3);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musicxml-io",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
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",