-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathessential.js
31 lines (25 loc) · 911 Bytes
/
essential.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
const fs = require('fs');
function readPropertiesFile(filePath) {
if (!fs.existsSync(filePath)) {
throw new Error(`Properties file not found: ${filePath}`);
}
const fileContent = fs.readFileSync(filePath, 'utf-8');
const lines = fileContent.split('\n');
const config = {};
lines.forEach(line => {
const trimmedLine = line.trim();
if (trimmedLine && trimmedLine.includes('=')) {
const [key, ...valueParts] = trimmedLine.split('=');
const value = valueParts.join('=').trim();
config[key.trim()] = value;
}
});
return config;
}
function replacePlaceholders(url, replacements) {
for (const placeholder in replacements) {
url = url.replace(new RegExp(`\\$\\{${placeholder}\\}`, 'g'), replacements[placeholder]);
}
return url;
}
module.exports = { readPropertiesFile, replacePlaceholders };