MCPcopy Index your code
hub / github.com/alibaba/lowcode-engine / transformArrayToMap

Function transformArrayToMap

packages/renderer-core/src/utils/common.ts:163–179  ·  view source on GitHub ↗
(arr: any[], key: string, overwrite = true)

Source from the content-addressed store, hash-verified

161 * @returns object result map
162 */
163export function transformArrayToMap(arr: any[], key: string, overwrite = true) {
164 if (isEmpty(arr) || !Array.isArray(arr)) {
165 return {};
166 }
167 const res: any = {};
168 arr.forEach((item) => {
169 const curKey = item[key];
170 if (item[key] === undefined) {
171 return;
172 }
173 if (res[curKey] && !overwrite) {
174 return;
175 }
176 res[curKey] = item;
177 });
178 return res;
179}
180
181/**
182 * transform string to a function

Callers 4

constructorMethod · 0.90
updateConfigMethod · 0.90
BaseRendererClass · 0.90
common.test.tsFile · 0.90

Calls 1

forEachMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…