@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]: unknown; | ||
| _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 a measurement attribute as a number or a verbatim measure/percent string. | ||
| * | ||
| * Counterpart to {@link attrNum} for XSD attribute unions of a decimal number | ||
| * and UniversalMeasure/Percentage (ST_TwipsMeasure, ST_MeasurementOrPercent, | ||
| * CT_TblWidth/@w, CT_Height/@val): a plain numeric token yields a number, while | ||
| * UniversalMeasure ("5mm") and Percentage ("50%") stay verbatim so they | ||
| * round-trip with the stringify-side value helpers in @office-open/core. | ||
| * | ||
| * For CT_TblWidth with type="pct", the fiftieths token ("5000" = 100%) is a | ||
| * plain numeric token and is returned as the number 5000; the stringify side | ||
| * emits it verbatim (never "5000%", which is a different XSD branch). | ||
| */ | ||
| declare function attrMeasure(element: Element | undefined, name: string): number | string | 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[]; | ||
| /** | ||
| * Find the first descendant element with the given name (depth-first pre-order). | ||
| * Short-circuits at the first match — prefer this over `findDeep(parent, name)[0]` | ||
| * to avoid traversing the whole subtree and allocating the full results array. | ||
| */ | ||
| declare function findFirst(parent: Element | undefined, name: string): Element | undefined; | ||
| /** | ||
| * Get the number of direct child elements. | ||
| */ | ||
| declare function childCount(parent: Element | undefined): number; | ||
| //#endregion | ||
| export { Xml2JsOptions as C, XmlDescArray as D, XmlDesc as E, XmlObject as O, Js2XmlOptions as S, XmlAttrs as T, DeclarationAttributes as _, attrNum as a, ElementObject as b, children as c, findChild as d, findDeep as f, Attributes as g, textOf as h, attrMeasure as i, XmlOption as k, collectText as l, hasChild as m, attr as n, childCount as o, findFirst as p, attrBool as r, childText as s, allChildren as t, colorAttr as u, Element as v, XmlAtom as w, IgnoreOptions as x, ElementCompact as y }; |
+1
-1
@@ -1,2 +0,2 @@ | ||
| import { C as Xml2JsOptions, D as XmlDescArray, E as XmlDesc, O as XmlObject, S as Js2XmlOptions, T as XmlAttrs, _ as DeclarationAttributes, a as attrNum, b as ElementObject, c as children, d as findChild, f as findDeep, g as Attributes, h as textOf, i as attrMeasure, k as XmlOption, l as collectText, m as hasChild, n as attr, o as childCount, p as findFirst, r as attrBool, s as childText, t as allChildren, u as colorAttr, v as Element, w as XmlAtom, x as IgnoreOptions, y as ElementCompact } from "./utils-CDLayhwk.mjs"; | ||
| import { C as Xml2JsOptions, D as XmlDescArray, E as XmlDesc, O as XmlObject, S as Js2XmlOptions, T as XmlAttrs, _ as DeclarationAttributes, a as attrNum, b as ElementObject, c as children, d as findChild, f as findDeep, g as Attributes, h as textOf, i as attrMeasure, k as XmlOption, l as collectText, m as hasChild, n as attr, o as childCount, p as findFirst, r as attrBool, s as childText, t as allChildren, u as colorAttr, v as Element, w as XmlAtom, x as IgnoreOptions, y as ElementCompact } from "./utils-t-_-N57p.mjs"; | ||
@@ -3,0 +3,0 @@ //#region src/serialize.d.ts |
+1
-1
@@ -1,2 +0,2 @@ | ||
| import { a as attrNum, c as children, d as findChild, f as findDeep, h as textOf, i as attrMeasure, l as collectText, m as hasChild, n as attr, o as childCount, p as findFirst, r as attrBool, s as childText, t as allChildren, u as colorAttr } from "./utils-CDLayhwk.mjs"; | ||
| import { a as attrNum, c as children, d as findChild, f as findDeep, h as textOf, i as attrMeasure, l as collectText, m as hasChild, n as attr, o as childCount, p as findFirst, r as attrBool, s as childText, t as allChildren, u as colorAttr } from "./utils-t-_-N57p.mjs"; | ||
| export { allChildren, attr, attrBool, attrMeasure, attrNum, childCount, childText, children, collectText, colorAttr, findChild, findDeep, findFirst, hasChild, textOf }; |
+4
-5
@@ -75,11 +75,10 @@ //#region src/utils.ts | ||
| * | ||
| * Pass the sibling @type for CT_TblWidth with type="pct" — its fiftieths token | ||
| * ("5000") must stay a string, since converting it to 5000 would make a later | ||
| * stringify re-emit "5000%", changing the value. | ||
| * For CT_TblWidth with type="pct", the fiftieths token ("5000" = 100%) is a | ||
| * plain numeric token and is returned as the number 5000; the stringify side | ||
| * emits it verbatim (never "5000%", which is a different XSD branch). | ||
| */ | ||
| function attrMeasure(element, name, type) { | ||
| function attrMeasure(element, name) { | ||
| const v = element?.attributes?.[name]; | ||
| if (v === void 0) return void 0; | ||
| const raw = String(v); | ||
| if (type === "pct") return raw; | ||
| const n = Number(raw); | ||
@@ -86,0 +85,0 @@ return Number.isNaN(n) ? raw : n; |
+1
-1
| { | ||
| "name": "@office-open/xml", | ||
| "version": "0.10.9", | ||
| "version": "0.10.10", | ||
| "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]: unknown; | ||
| _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 a measurement attribute as a number or a verbatim measure/percent string. | ||
| * | ||
| * Counterpart to {@link attrNum} for XSD attribute unions of a decimal number | ||
| * and UniversalMeasure/Percentage (ST_TwipsMeasure, ST_MeasurementOrPercent, | ||
| * CT_TblWidth/@w, CT_Height/@val): a plain numeric token yields a number, while | ||
| * UniversalMeasure ("5mm") and Percentage ("50%") stay verbatim so they | ||
| * round-trip with the stringify-side value helpers in @office-open/core. | ||
| * | ||
| * Pass the sibling @type for CT_TblWidth with type="pct" — its fiftieths token | ||
| * ("5000") must stay a string, since converting it to 5000 would make a later | ||
| * stringify re-emit "5000%", changing the value. | ||
| */ | ||
| declare function attrMeasure(element: Element | undefined, name: string, type?: string): number | string | 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[]; | ||
| /** | ||
| * Find the first descendant element with the given name (depth-first pre-order). | ||
| * Short-circuits at the first match — prefer this over `findDeep(parent, name)[0]` | ||
| * to avoid traversing the whole subtree and allocating the full results array. | ||
| */ | ||
| declare function findFirst(parent: Element | undefined, name: string): Element | undefined; | ||
| /** | ||
| * Get the number of direct child elements. | ||
| */ | ||
| declare function childCount(parent: Element | undefined): number; | ||
| //#endregion | ||
| export { Xml2JsOptions as C, XmlDescArray as D, XmlDesc as E, XmlObject as O, Js2XmlOptions as S, XmlAttrs as T, DeclarationAttributes as _, attrNum as a, ElementObject as b, children as c, findChild as d, findDeep as f, Attributes as g, textOf as h, attrMeasure as i, XmlOption as k, collectText as l, hasChild as m, attr as n, childCount as o, findFirst as p, attrBool as r, childText as s, allChildren as t, colorAttr as u, Element as v, XmlAtom as w, IgnoreOptions as x, ElementCompact as y }; |
46291
-0.05%770
-0.13%