MCPcopy Create free account
hub / github.com/cure53/DOMPurify / createDOMPurify

Function createDOMPurify

src/purify.ts:230–3148  ·  view source on GitHub ↗
(window: WindowLike = getGlobal())

Source from the content-addressed store, hash-verified

228};
229
230function createDOMPurify(window: WindowLike = getGlobal()): DOMPurify {
231 const DOMPurify: DOMPurify = (root: WindowLike) => createDOMPurify(root);
232
233 DOMPurify.version = VERSION;
234
235 DOMPurify.removed = [];
236
237 if (
238 !window ||
239 !window.document ||
240 window.document.nodeType !== NODE_TYPE.document ||
241 !window.Element
242 ) {
243 // Not running in a browser, provide a factory function
244 // so that you can pass your own Window
245 DOMPurify.isSupported = false;
246
247 return DOMPurify;
248 }
249
250 let { document } = window;
251
252 const originalDocument = document;
253 const currentScript: HTMLScriptElement =
254 originalDocument.currentScript as HTMLScriptElement;
255 const {
256 DocumentFragment,
257 HTMLTemplateElement,
258 Node,
259 Element,
260 NodeFilter,
261 NamedNodeMap = window.NamedNodeMap || (window as any).MozNamedAttrMap,
262 HTMLFormElement,
263 DOMParser,
264 trustedTypes,
265 } = window;
266
267 const ElementPrototype = Element.prototype;
268
269 const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
270 const remove = lookupGetter(ElementPrototype, 'remove');
271 const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
272 const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
273 const getParentNode = lookupGetter(ElementPrototype, 'parentNode');
274 const getShadowRoot = lookupGetter(ElementPrototype, 'shadowRoot');
275 const getAttributes = lookupGetter(ElementPrototype, 'attributes');
276 const getNodeType =
277 Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeType') : null;
278 const getNodeName =
279 Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeName') : null;
280 const getOwnerDocument =
281 Node && Node.prototype
282 ? lookupGetter(Node.prototype, 'ownerDocument')
283 : null;
284
285 /* Clobber-safe nodeType / nodeName reads through the cached Node.prototype
286 getters, with a direct-property fallback for environments that lack
287 Node.prototype. Sites that need a different fallback (e.g. _isClobbered

Callers 6

startQUnitFunction · 0.85
startQUnitFunction · 0.85
withDOMPurifyFunction · 0.85
DOMPurifyFunction · 0.85
purify.tsFile · 0.85
runFunction · 0.85

Calls 15

getGlobalFunction · 0.85
lookupGetterFunction · 0.85
_createHooksMapFunction · 0.85
addToSetFunction · 0.85
_isNodeFunction · 0.85
stringifyValueFunction · 0.85
_parseConfigFunction · 0.85
cloneFunction · 0.85
_neutralizePatchLinkageFunction · 0.85
_readNodeNameFunction · 0.85
_neutralizeRootFunction · 0.85
_isClobberedFunction · 0.85

Tested by

no test coverage detected