@office-open/xml
Advanced tools
| //#region src/types.d.ts | ||
| interface Attributes { | ||
| [key: string]: string | number | undefined; | ||
| } | ||
| interface DeclarationAttributes { | ||
| version?: string | number; | ||
| encoding?: string; | ||
| standalone?: string; | ||
| } | ||
| interface Element { | ||
| declaration?: { | ||
| attributes?: DeclarationAttributes; | ||
| }; | ||
| instruction?: string; | ||
| attributes?: Attributes; | ||
| cdata?: string; | ||
| doctype?: string; | ||
| comment?: string; | ||
| text?: string | number | boolean; | ||
| type?: string; | ||
| name?: string; | ||
| elements?: Element[]; | ||
| parent?: Element; | ||
| } | ||
| interface ElementCompact { | ||
| [key: string]: any; | ||
| _declaration?: { | ||
| _attributes?: DeclarationAttributes; | ||
| }; | ||
| _instruction?: { | ||
| [key: string]: string; | ||
| }; | ||
| _attributes?: Attributes; | ||
| _cdata?: string; | ||
| _doctype?: string; | ||
| _comment?: string; | ||
| _text?: string | number; | ||
| } | ||
| interface IgnoreOptions { | ||
| ignoreDeclaration?: boolean; | ||
| ignoreInstruction?: boolean; | ||
| ignoreAttributes?: boolean; | ||
| ignoreComment?: boolean; | ||
| ignoreCdata?: boolean; | ||
| ignoreDoctype?: boolean; | ||
| ignoreText?: boolean; | ||
| } | ||
| interface Xml2JsOptions extends IgnoreOptions { | ||
| compact?: boolean; | ||
| trim?: boolean; | ||
| sanitize?: boolean; | ||
| nativeType?: boolean; | ||
| nativeTypeAttributes?: boolean; | ||
| addParent?: boolean; | ||
| alwaysArray?: boolean | string[]; | ||
| alwaysChildren?: boolean; | ||
| instructionHasAttributes?: boolean; | ||
| captureSpacesBetweenElements?: boolean; | ||
| doctypeFn?: (value: string, parentElement: object) => string; | ||
| instructionFn?: (value: string, instructionName: string, parentElement: string) => string; | ||
| cdataFn?: (value: string, parentElement: object) => string; | ||
| commentFn?: (value: string, parentElement: object) => string; | ||
| textFn?: (value: string, parentElement: object) => string; | ||
| instructionNameFn?: (instructionName: string, instructionValue: string, parentElement: string) => string; | ||
| elementNameFn?: (value: string, parentElement: object) => string; | ||
| attributeNameFn?: (attributeName: string, attributeValue: string, parentElement: string) => string; | ||
| attributeValueFn?: (attributeValue: string, attributeName: string, parentElement: string) => string; | ||
| attributesFn?: (value: Attributes, parentElement: string) => Attributes; | ||
| } | ||
| interface Js2XmlOptions extends IgnoreOptions { | ||
| spaces?: number | string; | ||
| compact?: boolean; | ||
| indentText?: boolean; | ||
| indentCdata?: boolean; | ||
| indentAttributes?: boolean; | ||
| indentInstruction?: boolean; | ||
| fullTagEmptyElement?: boolean; | ||
| noQuotesForNativeAttributes?: boolean; | ||
| doctypeFn?: (value: string, currentElementName: string, currentElementObj: object) => string; | ||
| instructionFn?: (instructionValue: string, instructionName: string, currentElementName: string, currentElementObj: object) => string; | ||
| cdataFn?: (value: string, currentElementName: string, currentElementObj: object) => string; | ||
| commentFn?: (value: string, currentElementName: string, currentElementObj: object) => string; | ||
| textFn?: (value: string, currentElementName: string, currentElementObj: object) => string; | ||
| instructionNameFn?: (instructionName: string, instructionValue: string, currentElementName: string, currentElementObj: object) => string; | ||
| elementNameFn?: (value: string, currentElementName: string, currentElementObj: object) => string; | ||
| attributeNameFn?: (attributeName: string, attributeValue: string, currentElementName: string, currentElementObj: object) => string; | ||
| attributeValueFn?: (attributeValue: string, attributeName: string, currentElementName: string, currentElementObj: object) => string; | ||
| attributesFn?: (value: Attributes, currentElementName: string, currentElementObj: object) => Attributes; | ||
| fullTagEmptyElementFn?: (currentElementName: string, currentElementObj: object) => boolean; | ||
| } | ||
| interface XmlOption { | ||
| indent?: string; | ||
| stream?: boolean; | ||
| declaration?: boolean | { | ||
| encoding?: string; | ||
| standalone?: string; | ||
| }; | ||
| } | ||
| interface XmlAttrs { | ||
| [attr: string]: XmlAtom; | ||
| } | ||
| type XmlAtom = string | number | boolean | null; | ||
| interface ElementObject { | ||
| push(xmlObject: XmlObject): void; | ||
| close(xmlObject?: XmlObject): void; | ||
| } | ||
| type XmlDesc = { | ||
| _attr: XmlAttrs; | ||
| } | { | ||
| _cdata: string; | ||
| } | { | ||
| _attr: XmlAttrs; | ||
| _cdata: string; | ||
| } | XmlAtom | XmlAtom[] | XmlDescArray; | ||
| interface XmlDescArray { | ||
| [index: number]: { | ||
| _attr: XmlAttrs; | ||
| } | XmlObject; | ||
| } | ||
| type XmlObject = { | ||
| [tag: string]: ElementObject | XmlDesc; | ||
| } | XmlDesc; | ||
| //#endregion | ||
| //#region src/utils.d.ts | ||
| /** | ||
| * Find the first direct child element with the given name. | ||
| */ | ||
| declare function findChild(parent: Element | undefined, name: string): Element | undefined; | ||
| /** | ||
| * Get all direct child elements matching the given name. | ||
| */ | ||
| declare function children(parent: Element | undefined, name: string): Element[]; | ||
| /** | ||
| * Get all direct child elements. | ||
| */ | ||
| declare function allChildren(parent: Element | undefined): Element[]; | ||
| /** | ||
| * Get text content of the first child element with the given name. | ||
| */ | ||
| declare function childText(parent: Element | undefined, name: string): string; | ||
| /** | ||
| * Get text content of an element. | ||
| * Handles cases where text may be directly on .text or in a child element. | ||
| */ | ||
| declare function textOf(element: Element | undefined): string; | ||
| /** | ||
| * Collect text from all direct text nodes within an element. | ||
| */ | ||
| declare function collectText(element: Element | undefined): string; | ||
| /** | ||
| * Get an attribute value as a string. | ||
| */ | ||
| declare function attr(element: Element | undefined, name: string): string | undefined; | ||
| /** | ||
| * Get an attribute value as a number. | ||
| */ | ||
| declare function attrNum(element: Element | undefined, name: string): number | undefined; | ||
| /** | ||
| * Get an attribute value as a boolean. | ||
| */ | ||
| declare function attrBool(element: Element | undefined, name: string): boolean | undefined; | ||
| /** | ||
| * Get a hex color attribute, handling nativeTypeValue coercion. | ||
| * nativeTypeAttributes converts "000000" → 0 (number); this recovers | ||
| * the original 6-digit hex string by zero-padding numeric values. | ||
| */ | ||
| declare function colorAttr(element: Element | undefined, name: string): string | undefined; | ||
| /** | ||
| * Check if an element has a specific child element. | ||
| */ | ||
| declare function hasChild(parent: Element | undefined, name: string): boolean; | ||
| /** | ||
| * Find deep descendant elements matching the given name. | ||
| */ | ||
| declare function findDeep(parent: Element | undefined, name: string): Element[]; | ||
| /** | ||
| * Get the number of direct child elements. | ||
| */ | ||
| declare function childCount(parent: Element | undefined): number; | ||
| //#endregion | ||
| export { XmlAttrs as C, XmlOption as D, XmlObject as E, XmlAtom as S, XmlDescArray as T, ElementCompact as _, childCount as a, Js2XmlOptions as b, collectText as c, findDeep as d, hasChild as f, Element as g, DeclarationAttributes as h, attrNum as i, colorAttr as l, Attributes as m, attr as n, childText as o, textOf as p, attrBool as r, children as s, allChildren as t, findChild as u, ElementObject as v, XmlDesc as w, Xml2JsOptions as x, IgnoreOptions as y }; |
+2
-2
@@ -1,2 +0,2 @@ | ||
| import { C as XmlDesc, E as XmlOption, S as XmlAttrs, T as XmlObject, _ as ElementObject, a as childCount, b as Xml2JsOptions, c as collectText, d as hasChild, f as textOf, g as ElementCompact, h as Element, i as attrNum, l as findChild, m as DeclarationAttributes, n as attr, o as childText, p as Attributes, r as attrBool, s as children, t as allChildren, u as findDeep, v as IgnoreOptions, w as XmlDescArray, x as XmlAtom, y as Js2XmlOptions } from "./_chunks/utils-DlOOMr6B.mjs"; | ||
| 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 "./_chunks/utils-BHmdH50s.mjs"; | ||
@@ -40,2 +40,2 @@ //#region src/serialize.d.ts | ||
| //#endregion | ||
| export { Attributes, DeclarationAttributes, Element, ElementCompact, ElementObject, IgnoreOptions, Js2XmlOptions, Xml2JsOptions, XmlAtom, XmlAttrs, XmlDesc, XmlDescArray, XmlObject, XmlOption, allChildren, attr, attrBool, attrNum, childCount, childText, children, collectText, escapeAttributeValue, escapeXml, findChild, findDeep, hasChild, js2xml, json2xml, textOf, toElement, xml, xml2js, xml2json }; | ||
| export { Attributes, DeclarationAttributes, Element, ElementCompact, ElementObject, IgnoreOptions, Js2XmlOptions, Xml2JsOptions, XmlAtom, XmlAttrs, XmlDesc, XmlDescArray, XmlObject, XmlOption, allChildren, attr, attrBool, attrNum, childCount, childText, children, collectText, colorAttr, escapeAttributeValue, escapeXml, findChild, findDeep, hasChild, js2xml, json2xml, textOf, toElement, xml, xml2js, xml2json }; |
+4
-2
@@ -1,2 +0,2 @@ | ||
| import { allChildren, attr, attrBool, attrNum, childCount, childText, children, collectText, findChild, findDeep, hasChild, textOf } from "./utils.mjs"; | ||
| import { allChildren, attr, attrBool, attrNum, childCount, childText, children, collectText, colorAttr, findChild, findDeep, hasChild, textOf } from "./utils.mjs"; | ||
| //#region src/escape.ts | ||
@@ -70,2 +70,3 @@ const XML_CHAR_MAP = { | ||
| if (values._attr) for (const key of Object.keys(values._attr)) attributes.push(`${key}="${escapeXml(String(values._attr[key]))}"`); | ||
| if (values._attributes) for (const key of Object.keys(values._attributes)) attributes.push(`${key}="${escapeXml(String(values._attributes[key]))}"`); | ||
| if (values._cdata) { | ||
@@ -85,2 +86,3 @@ const escaped = String(values._cdata).replace(/\]\]>/g, "]]]]><![CDATA[>"); | ||
| for (const value of values) if (value && typeof value === "object" && "_attr" in value) for (const key of Object.keys(value._attr)) attributes.push(`${key}="${escapeXml(String(value._attr[key]))}"`); | ||
| else if (value && typeof value === "object" && "_attributes" in value) for (const key of Object.keys(value._attributes)) attributes.push(`${key}="${escapeXml(String(value._attributes[key]))}"`); | ||
| else if (value && typeof value === "object") content.push(resolve(value, indent, depth + 1)); | ||
@@ -505,2 +507,2 @@ else if (value != null) content.push(escapeXml(String(value))); | ||
| //#endregion | ||
| export { allChildren, attr, attrBool, attrNum, childCount, childText, children, collectText, escapeAttributeValue, escapeXml, findChild, findDeep, hasChild, js2xml, json2xml, textOf, toElement, xml, xml2js, xml2json }; | ||
| export { allChildren, attr, attrBool, attrNum, childCount, childText, children, collectText, colorAttr, escapeAttributeValue, escapeXml, findChild, findDeep, hasChild, js2xml, json2xml, textOf, toElement, xml, xml2js, xml2json }; |
+2
-2
@@ -1,2 +0,2 @@ | ||
| import { a as childCount, c as collectText, d as hasChild, f as textOf, i as attrNum, l as findChild, n as attr, o as childText, r as attrBool, s as children, t as allChildren, u as findDeep } from "./_chunks/utils-DlOOMr6B.mjs"; | ||
| export { allChildren, attr, attrBool, attrNum, childCount, childText, children, collectText, findChild, findDeep, hasChild, textOf }; | ||
| 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 "./_chunks/utils-BHmdH50s.mjs"; | ||
| export { allChildren, attr, attrBool, attrNum, childCount, childText, children, collectText, colorAttr, findChild, findDeep, hasChild, textOf }; |
+15
-1
@@ -78,2 +78,16 @@ //#region src/utils.ts | ||
| /** | ||
| * Get a hex color attribute, handling nativeTypeValue coercion. | ||
| * nativeTypeAttributes converts "000000" → 0 (number); this recovers | ||
| * the original 6-digit hex string by zero-padding numeric values. | ||
| */ | ||
| function colorAttr(element, name) { | ||
| const raw = element?.attributes?.[name]; | ||
| if (raw === void 0 || raw === "") return void 0; | ||
| if (typeof raw === "boolean") return void 0; | ||
| if (typeof raw === "number") return String(raw).padStart(6, "0"); | ||
| if (raw === "auto") return "auto"; | ||
| if (/^[0-9A-Fa-f]{6}$/.test(raw)) return raw; | ||
| return raw; | ||
| } | ||
| /** | ||
| * Check if an element has a specific child element. | ||
@@ -103,2 +117,2 @@ */ | ||
| //#endregion | ||
| export { allChildren, attr, attrBool, attrNum, childCount, childText, children, collectText, findChild, findDeep, hasChild, textOf }; | ||
| export { allChildren, attr, attrBool, attrNum, childCount, childText, children, collectText, colorAttr, findChild, findDeep, hasChild, textOf }; |
+1
-1
| { | ||
| "name": "@office-open/xml", | ||
| "version": "0.3.0", | ||
| "version": "0.3.1", | ||
| "description": "XML parsing and serialization for Office Open XML. Zero dependencies, drop-in replacement for xml + xml-js.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
| //#region src/types.d.ts | ||
| interface Attributes { | ||
| [key: string]: string | number | undefined; | ||
| } | ||
| interface DeclarationAttributes { | ||
| version?: string | number; | ||
| encoding?: string; | ||
| standalone?: string; | ||
| } | ||
| interface Element { | ||
| declaration?: { | ||
| attributes?: DeclarationAttributes; | ||
| }; | ||
| instruction?: string; | ||
| attributes?: Attributes; | ||
| cdata?: string; | ||
| doctype?: string; | ||
| comment?: string; | ||
| text?: string | number | boolean; | ||
| type?: string; | ||
| name?: string; | ||
| elements?: Element[]; | ||
| parent?: Element; | ||
| } | ||
| interface ElementCompact { | ||
| [key: string]: any; | ||
| _declaration?: { | ||
| _attributes?: DeclarationAttributes; | ||
| }; | ||
| _instruction?: { | ||
| [key: string]: string; | ||
| }; | ||
| _attributes?: Attributes; | ||
| _cdata?: string; | ||
| _doctype?: string; | ||
| _comment?: string; | ||
| _text?: string | number; | ||
| } | ||
| interface IgnoreOptions { | ||
| ignoreDeclaration?: boolean; | ||
| ignoreInstruction?: boolean; | ||
| ignoreAttributes?: boolean; | ||
| ignoreComment?: boolean; | ||
| ignoreCdata?: boolean; | ||
| ignoreDoctype?: boolean; | ||
| ignoreText?: boolean; | ||
| } | ||
| interface Xml2JsOptions extends IgnoreOptions { | ||
| compact?: boolean; | ||
| trim?: boolean; | ||
| sanitize?: boolean; | ||
| nativeType?: boolean; | ||
| nativeTypeAttributes?: boolean; | ||
| addParent?: boolean; | ||
| alwaysArray?: boolean | string[]; | ||
| alwaysChildren?: boolean; | ||
| instructionHasAttributes?: boolean; | ||
| captureSpacesBetweenElements?: boolean; | ||
| doctypeFn?: (value: string, parentElement: object) => string; | ||
| instructionFn?: (value: string, instructionName: string, parentElement: string) => string; | ||
| cdataFn?: (value: string, parentElement: object) => string; | ||
| commentFn?: (value: string, parentElement: object) => string; | ||
| textFn?: (value: string, parentElement: object) => string; | ||
| instructionNameFn?: (instructionName: string, instructionValue: string, parentElement: string) => string; | ||
| elementNameFn?: (value: string, parentElement: object) => string; | ||
| attributeNameFn?: (attributeName: string, attributeValue: string, parentElement: string) => string; | ||
| attributeValueFn?: (attributeValue: string, attributeName: string, parentElement: string) => string; | ||
| attributesFn?: (value: Attributes, parentElement: string) => Attributes; | ||
| } | ||
| interface Js2XmlOptions extends IgnoreOptions { | ||
| spaces?: number | string; | ||
| compact?: boolean; | ||
| indentText?: boolean; | ||
| indentCdata?: boolean; | ||
| indentAttributes?: boolean; | ||
| indentInstruction?: boolean; | ||
| fullTagEmptyElement?: boolean; | ||
| noQuotesForNativeAttributes?: boolean; | ||
| doctypeFn?: (value: string, currentElementName: string, currentElementObj: object) => string; | ||
| instructionFn?: (instructionValue: string, instructionName: string, currentElementName: string, currentElementObj: object) => string; | ||
| cdataFn?: (value: string, currentElementName: string, currentElementObj: object) => string; | ||
| commentFn?: (value: string, currentElementName: string, currentElementObj: object) => string; | ||
| textFn?: (value: string, currentElementName: string, currentElementObj: object) => string; | ||
| instructionNameFn?: (instructionName: string, instructionValue: string, currentElementName: string, currentElementObj: object) => string; | ||
| elementNameFn?: (value: string, currentElementName: string, currentElementObj: object) => string; | ||
| attributeNameFn?: (attributeName: string, attributeValue: string, currentElementName: string, currentElementObj: object) => string; | ||
| attributeValueFn?: (attributeValue: string, attributeName: string, currentElementName: string, currentElementObj: object) => string; | ||
| attributesFn?: (value: Attributes, currentElementName: string, currentElementObj: object) => Attributes; | ||
| fullTagEmptyElementFn?: (currentElementName: string, currentElementObj: object) => boolean; | ||
| } | ||
| interface XmlOption { | ||
| indent?: string; | ||
| stream?: boolean; | ||
| declaration?: boolean | { | ||
| encoding?: string; | ||
| standalone?: string; | ||
| }; | ||
| } | ||
| interface XmlAttrs { | ||
| [attr: string]: XmlAtom; | ||
| } | ||
| type XmlAtom = string | number | boolean | null; | ||
| interface ElementObject { | ||
| push(xmlObject: XmlObject): void; | ||
| close(xmlObject?: XmlObject): void; | ||
| } | ||
| type XmlDesc = { | ||
| _attr: XmlAttrs; | ||
| } | { | ||
| _cdata: string; | ||
| } | { | ||
| _attr: XmlAttrs; | ||
| _cdata: string; | ||
| } | XmlAtom | XmlAtom[] | XmlDescArray; | ||
| interface XmlDescArray { | ||
| [index: number]: { | ||
| _attr: XmlAttrs; | ||
| } | XmlObject; | ||
| } | ||
| type XmlObject = { | ||
| [tag: string]: ElementObject | XmlDesc; | ||
| } | XmlDesc; | ||
| //#endregion | ||
| //#region src/utils.d.ts | ||
| /** | ||
| * Find the first direct child element with the given name. | ||
| */ | ||
| declare function findChild(parent: Element | undefined, name: string): Element | undefined; | ||
| /** | ||
| * Get all direct child elements matching the given name. | ||
| */ | ||
| declare function children(parent: Element | undefined, name: string): Element[]; | ||
| /** | ||
| * Get all direct child elements. | ||
| */ | ||
| declare function allChildren(parent: Element | undefined): Element[]; | ||
| /** | ||
| * Get text content of the first child element with the given name. | ||
| */ | ||
| declare function childText(parent: Element | undefined, name: string): string; | ||
| /** | ||
| * Get text content of an element. | ||
| * Handles cases where text may be directly on .text or in a child element. | ||
| */ | ||
| declare function textOf(element: Element | undefined): string; | ||
| /** | ||
| * Collect text from all direct text nodes within an element. | ||
| */ | ||
| declare function collectText(element: Element | undefined): string; | ||
| /** | ||
| * Get an attribute value as a string. | ||
| */ | ||
| declare function attr(element: Element | undefined, name: string): string | undefined; | ||
| /** | ||
| * Get an attribute value as a number. | ||
| */ | ||
| declare function attrNum(element: Element | undefined, name: string): number | undefined; | ||
| /** | ||
| * Get an attribute value as a boolean. | ||
| */ | ||
| declare function attrBool(element: Element | undefined, name: string): boolean | undefined; | ||
| /** | ||
| * Check if an element has a specific child element. | ||
| */ | ||
| declare function hasChild(parent: Element | undefined, name: string): boolean; | ||
| /** | ||
| * Find deep descendant elements matching the given name. | ||
| */ | ||
| declare function findDeep(parent: Element | undefined, name: string): Element[]; | ||
| /** | ||
| * Get the number of direct child elements. | ||
| */ | ||
| declare function childCount(parent: Element | undefined): number; | ||
| //#endregion | ||
| export { XmlDesc as C, XmlOption as E, XmlAttrs as S, XmlObject as T, ElementObject as _, childCount as a, Xml2JsOptions as b, collectText as c, hasChild as d, textOf as f, ElementCompact as g, Element as h, attrNum as i, findChild as l, DeclarationAttributes as m, attr as n, childText as o, Attributes as p, attrBool as r, children as s, allChildren as t, findDeep as u, IgnoreOptions as v, XmlDescArray as w, XmlAtom as x, Js2XmlOptions as y }; |
37040
3.65%621
2.64%