-
Notifications
You must be signed in to change notification settings - Fork 0
/
.fxrc.js
54 lines (49 loc) · 1.69 KB
/
.fxrc.js
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
//carbon global.i3windows = function (json) {
//carbon function select(item, parent_item) {
//carbon if (parent_item === null) return null;
//carbon if (item.window_type === 'normal' || item.window_type === 'unknown') {
//carbon return [
//carbon item.id,
//carbon (parent_item?.name || '??').padStart(2, ' '),
//carbon item.window_properties.instance.padEnd(16, ' '),
//carbon item.window_properties.title,
//carbon ].join(' ');
//carbon }
//carbon }
//carbon function traverse(item, parent_item = null) {
//carbon const children = item.nodes.map((child) => {
//carbon return traverse(child, item.type === 'workspace' ? item : parent_item);
//carbon });
//carbon return [select(item, parent_item), ...children.flat()];
//carbon }
//carbon return traverse(json).filter(Boolean).join('\n');
//carbon };
// example: | fx 'matrix("foo", "bar")'
global.matrix = function (...params) {
return function (json) {
return json.map((x) => params.map((xx) => x[xx]).join('\t')).join('\n');
};
};
global.flat = function (json) {
const nskv = {};
let pad = 0;
function namespace(prefix, obj) {
Object.entries(obj).map((item) => {
const [key, value] = item;
const nskey = [prefix, key].filter(Boolean).join('.');
if (typeof value === typeof {} && value) {
namespace(nskey, value);
return;
}
if (nskey.length > pad) {
pad = nskey.length;
}
nskv[nskey] =
typeof value === 'string' ? value.replace(/\n/g, '\\n') : value;
});
}
namespace(undefined, json);
return Object.entries(nskv)
.map((kv) => [kv[0].padEnd(pad), kv[1]].join('\t'))
.join('\n');
};