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

Function createDOMPurify

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

Source from the content-addressed store, hash-verified

230};
231
232function 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

Callers 7

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

Calls 10

getGlobalFunction · 0.85
lookupGetterFunction · 0.85
lookupAccessorFunction · 0.85
_createHooksMapFunction · 0.85
addToSetFunction · 0.85
_sanitizeFunction · 0.85
_parseConfigFunction · 0.85
_isUnsafeAttributeValueFunction · 0.85
regExpTestFunction · 0.85
_isValidAttributeFunction · 0.85

Tested by

no test coverage detected