* 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, any>, array: readonly any[], transformCaseFunc: ReturnType<typeof unapply<string>> = stringToLowerCase )
| 97 | * @returns The modified set with added elements. |
| 98 | */ |
| 99 | function addToSet( |
| 100 | set: Record<string, any>, |
| 101 | array: readonly any[], |
| 102 | transformCaseFunc: ReturnType<typeof unapply<string>> = stringToLowerCase |
| 103 | ): Record<string, any> { |
| 104 | if (setPrototypeOf) { |
| 105 | // Make 'in' and truthy checks like Boolean(set.constructor) |
| 106 | // independent of any properties defined on Object.prototype. |
| 107 | // Prevent prototype setters from intercepting set as a this value. |
| 108 | setPrototypeOf(set, null); |
| 109 | } |
| 110 | |
| 111 | let l = array.length; |
| 112 | while (l--) { |
| 113 | let element = array[l]; |
| 114 | if (typeof element === 'string') { |
| 115 | const lcElement = transformCaseFunc(element); |
| 116 | if (lcElement !== element) { |
| 117 | // Config presets (e.g. tags.js, attrs.js) are immutable. |
| 118 | if (!isFrozen(array)) { |
| 119 | (array as any[])[l] = lcElement; |
| 120 | } |
| 121 | |
| 122 | element = lcElement; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | set[element] = true; |
| 127 | } |
| 128 | |
| 129 | return set; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Clean up an array to harden against CSPP |
no outgoing calls
no test coverage detected