@mitm/config
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -7,52 +7,16 @@ (function (global, factory) { | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
class NoSuchConfigurationKeyError extends Error { | ||
constructor(key, varName) { | ||
super(`Configuration key "${key}" was required but is not defined (have you defined "${varName}"?).`); | ||
} | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
/* global Reflect, Promise */ | ||
var extendStatics = function(d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
function __extends(d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
} | ||
var NoSuchConfigurationKeyError = | ||
/** @class */ | ||
function (_super) { | ||
__extends(NoSuchConfigurationKeyError, _super); | ||
function NoSuchConfigurationKeyError(key, varName) { | ||
return _super.call(this, "Configuration key \"".concat(key, "\" was required but is not defined (have you defined \"").concat(varName, "\"?).")) || this; | ||
} | ||
return NoSuchConfigurationKeyError; | ||
}(Error); | ||
function getOptionalConfig(key, parser) { | ||
var varName = getEnvVariableName(key); | ||
var strValue = getVariables()[varName]; | ||
const varName = getEnvVariableName(key); | ||
const strValue = getVariables()[varName]; | ||
return strValue ? parser(strValue) : undefined; | ||
} | ||
function getConfig(key, parser) { | ||
var varName = getEnvVariableName(key); | ||
var strValue = getVariables()[varName]; | ||
const varName = getEnvVariableName(key); | ||
const strValue = getVariables()[varName]; | ||
@@ -66,5 +30,3 @@ if (!strValue) { | ||
function getEnvVariableName(key) { | ||
return key.split('.').map(function (part) { | ||
return _case.constant(part); | ||
}).join('_'); | ||
return key.split('.').map(part => _case.constant(part)).join('_'); | ||
} | ||
@@ -82,9 +44,9 @@ | ||
function asBoolean(value) { | ||
return value == 'true' ? true : value == 'false' ? false : common.ethrow(new Error("Cannot parse \"".concat(value, "\" as boolean (expected \"true\"|\"false\")."))); | ||
return value == 'true' ? true : value == 'false' ? false : common.ethrow(new Error(`Cannot parse "${value}" as boolean (expected "true"|"false").`)); | ||
} | ||
function asNumber(value) { | ||
var number = Number(value); | ||
const number = Number(value); | ||
if (Number.isNaN(number)) { | ||
throw new Error("Cannot parse \"".concat(value, "\" as number (parsing resulted in NaN)")); | ||
throw new Error(`Cannot parse "${value}" as number (parsing resulted in NaN)`); | ||
} | ||
@@ -95,9 +57,9 @@ | ||
function asNodeEnv(value) { | ||
return value == 'development' ? 'development' : value == 'production' ? 'production' : common.ethrow(new Error("Cannot parse \"".concat(value, "\" as Node environment (expected \"development\"|\"production\")."))); | ||
return value == 'development' ? 'development' : value == 'production' ? 'production' : common.ethrow(new Error(`Cannot parse "${value}" as Node environment (expected "development"|"production").`)); | ||
} | ||
function asLogLevel(value) { | ||
var logLevels = ['error', 'warn', 'info', 'http', 'verbose', 'debug', 'silly']; | ||
const logLevels = ['error', 'warn', 'info', 'http', 'verbose', 'debug', 'silly']; | ||
if (!logLevels.includes(value)) { | ||
throw new Error("Cannot parse \"".concat(value, "\" as a standard npm/winston log level (allowed: ").concat(logLevels.join(', '), ").")); | ||
throw new Error(`Cannot parse "${value}" as a standard npm/winston log level (allowed: ${logLevels.join(', ')}).`); | ||
} | ||
@@ -108,8 +70,6 @@ | ||
function asCommaSeparatedStrings(value) { | ||
return value.split(',').map(function (key) { | ||
return key.trim(); | ||
}); | ||
return value.split(',').map(key => key.trim()); | ||
} | ||
var wellKnown = { | ||
const wellKnown = { | ||
get nodeEnv() { | ||
@@ -132,3 +92,3 @@ return getConfig('nodeEnv', asNodeEnv); | ||
var config = wellKnown; | ||
const config = wellKnown; | ||
@@ -135,0 +95,0 @@ exports.NoSuchConfigurationKeyError = NoSuchConfigurationKeyError; |
{ | ||
"name": "@mitm/config", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"dependencies": { | ||
@@ -5,0 +5,0 @@ "case": "^1.6.0" |
@@ -10,1 +10,5 @@ # @mitm/config | ||
- Ajout du parseur `asLogLevel` et utilisation dans la variable standard `config.logLevel`. | ||
### 2.2.0 | ||
- Cible de compilation plus moderne. |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
14
0
7837
177