(arr: any[], key: string, overwrite = true)
| 161 | * @returns object result map |
| 162 | */ |
| 163 | export 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 |
no test coverage detected
searching dependent graphs…