zarro 1.192.0 → 1.194.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 parseBool(name, value);
25
+ return parseBoolEnvVar(name, value);
25
26
  }
26
- const truthy = [
27
- "1",
28
- "yes",
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, true);
38
30
  }
39
- if (falsey.indexOf(value === null || value === void 0 ? void 0 : value.toString()) > -1) {
40
- return false;
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,25 @@
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, strict) {
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
+ if (strict) {
21
+ throw new Error(`could not parse '${value}' as a boolean value`);
22
+ }
23
+ return !!value;
24
+ }
25
+ exports.parseBool = parseBool;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zarro",
3
- "version": "1.192.0",
3
+ "version": "1.194.0",
4
4
  "description": "Some glue to make gulp easier, perhaps even zero- or close-to-zero-conf",
5
5
  "bin": {
6
6
  "zarro": "index.js"
package/types.d.ts CHANGED
@@ -2216,5 +2216,9 @@ declare global {
2216
2216
  interface Timestamp {
2217
2217
  timestamp: (opts?: TimestampOptions) => string;
2218
2218
  }
2219
+
2220
+ interface ParseBool {
2221
+ parseBool: (s: string, strict?: boolean) => boolean;
2222
+ }
2219
2223
  }
2220
2224