forked from darkreader/darkreader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat.ts
More file actions
42 lines (37 loc) · 1.17 KB
/
Copy pathformat.ts
File metadata and controls
42 lines (37 loc) · 1.17 KB
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
import {push} from '../../utils/array';
interface SiteFix {
url: string[];
[prop: string]: any;
}
interface SitesFixesFormatOptions {
props: string[];
getPropCommandName: (prop: string) => string;
formatPropValue: (prop: string, value) => string;
shouldIgnoreProp: (props: string, value) => boolean;
}
export function formatSitesFixesConfig(fixes: SiteFix[], options: SitesFixesFormatOptions) {
const lines: string[] = [];
fixes.forEach((fix, i) => {
push(lines, fix.url);
options.props.forEach((prop) => {
const command = options.getPropCommandName(prop);
const value = fix[prop];
if (options.shouldIgnoreProp(prop, value)) {
return;
}
lines.push('');
lines.push(command);
const formattedValue = options.formatPropValue(prop, value);
if (formattedValue) {
lines.push(formattedValue);
}
});
if (i < fixes.length - 1) {
lines.push('');
lines.push('='.repeat(32));
lines.push('');
}
});
lines.push('');
return lines.join('\n');
}