(arr: any[], key: string, overwrite = true)
| 69 | } |
| 70 | |
| 71 | export 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 | |
| 89 | interface IParseOptions { |
| 90 | logScope?: string |
no test coverage detected