| 133 | * Performs a case-insenstive merge of the list of objects. |
| 134 | */ |
| 135 | export function caseInsensitiveMerge<V>( |
| 136 | ...objs: ReadonlyArray<Readonly<{ [key: string]: V }> | undefined | null> |
| 137 | ) { |
| 138 | if (objs.length === 0) { |
| 139 | return {}; |
| 140 | } |
| 141 | |
| 142 | const out: { [key: string]: V } = {}; |
| 143 | const caseMapping: { [key: string]: string } = Object.create(null); // prototype-free object |
| 144 | for (const obj of objs) { |
| 145 | if (!obj) { |
| 146 | continue; |
| 147 | } |
| 148 | |
| 149 | for (const key of Object.keys(obj)) { |
| 150 | const normalized = key.toLowerCase(); |
| 151 | if (caseMapping[normalized]) { |
| 152 | out[caseMapping[normalized]] = obj[key]; |
| 153 | } else { |
| 154 | caseMapping[normalized] = key; |
| 155 | out[key] = obj[key]; |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | return out; |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Does a case-insensitive lookup on the given object. |