MCPcopy
hub / github.com/cure53/DOMPurify / createDOMPurify

Function createDOMPurify

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

Source from the content-addressed store, hash-verified

164};
165
166function createDOMPurify(window: WindowLike = getGlobal()): DOMPurify {
167 const DOMPurify: DOMPurify = (root: WindowLike) => createDOMPurify(root);
168
169 DOMPurify.version = VERSION;
170
171 DOMPurify.removed = [];
172
173 if (
174 !window ||
175 !window.document ||
176 window.document.nodeType !== NODE_TYPE.document ||
177 !window.Element
178 ) {
179 // Not running in a browser, provide a factory function
180 // so that you can pass your own Window
181 DOMPurify.isSupported = false;
182
183 return DOMPurify;
184 }
185
186 let { document } = window;
187
188 const originalDocument = document;
189 const currentScript: HTMLScriptElement =
190 originalDocument.currentScript as HTMLScriptElement;
191 const {
192 DocumentFragment,
193 HTMLTemplateElement,
194 Node,
195 Element,
196 NodeFilter,
197 NamedNodeMap = window.NamedNodeMap || (window as any).MozNamedAttrMap,
198 HTMLFormElement,
199 DOMParser,
200 trustedTypes,
201 } = window;
202
203 const ElementPrototype = Element.prototype;
204
205 const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
206 const remove = lookupGetter(ElementPrototype, 'remove');
207 const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
208 const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
209 const getParentNode = lookupGetter(ElementPrototype, 'parentNode');
210 const getShadowRoot = lookupGetter(ElementPrototype, 'shadowRoot');
211 const getAttributes = lookupGetter(ElementPrototype, 'attributes');
212 const getNodeType =
213 Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeType') : null;
214 const getNodeName =
215 Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeName') : null;
216
217 // As per issue #47, the web-components registry is inherited by a
218 // new document created via createHTMLDocument. As per the spec
219 // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
220 // a new empty registry is used when creating a template contents owner
221 // document, so we use that as our parent document to ensure nothing
222 // is inherited.
223 if (typeof HTMLTemplateElement === 'function') {

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
_isClobberedFunction · 0.85
_neutralizeRootFunction · 0.85
_initDocumentFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…