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

Function addToSet

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

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

Callers 3

_resolveSetOptionFunction · 0.85
createDOMPurifyFunction · 0.85
_parseConfigFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…