musicxml-io 0.3.7 → 0.3.8

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
@@ -220,7 +220,7 @@ var xmlParser = new (0, _fastxmlparser.XMLParser)({
220
220
  textNodeName: "#text",
221
221
  parseAttributeValue: false,
222
222
  parseTagValue: false,
223
- trimValues: true,
223
+ trimValues: false,
224
224
  preserveOrder: true
225
225
  });
226
226
  function parse(xmlString) {
@@ -253,9 +253,12 @@ function findElement(elements, tagName) {
253
253
  function getElementContent(elements, tagName) {
254
254
  return findElement(elements, tagName);
255
255
  }
256
- function extractText(elements) {
256
+ function extractText(elements, preserveWhitespace = false) {
257
257
  for (const item of elements) {
258
- if (item["#text"] !== void 0) return String(item["#text"]);
258
+ if (item["#text"] !== void 0) {
259
+ const text = String(item["#text"]);
260
+ return preserveWhitespace ? text : text.trim();
261
+ }
259
262
  }
260
263
  return "";
261
264
  }
@@ -565,7 +568,7 @@ function parseCredits(elements) {
565
568
  if (attrs["page"]) credit.page = parseInt(attrs["page"], 10);
566
569
  const types = collectElements(content, "credit-type", (c) => extractText(c));
567
570
  const words = collectElements(content, "credit-words", (c, a) => {
568
- const cw = { text: extractText(c) };
571
+ const cw = { text: extractText(c, true) };
569
572
  if (a["default-x"]) cw.defaultX = parseFloat(a["default-x"]);
570
573
  if (a["default-y"]) cw.defaultY = parseFloat(a["default-y"]);
571
574
  if (a["font-family"]) cw.fontFamily = a["font-family"];
@@ -1596,7 +1599,7 @@ function parseNotations(elements, notationsIndex = 0) {
1596
1599
  let text;
1597
1600
  for (const item of glissContent) {
1598
1601
  if (item["#text"] !== void 0) {
1599
- text = String(item["#text"]);
1602
+ text = String(item["#text"]).trim();
1600
1603
  break;
1601
1604
  }
1602
1605
  }
@@ -1634,7 +1637,7 @@ function parseLyric(elements, attrs) {
1634
1637
  const content = el["syllabic"];
1635
1638
  for (const item of content) {
1636
1639
  if (item["#text"] !== void 0) {
1637
- const syl = String(item["#text"]);
1640
+ const syl = String(item["#text"]).trim();
1638
1641
  if (syl === "single" || syl === "begin" || syl === "middle" || syl === "end") {
1639
1642
  currentSyllabic = syl;
1640
1643
  }
@@ -1882,7 +1885,7 @@ function parseDirectionTypes(elements) {
1882
1885
  const buContent = met["beat-unit"];
1883
1886
  for (const item of buContent) {
1884
1887
  if (item["#text"] !== void 0) {
1885
- beatUnits.push(String(item["#text"]));
1888
+ beatUnits.push(String(item["#text"]).trim());
1886
1889
  dotForPrev = true;
1887
1890
  break;
1888
1891
  }
@@ -1915,7 +1918,7 @@ function parseDirectionTypes(elements) {
1915
1918
  }
1916
1919
  if (el["words"]) {
1917
1920
  const a = getAttributes(el);
1918
- const text = extractText(el["words"]);
1921
+ const text = extractText(el["words"], true);
1919
1922
  const result = { kind: "words", text: text || "" };
1920
1923
  if (a["default-x"]) result.defaultX = parseFloat(a["default-x"]);
1921
1924
  if (a["default-y"]) result.defaultY = parseFloat(a["default-y"]);
@@ -2003,7 +2006,7 @@ function parseDirectionTypes(elements) {
2003
2006
  const otherContent = el["other-direction"];
2004
2007
  for (const o of otherContent) {
2005
2008
  if (o["#text"] !== void 0) {
2006
- const result = { kind: "other-direction", text: String(o["#text"]) };
2009
+ const result = { kind: "other-direction", text: String(o["#text"]).trim() };
2007
2010
  if (otherAttrs["default-x"]) result.defaultX = parseFloat(otherAttrs["default-x"]);
2008
2011
  if (otherAttrs["default-y"]) result.defaultY = parseFloat(otherAttrs["default-y"]);
2009
2012
  if (otherAttrs["halign"]) result.halign = otherAttrs["halign"];
@@ -2135,8 +2138,8 @@ function parseDirectionTypes(elements) {
2135
2138
  } else if (sw["swing-type"]) {
2136
2139
  const stContent = sw["swing-type"];
2137
2140
  for (const item of stContent) {
2138
- if (item["#text"] !== void 0 && isValidNoteType(String(item["#text"]))) {
2139
- result.swingType = String(item["#text"]);
2141
+ if (item["#text"] !== void 0 && isValidNoteType(String(item["#text"]).trim())) {
2142
+ result.swingType = String(item["#text"]).trim();
2140
2143
  break;
2141
2144
  }
2142
2145
  }
@@ -2407,7 +2410,7 @@ function parseHarmony(elements, attrs) {
2407
2410
  const kindContent = el["kind"];
2408
2411
  for (const item of kindContent) {
2409
2412
  if (item["#text"] !== void 0) {
2410
- harmony.kind = String(item["#text"]);
2413
+ harmony.kind = String(item["#text"]).trim();
2411
2414
  break;
2412
2415
  }
2413
2416
  }
@@ -2530,7 +2533,7 @@ function parseFiguredBass(elements, attrs) {
2530
2533
  const prefixContent = figEl["prefix"];
2531
2534
  for (const item of prefixContent) {
2532
2535
  if (item["#text"] !== void 0) {
2533
- figure.prefix = String(item["#text"]);
2536
+ figure.prefix = String(item["#text"]).trim();
2534
2537
  break;
2535
2538
  }
2536
2539
  }
@@ -2538,7 +2541,7 @@ function parseFiguredBass(elements, attrs) {
2538
2541
  const suffixContent = figEl["suffix"];
2539
2542
  for (const item of suffixContent) {
2540
2543
  if (item["#text"] !== void 0) {
2541
- figure.suffix = String(item["#text"]);
2544
+ figure.suffix = String(item["#text"]).trim();
2542
2545
  break;
2543
2546
  }
2544
2547
  }
@@ -2601,7 +2604,7 @@ function parseSound(elements, attrs) {
2601
2604
  const typeContent = swingEl["swing-type"];
2602
2605
  for (const item of typeContent) {
2603
2606
  if (item["#text"] !== void 0) {
2604
- swing.swingType = String(item["#text"]);
2607
+ swing.swingType = String(item["#text"]).trim();
2605
2608
  break;
2606
2609
  }
2607
2610
  }
package/dist/index.mjs CHANGED
@@ -220,7 +220,7 @@ var xmlParser = new XMLParser({
220
220
  textNodeName: "#text",
221
221
  parseAttributeValue: false,
222
222
  parseTagValue: false,
223
- trimValues: true,
223
+ trimValues: false,
224
224
  preserveOrder: true
225
225
  });
226
226
  function parse(xmlString) {
@@ -253,9 +253,12 @@ function findElement(elements, tagName) {
253
253
  function getElementContent(elements, tagName) {
254
254
  return findElement(elements, tagName);
255
255
  }
256
- function extractText(elements) {
256
+ function extractText(elements, preserveWhitespace = false) {
257
257
  for (const item of elements) {
258
- if (item["#text"] !== void 0) return String(item["#text"]);
258
+ if (item["#text"] !== void 0) {
259
+ const text = String(item["#text"]);
260
+ return preserveWhitespace ? text : text.trim();
261
+ }
259
262
  }
260
263
  return "";
261
264
  }
@@ -565,7 +568,7 @@ function parseCredits(elements) {
565
568
  if (attrs["page"]) credit.page = parseInt(attrs["page"], 10);
566
569
  const types = collectElements(content, "credit-type", (c) => extractText(c));
567
570
  const words = collectElements(content, "credit-words", (c, a) => {
568
- const cw = { text: extractText(c) };
571
+ const cw = { text: extractText(c, true) };
569
572
  if (a["default-x"]) cw.defaultX = parseFloat(a["default-x"]);
570
573
  if (a["default-y"]) cw.defaultY = parseFloat(a["default-y"]);
571
574
  if (a["font-family"]) cw.fontFamily = a["font-family"];
@@ -1596,7 +1599,7 @@ function parseNotations(elements, notationsIndex = 0) {
1596
1599
  let text;
1597
1600
  for (const item of glissContent) {
1598
1601
  if (item["#text"] !== void 0) {
1599
- text = String(item["#text"]);
1602
+ text = String(item["#text"]).trim();
1600
1603
  break;
1601
1604
  }
1602
1605
  }
@@ -1634,7 +1637,7 @@ function parseLyric(elements, attrs) {
1634
1637
  const content = el["syllabic"];
1635
1638
  for (const item of content) {
1636
1639
  if (item["#text"] !== void 0) {
1637
- const syl = String(item["#text"]);
1640
+ const syl = String(item["#text"]).trim();
1638
1641
  if (syl === "single" || syl === "begin" || syl === "middle" || syl === "end") {
1639
1642
  currentSyllabic = syl;
1640
1643
  }
@@ -1882,7 +1885,7 @@ function parseDirectionTypes(elements) {
1882
1885
  const buContent = met["beat-unit"];
1883
1886
  for (const item of buContent) {
1884
1887
  if (item["#text"] !== void 0) {
1885
- beatUnits.push(String(item["#text"]));
1888
+ beatUnits.push(String(item["#text"]).trim());
1886
1889
  dotForPrev = true;
1887
1890
  break;
1888
1891
  }
@@ -1915,7 +1918,7 @@ function parseDirectionTypes(elements) {
1915
1918
  }
1916
1919
  if (el["words"]) {
1917
1920
  const a = getAttributes(el);
1918
- const text = extractText(el["words"]);
1921
+ const text = extractText(el["words"], true);
1919
1922
  const result = { kind: "words", text: text || "" };
1920
1923
  if (a["default-x"]) result.defaultX = parseFloat(a["default-x"]);
1921
1924
  if (a["default-y"]) result.defaultY = parseFloat(a["default-y"]);
@@ -2003,7 +2006,7 @@ function parseDirectionTypes(elements) {
2003
2006
  const otherContent = el["other-direction"];
2004
2007
  for (const o of otherContent) {
2005
2008
  if (o["#text"] !== void 0) {
2006
- const result = { kind: "other-direction", text: String(o["#text"]) };
2009
+ const result = { kind: "other-direction", text: String(o["#text"]).trim() };
2007
2010
  if (otherAttrs["default-x"]) result.defaultX = parseFloat(otherAttrs["default-x"]);
2008
2011
  if (otherAttrs["default-y"]) result.defaultY = parseFloat(otherAttrs["default-y"]);
2009
2012
  if (otherAttrs["halign"]) result.halign = otherAttrs["halign"];
@@ -2135,8 +2138,8 @@ function parseDirectionTypes(elements) {
2135
2138
  } else if (sw["swing-type"]) {
2136
2139
  const stContent = sw["swing-type"];
2137
2140
  for (const item of stContent) {
2138
- if (item["#text"] !== void 0 && isValidNoteType(String(item["#text"]))) {
2139
- result.swingType = String(item["#text"]);
2141
+ if (item["#text"] !== void 0 && isValidNoteType(String(item["#text"]).trim())) {
2142
+ result.swingType = String(item["#text"]).trim();
2140
2143
  break;
2141
2144
  }
2142
2145
  }
@@ -2407,7 +2410,7 @@ function parseHarmony(elements, attrs) {
2407
2410
  const kindContent = el["kind"];
2408
2411
  for (const item of kindContent) {
2409
2412
  if (item["#text"] !== void 0) {
2410
- harmony.kind = String(item["#text"]);
2413
+ harmony.kind = String(item["#text"]).trim();
2411
2414
  break;
2412
2415
  }
2413
2416
  }
@@ -2530,7 +2533,7 @@ function parseFiguredBass(elements, attrs) {
2530
2533
  const prefixContent = figEl["prefix"];
2531
2534
  for (const item of prefixContent) {
2532
2535
  if (item["#text"] !== void 0) {
2533
- figure.prefix = String(item["#text"]);
2536
+ figure.prefix = String(item["#text"]).trim();
2534
2537
  break;
2535
2538
  }
2536
2539
  }
@@ -2538,7 +2541,7 @@ function parseFiguredBass(elements, attrs) {
2538
2541
  const suffixContent = figEl["suffix"];
2539
2542
  for (const item of suffixContent) {
2540
2543
  if (item["#text"] !== void 0) {
2541
- figure.suffix = String(item["#text"]);
2544
+ figure.suffix = String(item["#text"]).trim();
2542
2545
  break;
2543
2546
  }
2544
2547
  }
@@ -2601,7 +2604,7 @@ function parseSound(elements, attrs) {
2601
2604
  const typeContent = swingEl["swing-type"];
2602
2605
  for (const item of typeContent) {
2603
2606
  if (item["#text"] !== void 0) {
2604
- swing.swingType = String(item["#text"]);
2607
+ swing.swingType = String(item["#text"]).trim();
2605
2608
  break;
2606
2609
  }
2607
2610
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musicxml-io",
3
- "version": "0.3.7",
3
+ "version": "0.3.8",
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",