UNPKG

lit-xml

Version:

Burning your XML documents to the ground? Yes please. In the mean time, let's use lit-xml.

41 lines 1.21 kB
import { valueToString, format } from './xml-helpers.js'; export class XmlFragment { xmlLiterals; values; options; constructor(xmlLiterals, values, options) { this.xmlLiterals = xmlLiterals; this.values = values; this.options = options; } /** * Converts the XML fragment to a string. * This method runs the validators on the generated XML string. */ toString() { const xml = this.toStringRaw(); this.options.validators.forEach((validator) => validator(xml)); return format(xml, this.options); } /** * @internal * Same as `toString`, but does not run the validators. */ toStringRaw() { let stringBuilder = ''; for (let i = 0; i < this.values.length; i++) { stringBuilder = stringBuilder.concat(this.xmlLiterals[i], valueToString(this.values[i])); } return stringBuilder + this.xmlLiterals[this.xmlLiterals.length - 1]; } } export class UnsafeXmlFragment { #unsafeXml; constructor(unsafeXml) { this.#unsafeXml = unsafeXml; } toString() { return this.#unsafeXml; } } //# sourceMappingURL=xml-fragment.js.map