UNPKG

iterparse

Version:
162 lines 5.17 kB
import { ProgressReportOptions, WriteProgressReportOptions } from "./helpers"; import { AnyIterable, FileReference, FileWriteMode, IX } from "./types"; export interface FastXMLParser { /** * Node attribute prefix * @defaultValue `""` * @example * const cfg: FastXMLWriteOptions = { attributeNamePrefix: "#", attrNodeName: "_" } * const obj = { "_":{ "#id": "1" }, "Person": { ... } } //-> <Person id="1">...</Person> */ attributeNamePrefix?: string; /** * Node attribute prefix * @defaultValue `"_"` * @example * const cfg: FastXMLWriteOptions = { attributeNamePrefix: "#", attrNodeName: "_" } * const obj = { "_":{ "#id": "1" }, "Person": { ... } } //-> <Person id="1">...</Person> */ attrNodeName?: false | string; /** * Text node key * @defaultValue `"#text"` * @example * <Node> * Text attribute value * <NodeChild></NodeChild> * </Node> */ textNodeName?: string; /** * Should we parse node attributes? * @defaultValue `false` */ ignoreAttributes?: boolean; ignoreNameSpace?: boolean; allowBooleanAttributes?: boolean; parseNodeValue?: boolean; /** * Should we parse attributes? * * Recommended value is false. Improves parsing performance. * @defaultValue `false` */ parseAttributeValue?: boolean; arrayMode?: boolean | 'strict' | RegExp | ((tagName: string, parentTagName: string) => boolean); trimValues?: boolean; /** * @defaultValue `"__cdata"` */ cdataTagName?: false | string; /** * @defaultValue `"\\c"` */ cdataPositionChar?: string; /** * Should we parse number values? * Recommended value is false. Improves parsing speed * @defaultValue false */ parseTrueNumberOnly?: boolean; /** * How tag value is processed? */ tagValueProcessor?: (tagValue: string, tagName: string) => string; /** * How attribute value is processed? */ attrValueProcessor?: (attrValue: string, attrName: string) => string; /** * Nodes that are included in this list will not be processed */ stopNodes?: string[]; } export interface XMLReadOptions extends ProgressReportOptions, FastXMLParser, FileReference { /** * Object node name * @example * nodeName === "Person" * <Person>...</Person> */ nodeName: string; encoding?: "utf8" | "utf16le" | "ascii" | "base64" | "binary"; } export interface FastXMLWriteOptions { /** * Node attribute prefix * @example * const cfg: FastXMLWriteOptions = { attributeNamePrefix: "#", attrNodeName: "_" } * const obj = { "_":{ "#id": "1" }, "Person": { ... } } //-> <Person id="1">...</Person> */ attributeNamePrefix?: string; /** * Node attribute prefix * @example * const cfg: FastXMLWriteOptions = { attributeNamePrefix: "#", attrNodeName: "_" } * const obj = { "_":{ "#id": "1" }, "Person": { ... } } //-> <Person id="1">...</Person> */ attrNodeName?: false | string; /** * How text node is formatted? */ textNodeName?: string; ignoreAttributes?: boolean; cdataTagName?: false | string; cdataPositionChar?: string; format?: boolean; indentBy?: string; supressEmptyNode?: boolean; tagValueProcessor?: (tagValue: string) => string; attrValueProcessor?: (attrValue: string) => string; } export interface XMLWriteOptions extends FastXMLWriteOptions, FileReference, FileWriteMode, WriteProgressReportOptions { /** * Object node name * @example * nodeName === "Person" * <Person>...</Person> */ nodeName: string; } /** * Writes JSON object iteratable to file in .xml format * * @include ./XMLWriteOptions.md * @example * import { AsyncIterable } from 'ix' * import { xmlWrite } from 'iterparse' * * AsyncIterable.from([{ a: 1, b: 2 }, { a: 1, b: 2 }]) * .pipe(xmlWrite({ filePath: "path/to/file", nodeName: 'Person' })) * .count() * @example * import { xmlWrite } from 'iterparse' * * xmlWrite([{...}, {...}], { filePath: 'filePath', nodeName: "Person" }) * .count() * @category XML */ export declare function xmlWrite<T extends { [k: string]: unknown; }>(options: XMLWriteOptions): (data: AnyIterable<T>) => IX<T>; export declare function xmlWrite<T extends { [k: string]: unknown; }>(data: AnyIterable<T>, options: XMLWriteOptions): IX<T>; /** * Function read xml from file in memory efficient way * This parser are able to handled `unlimited` size xml files in memory efficient manner. * * @includes ./xml-read.md * @example * import { xmlRead } from 'iterparse' * xmlRead({ filePath: "./path/to/file.xml" }) * .map((q)=> console.log(q)) * .count() * @example * import { xmlRead } from 'iterparse' * for await (const item of xmlRead({ filePath: "./path/to/file.xml" })) { * console.log(item) * } * @category XML */ export declare function xmlRead<T>(options: XMLReadOptions): IX<T>; //# sourceMappingURL=xml.d.ts.map