-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdot_jq
82 lines (59 loc) · 1.23 KB
/
dot_jq
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
def head($count):
.[0:$count]|select(length > 0) |
if type == "array" then .[] else . end;
def tail($count):
.[$count:];
def head:
head(1);
def tail:
tail(1);
def capitalize:
(head | ascii_upcase) + tail;
def from_kebab:
split("-");
def to_kebab:
join("-");
def from_snake:
split("_");
def to_snake:
join("_");
def from_pascal:
[splits("(?=[A-Z])")] | map(select(. != "")) | map(ascii_downcase);
def to_pascal:
map(capitalize) | join("");
def from_camel:
from_pascal;
def to_camel:
[ head ] + (tail | map(capitalize)) | join("");
def from_constant:
from_snake | map(ascii_downcase);
def to_constant:
map(ascii_upcase) | join("_");
def from_dot:
split(".");
def to_dot:
join(".");
def from_header:
split("-") | map(ascii_downcase);
def to_header:
map(capitalize) | join("-");
def to_manycase_regex:
join("[ -_]*");
def map_keys(mapper):
walk(
if type == "object" then
with_entries(.key |= mapper)
else .
end
);
def map_files:
reduce inputs as $line ({}; .[input_filename] += [$line]);
def flatten_object:
[
leaf_paths as $path | {
key: $path | join("_"),
value: getpath($path)
}
]|from_entries;
def chunk($n):
range(length/$n|ceil) as $i | .[$n*$i:$n*$i+5];