UNPKG

radius-read

Version:

Realtime Dashboard

55 lines 1.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PropertyService = void 0; const tslib_1 = require("tslib"); const fs = tslib_1.__importStar(require("fs")); const ini_1 = tslib_1.__importDefault(require("ini")); /** * Service to read properties from a configuration file. */ class PropertyService { /** * Creates an instance of PropertyService. */ constructor() { } /** * Gets properties from a configuration file. * @param configPath * @returns */ static getProperties(configPath) { const content = fs.readFileSync(configPath, 'utf-8'); const rawConfig = ini_1.default.parse(content); const result = {}; for (const [section, data] of Object.entries(rawConfig)) { const match = section.match(/^([^.]+)\.(.+)$/); if (match) { const group = match[1]; // WebApps const name = match[2]; // Grid if (!result[group]) { result[group] = []; } result[group].push(Object.assign({ name }, data)); } else { result[section] = data; } } return result; } static getPropertiesFromJson(jsonConfigPath) { const content = fs.readFileSync(jsonConfigPath, 'utf-8'); const rawConfig = JSON.parse(content); return rawConfig; } /** * Gets a specific property from a configuration object. * @param configObject * @returns */ static getProperty(configObject) { return configObject; } } exports.PropertyService = PropertyService; //# sourceMappingURL=property.service.js.map