MCPcopy Create free account
hub / github.com/Snapchat/Valdi / caseInsensitiveMerge

Function caseInsensitiveMerge

valdi/vscode_debugger/src/common/objUtils.ts:135–161  ·  view source on GitHub ↗
(
  ...objs: ReadonlyArray<Readonly<{ [key: string]: V }> | undefined | null>
)

Source from the content-addressed store, hash-verified

133 * Performs a case-insenstive merge of the list of objects.
134 */
135export 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.

Callers 1

mergeMethod · 0.90

Calls 2

createMethod · 0.65
keysMethod · 0.65

Tested by

no test coverage detected