(data: any)
| 209 | * @returns |
| 210 | */ |
| 211 | export function getObjectPathArrayMap(data: any) { |
| 212 | const mapResult: Record<string, Array<any>> = {}; |
| 213 | |
| 214 | function traverse(obj: any, path: string = "") { |
| 215 | if (typeof obj !== "object" || obj === null || obj === undefined) { |
| 216 | return; |
| 217 | } |
| 218 | if (Array.isArray(obj)) { |
| 219 | mapResult[path] = obj; |
| 220 | } |
| 221 | for (const [key, value] of Object.entries(obj)) { |
| 222 | const newPath = path ? `${path}.${key}` : key; |
| 223 | traverse(value, newPath); |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | traverse(data); |
| 228 | // 将结果转换成数组,并且按照字母顺序排序,格式是{path:string,value:BaseType}[] |
| 229 | const arrayResult = Array.from(Object.entries(mapResult)) |
| 230 | .sort((a, b) => a[0].localeCompare(b[0])) |
| 231 | .map(([path, value]) => ({ path, value })); |
| 232 | |
| 233 | return { mapResult, arrayResult }; |
| 234 | } |
| 235 | |
| 236 | type DataArrayType = { |
| 237 | path: string; |
no test coverage detected