zarro 1.191.2 → 1.193.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
(function () {
|
|
3
3
|
const ZarroError = requireModule("zarro-error");
|
|
4
|
+
const { parseBool } = requireModule("parse-bool");
|
|
4
5
|
function env(name, fallback) {
|
|
5
6
|
const value = process.env[name];
|
|
6
7
|
if (value !== undefined) {
|
|
@@ -21,25 +22,15 @@
|
|
|
21
22
|
}
|
|
22
23
|
function envFlag(name, fallback) {
|
|
23
24
|
const haveFallback = fallback !== undefined, value = haveFallback ? env(name, fallback === null || fallback === void 0 ? void 0 : fallback.toString()) : env(name);
|
|
24
|
-
return
|
|
25
|
+
return parseBoolEnvVar(name, value);
|
|
25
26
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"true"
|
|
30
|
-
], falsey = [
|
|
31
|
-
"0",
|
|
32
|
-
"no",
|
|
33
|
-
"false"
|
|
34
|
-
];
|
|
35
|
-
function parseBool(name, value) {
|
|
36
|
-
if (truthy.indexOf(value === null || value === void 0 ? void 0 : value.toString()) > -1) {
|
|
37
|
-
return true;
|
|
27
|
+
function parseBoolEnvVar(name, value) {
|
|
28
|
+
try {
|
|
29
|
+
return parseBool(value);
|
|
38
30
|
}
|
|
39
|
-
|
|
40
|
-
|
|
31
|
+
catch (e) {
|
|
32
|
+
throw new ZarroError(`environment variable '${name}' is invalid: could not parse '${value}' as a boolean value`);
|
|
41
33
|
}
|
|
42
|
-
throw new ZarroError(`environment variable '${name}' is invalid: could not parse '${value}' as a boolean value`);
|
|
43
34
|
}
|
|
44
35
|
module.exports = {
|
|
45
36
|
env,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseBool = void 0;
|
|
4
|
+
const truthy = [
|
|
5
|
+
"1",
|
|
6
|
+
"yes",
|
|
7
|
+
"true"
|
|
8
|
+
], falsey = [
|
|
9
|
+
"0",
|
|
10
|
+
"no",
|
|
11
|
+
"false"
|
|
12
|
+
];
|
|
13
|
+
function parseBool(value) {
|
|
14
|
+
if (truthy.indexOf(value === null || value === void 0 ? void 0 : value.toString()) > -1) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
if (falsey.indexOf(value === null || value === void 0 ? void 0 : value.toString()) > -1) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
throw new Error(`could not parse '${value}' as a boolean value`);
|
|
21
|
+
}
|
|
22
|
+
exports.parseBool = parseBool;
|
package/package.json
CHANGED