@office-open/xml 0.6.9 → 0.7.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.d.mts CHANGED
@@ -1,7 +1,7 @@
1
- import { C as XmlAttrs, D as XmlOption, E as XmlObject, S as XmlAtom, T as XmlDescArray, _ as ElementCompact, a as childCount, b as Js2XmlOptions, c as collectText, d as findDeep, f as hasChild, g as Element, h as DeclarationAttributes, i as attrNum, l as colorAttr, m as Attributes, n as attr, o as childText, p as textOf, r as attrBool, s as children, t as allChildren, u as findChild, v as ElementObject, w as XmlDesc, x as Xml2JsOptions, y as IgnoreOptions } from "./utils-CSaXdiWb.mjs";
1
+ import { C as XmlAttrs, D as XmlOption, E as XmlObject, S as XmlAtom, T as XmlDescArray, _ as ElementCompact, a as childCount, b as Js2XmlOptions, c as collectText, d as findDeep, f as hasChild, g as Element, h as DeclarationAttributes, i as attrNum, l as colorAttr, m as Attributes, n as attr, o as childText, p as textOf, r as attrBool, s as children, t as allChildren, u as findChild, v as ElementObject, w as XmlDesc, x as Xml2JsOptions, y as IgnoreOptions } from "./utils-DJSm61Ws.mjs";
2
2
 
3
3
  //#region src/serialize.d.ts
4
- declare function xml(input: Record<string, any> | Record<string, any>[], options?: boolean | string | {
4
+ declare function xml(input: Record<string, unknown> | Record<string, unknown>[], options?: boolean | string | {
5
5
  indent?: boolean | string;
6
6
  declaration?: boolean | {
7
7
  encoding?: string;
package/dist/index.mjs CHANGED
@@ -103,17 +103,28 @@ function formatElement(name, values, indent, depth) {
103
103
  return `${indent ? indent.repeat(depth) : ""}<${name}${attrStr}/>`;
104
104
  }
105
105
  if (typeof values === "object") {
106
- if (values._attr) for (const key of Object.keys(values._attr)) attrParts.push(`${key}="${escapeXml(String(values._attr[key]))}"`);
107
- if (values._attributes) for (const key of Object.keys(values._attributes)) attrParts.push(`${key}="${escapeXml(String(values._attributes[key]))}"`);
108
- if (values._cdata) {
109
- const escaped = String(values._cdata).replace(/\]\]>/g, "]]]]><![CDATA[>");
106
+ const obj = values;
107
+ if (obj._attr) {
108
+ const attr = obj._attr;
109
+ for (const key of Object.keys(attr)) attrParts.push(`${key}="${escapeXml(String(attr[key]))}"`);
110
+ }
111
+ if (obj._attributes) {
112
+ const attr = obj._attributes;
113
+ for (const key of Object.keys(attr)) attrParts.push(`${key}="${escapeXml(String(attr[key]))}"`);
114
+ }
115
+ if (obj._cdata) {
116
+ const escaped = String(obj._cdata).replace(/\]\]>/g, "]]]]><![CDATA[>");
110
117
  textParts.push(`<![CDATA[${escaped}]]>`);
111
118
  }
112
119
  if (Array.isArray(values)) {
113
120
  if (values.length === 0) emptyArray = true;
114
- else for (const value of values) if (value && typeof value === "object" && "_attr" in value) for (const key of Object.keys(value._attr)) attrParts.push(`${key}="${escapeXml(String(value._attr[key]))}"`);
115
- else if (value && typeof value === "object" && "_attributes" in value) for (const key of Object.keys(value._attributes)) attrParts.push(`${key}="${escapeXml(String(value._attributes[key]))}"`);
116
- else if (value && typeof value === "object") {
121
+ else for (const value of values) if (value && typeof value === "object" && "_attr" in value) {
122
+ const attr = value._attr;
123
+ for (const key of Object.keys(attr)) attrParts.push(`${key}="${escapeXml(String(attr[key]))}"`);
124
+ } else if (value && typeof value === "object" && "_attributes" in value) {
125
+ const attr = value._attributes;
126
+ for (const key of Object.keys(attr)) attrParts.push(`${key}="${escapeXml(String(attr[key]))}"`);
127
+ } else if (value && typeof value === "object") {
117
128
  const childKeys = Object.keys(value);
118
129
  elemParts.push(formatElement(childKeys[0], value[childKeys[0]], indent, depth + 1));
119
130
  } else if (value != null) textParts.push(escapeXml(String(value)));
@@ -23,7 +23,7 @@ interface Element {
23
23
  parent?: Element;
24
24
  }
25
25
  interface ElementCompact {
26
- [key: string]: any;
26
+ [key: string]: unknown;
27
27
  _declaration?: {
28
28
  _attributes?: DeclarationAttributes;
29
29
  };
package/dist/utils.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as childCount, c as collectText, d as findDeep, f as hasChild, i as attrNum, l as colorAttr, n as attr, o as childText, p as textOf, r as attrBool, s as children, t as allChildren, u as findChild } from "./utils-CSaXdiWb.mjs";
1
+ import { a as childCount, c as collectText, d as findDeep, f as hasChild, i as attrNum, l as colorAttr, n as attr, o as childText, p as textOf, r as attrBool, s as children, t as allChildren, u as findChild } from "./utils-DJSm61Ws.mjs";
2
2
  export { allChildren, attr, attrBool, attrNum, childCount, childText, children, collectText, colorAttr, findChild, findDeep, hasChild, textOf };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@office-open/xml",
3
- "version": "0.6.9",
3
+ "version": "0.7.0",
4
4
  "description": "XML parsing and serialization for Office Open XML. Zero dependencies, drop-in replacement for xml + xml-js.",
5
5
  "keywords": [
6
6
  "office-open",