MCPcopy Create free account
hub / github.com/Easy-Editor/EasyEditor / transformArrayToMap

Function transformArrayToMap

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

Source from the content-addressed store, hash-verified

69}
70
71export const transformArrayToMap = (arr: any[], key: string, overwrite = true) => {
72 if (!arr || !Array.isArray(arr)) {
73 return {}
74 }
75 const res: any = {}
76 arr.forEach(item => {
77 const curKey = item[key]
78 if (item[key] === undefined) {
79 return
80 }
81 if (res[curKey] && !overwrite) {
82 return
83 }
84 res[curKey] = item
85 })
86 return res
87}
88
89interface IParseOptions {
90 logScope?: string

Callers 3

BaseRendererClass · 0.90
constructorMethod · 0.90
updateConfigMethod · 0.90

Calls 1

forEachMethod · 0.45

Tested by

no test coverage detected