MCPcopy Create free account
hub / github.com/violentmonkey/violentmonkey / envFile

Method envFile

scripts/config-helper.js:15–40  ·  view source on GitHub ↗
(filepath = '.env')

Source from the content-addressed store, hash-verified

13 }
14
15 envFile(filepath = '.env') {
16 let content = '';
17 try {
18 content = fs.readFileSync(filepath, 'utf8');
19 } catch {
20 // ignore error
21 }
22 const values = content
23 .split('\n')
24 .map((line) => line.trim())
25 .filter((line) => line && !line.startsWith('#'))
26 .map((line) => {
27 const i = line.indexOf('=');
28 if (i < 0) return [];
29 const key = line.slice(0, i).trim();
30 let value = line.slice(i + 1).trim();
31 // Note: escaped characters are not supported
32 if (/^(['"]).*\1$/.test(value)) value = value.slice(1, -1);
33 return [key, value];
34 })
35 .reduce((prev, [key, value]) => {
36 if (key) prev[key] = value;
37 return prev;
38 }, {});
39 return this.add(values);
40 }
41
42 get(key, def) {
43 return this.data[key] ?? def;

Callers 1

webpack.conf.jsFile · 0.80

Calls 4

addMethod · 0.95
mapMethod · 0.80
filterMethod · 0.80
testMethod · 0.45

Tested by

no test coverage detected