MCPcopy Create free account
hub / github.com/triggerdotdev/jsonhero-web / groupRelatedValues

Function groupRelatedValues

app/utilities/relatedValues.ts:18–50  ·  view source on GitHub ↗
(
  relatedPaths: Array<string>,
  json: unknown
)

Source from the content-addressed store, hash-verified

16}
17
18export 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
52export function getRelatedPathsAtPath(
53 path: string,

Callers 2

RelatedValuesFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected