( relatedPaths: Array<string>, json: unknown )
| 16 | } |
| 17 | |
| 18 | export function groupRelatedValues( |
| 19 | relatedPaths: Array<string>, |
| 20 | json: unknown |
| 21 | ): Array<RelatedValuesGroup> { |
| 22 | const groupedByValue = groupBy(relatedPaths, (path) => { |
| 23 | const heroPath = new JSONHeroPath(path); |
| 24 | |
| 25 | const value = heroPath.first(json); |
| 26 | |
| 27 | if (typeof value === "undefined") { |
| 28 | return "undefined"; |
| 29 | } else if (value == null) { |
| 30 | return "null"; |
| 31 | } else if (Array.isArray(value)) { |
| 32 | return `Array(${value.length})`; |
| 33 | } else if (typeof value === "object") { |
| 34 | return "{...}"; |
| 35 | } else { |
| 36 | return value.toString(); |
| 37 | } |
| 38 | }); |
| 39 | |
| 40 | const unsortedResult = Object.entries(groupedByValue).map( |
| 41 | ([value, paths]) => { |
| 42 | return { |
| 43 | value, |
| 44 | paths: sortBy(paths), |
| 45 | }; |
| 46 | } |
| 47 | ); |
| 48 | |
| 49 | return sortBy(unsortedResult, (group) => -group.paths.length); |
| 50 | } |
| 51 | |
| 52 | export function getRelatedPathsAtPath( |
| 53 | path: string, |
no outgoing calls
no test coverage detected