UNPKG

curli-config

Version:

A small library to load/validate configuration files placed in different sides of the application using environments

40 lines (39 loc) 1.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const FilesPathsCollection_1 = require("./FilesPathsCollection"); class Settings { constructor(settingsByUser) { this.settingsByUser = settingsByUser; this.DEFAULT_FILE_NAME = 'default'; this.FILE_NAME_EXTENSION = '.json'; this.environments = ['local', 'dev', 'production']; this.forceValidateSchemas = true; this.environment = settingsByUser.environment; this.filesPaths = new FilesPathsCollection_1.FilesPathsCollection(settingsByUser.filesPaths); const environments = settingsByUser.environments; const forceSchemas = (settingsByUser.forceValidateSchemas) ? true : false; const existForceValidateSchemas = (typeof settingsByUser.forceValidateSchemas === 'boolean'); this.environments = (environments) ? environments : this.environments; this.forceValidateSchemas = (existForceValidateSchemas) ? forceSchemas : this.forceValidateSchemas; this.validate(); } getEnvironment() { return this.environment; } getForceValidateSchemas() { return this.forceValidateSchemas; } getFilesPaths() { return this.filesPaths; } validate() { if (this.environment === '') { throw new Error('The environment can\'t be empty.'); } if (this.environments.indexOf(this.environment) === -1) { throw new Error('This environment (' + this.environment + ') doesn\'t exist.'); } } } exports.Settings = Settings;