MCPcopy Index your code
hub / github.com/darkreader/darkreader / parseSitesFixesConfig

Function parseSitesFixesConfig

src/generators/utils/parse.ts:24–60  ·  view source on GitHub ↗
(text: string, options: SitesFixesParserOptions<T>)

Source from the content-addressed store, hash-verified

22export type SiteFixesIndex = URLTrie<[number, number]>;
23
24export function parseSitesFixesConfig<T extends SiteProps>(text: string, options: SitesFixesParserOptions<T>): T[] {
25 const sites: T[] = [];
26
27 const blocks = text.replace(/\r/g, '').split(/^\s*={2,}\s*$/gm);
28 blocks.forEach((block) => {
29 const lines = block.split('\n');
30 const commandIndices: number[] = [];
31 lines.forEach((ln, i) => {
32 if (ln.match(/^[A-Z]+(\s[A-Z]+){0,2}$/)) {
33 commandIndices.push(i);
34 }
35 });
36
37 if (commandIndices.length === 0) {
38 return;
39 }
40
41 const siteFix = {
42 url: parseArray(lines.slice(0, commandIndices[0]).join('\n')) as readonly string[],
43 } as T;
44
45 commandIndices.forEach((commandIndex, i) => {
46 const command = lines[commandIndex].trim();
47 const valueText = lines.slice(commandIndex + 1, i === commandIndices.length - 1 ? lines.length : commandIndices[i + 1]).join('\n');
48 const prop = options.getCommandPropName(command);
49 if (!prop) {
50 return;
51 }
52 const value = options.parseCommandValue(command, valueText);
53 siteFix[prop] = value;
54 });
55
56 sites.push(siteFix);
57 });
58
59 return sites;
60}
61
62// URL patterns are guaranteed to not have protocol and leading '/'
63export function getDomain(url: string): string {

Callers 5

parseDetectorHintsFunction · 0.90
parseDynamicThemeFixesFunction · 0.90
parseStaticThemesFunction · 0.90
parseInversionFixesFunction · 0.90
parseFunction · 0.90

Calls 1

parseArrayFunction · 0.90

Tested by

no test coverage detected