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.9
to
0.6.10
+181
dist/utils-DJSm61Ws.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]: 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 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,5 +0,5 @@

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";
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";
//#region src/serialize.d.ts
declare function xml(input: Record<string, any> | Record<string, any>[], options?: boolean | string | {
declare function xml(input: Record<string, unknown> | Record<string, unknown>[], options?: boolean | string | {
indent?: boolean | string;

@@ -6,0 +6,0 @@ declaration?: boolean | {

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

if (typeof values === "object") {
if (values._attr) for (const key of Object.keys(values._attr)) attrParts.push(`${key}="${escapeXml(String(values._attr[key]))}"`);
if (values._attributes) for (const key of Object.keys(values._attributes)) attrParts.push(`${key}="${escapeXml(String(values._attributes[key]))}"`);
if (values._cdata) {
const escaped = String(values._cdata).replace(/\]\]>/g, "]]]]><![CDATA[>");
const obj = values;
if (obj._attr) {
const attr = obj._attr;
for (const key of Object.keys(attr)) attrParts.push(`${key}="${escapeXml(String(attr[key]))}"`);
}
if (obj._attributes) {
const attr = obj._attributes;
for (const key of Object.keys(attr)) attrParts.push(`${key}="${escapeXml(String(attr[key]))}"`);
}
if (obj._cdata) {
const escaped = String(obj._cdata).replace(/\]\]>/g, "]]]]><![CDATA[>");
textParts.push(`<![CDATA[${escaped}]]>`);

@@ -115,5 +122,9 @@ }

if (values.length === 0) emptyArray = true;
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]))}"`);
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]))}"`);
else if (value && typeof value === "object") {
else for (const value of values) if (value && typeof value === "object" && "_attr" in value) {
const attr = value._attr;
for (const key of Object.keys(attr)) attrParts.push(`${key}="${escapeXml(String(attr[key]))}"`);
} else if (value && typeof value === "object" && "_attributes" in value) {
const attr = value._attributes;
for (const key of Object.keys(attr)) attrParts.push(`${key}="${escapeXml(String(attr[key]))}"`);
} else if (value && typeof value === "object") {
const childKeys = Object.keys(value);

@@ -120,0 +131,0 @@ elemParts.push(formatElement(childKeys[0], value[childKeys[0]], indent, depth + 1));

@@ -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-CSaXdiWb.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-DJSm61Ws.mjs";
export { allChildren, attr, attrBool, attrNum, childCount, childText, children, collectText, colorAttr, findChild, findDeep, hasChild, textOf };
{
"name": "@office-open/xml",
"version": "0.6.9",
"version": "0.6.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]: 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 };