|
import { decodeXML, decodeHTML, DecodingMode } from "./decode.js"; |
|
import { encodeHTML, encodeNonAsciiHTML } from "./encode.js"; |
|
import { encodeXML, escapeUTF8, escapeAttribute, escapeText, } from "./escape.js"; |
|
|
|
export var EntityLevel; |
|
(function (EntityLevel) { |
|
|
|
EntityLevel[EntityLevel["XML"] = 0] = "XML"; |
|
|
|
EntityLevel[EntityLevel["HTML"] = 1] = "HTML"; |
|
})(EntityLevel || (EntityLevel = {})); |
|
export var EncodingMode; |
|
(function (EncodingMode) { |
|
|
|
|
|
|
|
|
|
EncodingMode[EncodingMode["UTF8"] = 0] = "UTF8"; |
|
|
|
|
|
|
|
|
|
|
|
EncodingMode[EncodingMode["ASCII"] = 1] = "ASCII"; |
|
|
|
|
|
|
|
|
|
EncodingMode[EncodingMode["Extensive"] = 2] = "Extensive"; |
|
|
|
|
|
|
|
|
|
EncodingMode[EncodingMode["Attribute"] = 3] = "Attribute"; |
|
|
|
|
|
|
|
|
|
EncodingMode[EncodingMode["Text"] = 4] = "Text"; |
|
})(EncodingMode || (EncodingMode = {})); |
|
|
|
|
|
|
|
|
|
|
|
|
|
export function decode(data, options = EntityLevel.XML) { |
|
const level = typeof options === "number" ? options : options.level; |
|
if (level === EntityLevel.HTML) { |
|
const mode = typeof options === "object" ? options.mode : undefined; |
|
return decodeHTML(data, mode); |
|
} |
|
return decodeXML(data); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function decodeStrict(data, options = EntityLevel.XML) { |
|
var _a; |
|
const opts = typeof options === "number" ? { level: options } : options; |
|
(_a = opts.mode) !== null && _a !== void 0 ? _a : (opts.mode = DecodingMode.Strict); |
|
return decode(data, opts); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
export function encode(data, options = EntityLevel.XML) { |
|
const opts = typeof options === "number" ? { level: options } : options; |
|
|
|
if (opts.mode === EncodingMode.UTF8) |
|
return escapeUTF8(data); |
|
if (opts.mode === EncodingMode.Attribute) |
|
return escapeAttribute(data); |
|
if (opts.mode === EncodingMode.Text) |
|
return escapeText(data); |
|
if (opts.level === EntityLevel.HTML) { |
|
if (opts.mode === EncodingMode.ASCII) { |
|
return encodeNonAsciiHTML(data); |
|
} |
|
return encodeHTML(data); |
|
} |
|
|
|
return encodeXML(data); |
|
} |
|
export { encodeXML, escape, escapeUTF8, escapeAttribute, escapeText, } from "./escape.js"; |
|
export { encodeHTML, encodeNonAsciiHTML, |
|
|
|
encodeHTML as encodeHTML4, encodeHTML as encodeHTML5, } from "./encode.js"; |
|
export { EntityDecoder, DecodingMode, decodeXML, decodeHTML, decodeHTMLStrict, decodeHTMLAttribute, |
|
|
|
decodeHTML as decodeHTML4, decodeHTML as decodeHTML5, decodeHTMLStrict as decodeHTML4Strict, decodeHTMLStrict as decodeHTML5Strict, decodeXML as decodeXMLStrict, } from "./decode.js"; |
|
|