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

Function addToSet

src/utils.ts:119–156  ·  view source on GitHub ↗

* Add properties to a lookup table * * @param set - The set to which elements will be added. * @param array - The array containing elements to be added to the set. * @param transformCaseFunc - An optional function to transform the case of each element before adding to the set. * @returns The mo

(
  set: Record<string, boolean>,
  array: readonly unknown[],
  transformCaseFunc: ReturnType<typeof unapply<string>> = stringToLowerCase
)

Source from the content-addressed store, hash-verified

117 * @returns The modified set with added elements.
118 */
119function addToSet(
120 set: Record<string, boolean>,
121 array: readonly unknown[],
122 transformCaseFunc: ReturnType<typeof unapply<string>> = stringToLowerCase
123): Record<string, boolean> {
124 if (setPrototypeOf) {
125 // Make 'in' and truthy checks like Boolean(set.constructor)
126 // independent of any properties defined on Object.prototype.
127 // Prevent prototype setters from intercepting set as a this value.
128 setPrototypeOf(set, null);
129 }
130
131 if (!arrayIsArray(array)) {
132 return set;
133 }
134
135 let l = array.length;
136 while (l--) {
137 let element = array[l];
138
139 if (typeof element === 'string') {
140 const lcElement = transformCaseFunc(element);
141
142 if (lcElement !== element) {
143 // Config presets (e.g. tags.js, attrs.js) are immutable.
144 if (!isFrozen(array)) {
145 (array as unknown[])[l] = lcElement;
146 }
147
148 element = lcElement;
149 }
150 }
151
152 set[element as string] = true;
153 }
154
155 return set;
156}
157
158/**
159 * Clean up an array to harden against CSPP

Callers 4

purify.tsFile · 0.85
_resolveSetOptionFunction · 0.85
createDOMPurifyFunction · 0.85
_parseConfigFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected