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

Function localeFileToJson

tasks/bundle-locales.js:16–38  ·  view source on GitHub ↗

@type {(filePath: string) => Promise }

(filePath)

Source from the content-addressed store, hash-verified

14
15/** @type {(filePath: string) => Promise<LocaleMessages>} */
16async function localeFileToJson(filePath) {
17 let file = await readFile(filePath);
18 file = file.replace(/^#.*?$/gm, '');
19
20 /** @type {LocaleMessages} */
21 const messages = {};
22
23 const regex = /@([a-z0-9_]+)/ig;
24 let match;
25 while ((match = regex.exec(file))) {
26 const messageName = match[1];
27 const messageStart = match.index + match[0].length;
28 let messageEnd = file.indexOf('@', messageStart);
29 if (messageEnd < 0) {
30 messageEnd = file.length;
31 }
32 messages[messageName] = {
33 message: file.substring(messageStart, messageEnd).trim(),
34 };
35 }
36
37 return messages;
38}
39
40/** @type {(localesDir: string, code: string) => Promise<string>} */
41async function mergeLocale(localesDir, code) {

Callers 1

walkFunction · 0.85

Calls 2

readFileFunction · 0.90
execMethod · 0.80

Tested by

no test coverage detected