File: format_summary.jq

package info (click to toggle)
fq 0.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 106,624 kB
  • sloc: xml: 2,835; makefile: 250; sh: 241; exp: 57; ansic: 21
file content (34 lines) | stat: -rwxr-xr-x 660 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env fq -f

def recurse_depth(f; cond):
  def _r($depth):
    ( ( .
      | select(cond)
      | {depth: $depth, value: .}
      )
    , ( [f]
      | to_entries[] as $e
      | $e.value
      | _r($depth + if cond then 1 else 0 end)
      )
    );
  _r(0);

[ ( recurse_depth(
      .[]?;
      format
    )
  | . + {
      norm_path: (.value._path | map(if type == "number" then "index" end)),
    }
  )
]
| streaks_by(.norm_path)
| map(.[0] + {count: length})
| .[]
| [ if .depth > 0 then "  "*.depth else empty end
  , ((.value | format) + if .count > 1 then "*\(.count) " else " " end)
  , (.value._path | path_to_expr)
  ]
| join("")
| println