(window: WindowLike = getGlobal())
| 230 | }; |
| 231 | |
| 232 | function createDOMPurify(window: WindowLike = getGlobal()): DOMPurify { |
| 233 | const DOMPurify: DOMPurify = (root: WindowLike) => createDOMPurify(root); |
| 234 | |
| 235 | DOMPurify.version = VERSION; |
| 236 | |
| 237 | DOMPurify.removed = []; |
| 238 | |
| 239 | if ( |
| 240 | !window || |
| 241 | !window.document || |
| 242 | window.document.nodeType !== NODE_TYPE.document || |
| 243 | !window.Element |
| 244 | ) { |
| 245 | // Not running in a browser, provide a factory function |
| 246 | // so that you can pass your own Window |
| 247 | DOMPurify.isSupported = false; |
| 248 | |
| 249 | return DOMPurify; |
| 250 | } |
| 251 | |
| 252 | let { document } = window; |
| 253 | |
| 254 | const originalDocument = document; |
| 255 | const currentScript: HTMLScriptElement = |
| 256 | originalDocument.currentScript as HTMLScriptElement; |
| 257 | const { |
| 258 | HTMLTemplateElement, |
| 259 | Node, |
| 260 | Element, |
| 261 | NodeFilter, |
| 262 | DOMParser, |
| 263 | trustedTypes, |
| 264 | } = window; |
| 265 | |
| 266 | const ElementPrototype = Element.prototype; |
| 267 | |
| 268 | const cloneNode = lookupGetter(ElementPrototype, 'cloneNode'); |
| 269 | const remove = lookupGetter(ElementPrototype, 'remove'); |
| 270 | const removeChild = lookupGetter(ElementPrototype, 'removeChild'); |
| 271 | // Cached, as a form child named "removeAttributeNode" shadows the method |
| 272 | const removeAttributeNode = lookupGetter( |
| 273 | ElementPrototype, |
| 274 | 'removeAttributeNode' |
| 275 | ); |
| 276 | const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling'); |
| 277 | const getChildNodes = lookupGetter(ElementPrototype, 'childNodes'); |
| 278 | const getParentNode = lookupGetter(ElementPrototype, 'parentNode'); |
| 279 | const getShadowRoot = lookupGetter(ElementPrototype, 'shadowRoot'); |
| 280 | const getAttributes = lookupGetter(ElementPrototype, 'attributes'); |
| 281 | const getNodeType = |
| 282 | Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeType') : null; |
| 283 | const getNodeName = |
| 284 | Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeName') : null; |
| 285 | const getOwnerDocument = |
| 286 | Node && Node.prototype |
| 287 | ? lookupGetter(Node.prototype, 'ownerDocument') |
| 288 | : null; |
| 289 |
no test coverage detected