Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@office-open/xml

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@office-open/xml - npm Package Compare versions

Comparing version
0.6.8
to
0.6.9
+181
dist/utils-CSaXdiWb.d.mts
//#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 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-DTU54qj_.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 "./utils-CSaXdiWb.mjs";

@@ -53,2 +53,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, attrs, childCount, childText, children, collectText, colorAttr, escapeXml, findChild, findDeep, hasChild, js2xml, json2xml, nativeTypeValue, parseAttributes, selfCloseElement, textOf, toElement, unescapeXml, xml, xml2js, xml2json };
export { type Attributes, type DeclarationAttributes, type Element, type ElementCompact, type ElementObject, type IgnoreOptions, type Js2XmlOptions, type Xml2JsOptions, type XmlAtom, type XmlAttrs, type XmlDesc, type XmlDescArray, type XmlObject, type XmlOption, allChildren, attr, attrBool, attrNum, attrs, childCount, childText, children, collectText, colorAttr, escapeXml, findChild, findDeep, hasChild, js2xml, json2xml, nativeTypeValue, parseAttributes, selfCloseElement, textOf, toElement, unescapeXml, xml, xml2js, xml2json };

@@ -421,3 +421,3 @@ import { allChildren, attr, attrBool, attrNum, childCount, childText, children, collectText, colorAttr, findChild, findDeep, hasChild, textOf } from "./utils.mjs";

function writeElements(elements, opts, depth, firstLine) {
let result = "";
const parts = [];
for (let i = 0; i < elements.length; i++) {

@@ -428,24 +428,24 @@ const element = elements[i];

case "element":
result += writeIndentation(opts.spaces, depth, isFirst);
result += writeElement(element, opts, depth);
parts.push(writeIndentation(opts.spaces, depth, isFirst));
parts.push(writeElement(element, opts, depth));
break;
case "text":
if (opts.ignoreText) continue;
if (opts.indentText) result += writeIndentation(opts.spaces, depth, isFirst);
result += writeText(element.text);
if (opts.indentText) parts.push(writeIndentation(opts.spaces, depth, isFirst));
parts.push(writeText(element.text));
break;
case "cdata":
if (opts.ignoreCdata) continue;
if (opts.indentCdata) result += writeIndentation(opts.spaces, depth, isFirst);
result += writeCdata(element.cdata);
if (opts.indentCdata) parts.push(writeIndentation(opts.spaces, depth, isFirst));
parts.push(writeCdata(element.cdata));
break;
case "comment":
if (opts.ignoreComment) continue;
result += writeIndentation(opts.spaces, depth, isFirst);
result += writeComment(element.comment);
parts.push(writeIndentation(opts.spaces, depth, isFirst));
parts.push(writeComment(element.comment));
break;
case "doctype":
if (opts.ignoreDoctype) continue;
result += writeIndentation(opts.spaces, depth, isFirst);
result += writeDoctype(element.doctype);
parts.push(writeIndentation(opts.spaces, depth, isFirst));
parts.push(writeDoctype(element.doctype));
break;

@@ -455,3 +455,3 @@ default: break;

}
return result;
return parts.join("");
}

@@ -458,0 +458,0 @@ function writeText(text) {

@@ -1,2 +0,2 @@

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-DTU54qj_.mjs";
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";
export { allChildren, attr, attrBool, attrNum, childCount, childText, children, collectText, colorAttr, findChild, findDeep, hasChild, textOf };
{
"name": "@office-open/xml",
"version": "0.6.8",
"version": "0.6.9",
"description": "XML parsing and serialization for Office Open XML. Zero dependencies, drop-in replacement for xml + xml-js.",

@@ -5,0 +5,0 @@ "keywords": [

+10
-10

@@ -106,5 +106,5 @@ # @office-open/xml

| ----------------------- | ---------------: | ---------: | --------: |
| Simple element | 5,177,260 hz | 788,296 hz | **6.57x** |
| Nested element | 931,473 hz | 283,093 hz | **3.29x** |
| Nested with declaration | 871,188 hz | 252,580 hz | **3.45x** |
| Simple element | 5,069,751 hz | 724,533 hz | **7.00x** |
| Nested element | 1,122,376 hz | 279,423 hz | **4.02x** |
| Nested with declaration | 1,050,046 hz | 248,678 hz | **4.22x** |

@@ -115,5 +115,5 @@ ### Parsing (xml2js)

| ------------------ | ---------------: | --------: | ---------: |
| Simple XML | 1,007,094 hz | 91,782 hz | **10.97x** |
| Complex OOXML | 340,595 hz | 49,733 hz | **6.85x** |
| With captureSpaces | 314,648 hz | 44,190 hz | **7.12x** |
| Simple XML | 1,000,869 hz | 90,488 hz | **11.06x** |
| Complex OOXML | 310,266 hz | 42,938 hz | **7.23x** |
| With captureSpaces | 313,183 hz | 41,814 hz | **7.49x** |

@@ -124,4 +124,4 @@ ### Stringifying (js2xml)

| -------------- | ---------------: | ---------: | --------: |
| Simple element | 712,314 hz | 182,865 hz | **3.90x** |
| Complex OOXML | 333,739 hz | 125,132 hz | **2.67x** |
| Simple element | 975,878 hz | 198,953 hz | **4.90x** |
| Complex OOXML | 492,220 hz | 107,815 hz | **4.57x** |

@@ -132,4 +132,4 @@ ### Direct Conversion (toElement vs bridge)

| -------- | ------------: | ----------------------: | ---------: |
| Simple | 13,922,735 hz | 1,083,869 hz | **12.85x** |
| Nested | 3,799,372 hz | 436,241 hz | **8.71x** |
| Simple | 13,199,415 hz | 805,104 hz | **16.40x** |
| Nested | 4,207,319 hz | 458,333 hz | **9.18x** |

@@ -136,0 +136,0 @@ ## Bundle Size

//#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 };