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

Function addToSet

src/utils.ts:114–151  ·  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

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