@digitraffic/common 2023.1.18-1 → 2023.1.18-2

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.
@@ -44,3 +44,18 @@ export declare function getEnvVariable(key: string): string;
44
44
  * @return Either<string>
45
45
  */
46
46
  export declare function getEnvVariableSafe(key: string): Either<string>;
47
+ /**
48
+ * Gets environment variable. If environment variable is undefined, returns value of given function.
49
+ *
50
+ * @param key Environment key
51
+ * @param fn Alternative function
52
+ */
53
+ export declare function getEnvVariableOr<T>(key: string, fn: () => T): string | T;
54
+ /**
55
+ * Gets environment variable. If environment variable is undefined, returns given value.
56
+ * Use to return an explicit alternative value e.g. in cases where environment variable may be undefined.
57
+ *
58
+ * @param key Environment key
59
+ * @param orElse Alternative value
60
+ */
61
+ export declare function getEnvVariableOrElse<T>(key: string, orElse: T): string | T;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getEnvVariableSafe = exports.getEnvVariable = exports.getFirst = exports.getLast = exports.bothArraysHasSameValues = void 0;
3
+ exports.getEnvVariableOrElse = exports.getEnvVariableOr = exports.getEnvVariableSafe = exports.getEnvVariable = exports.getFirst = exports.getLast = exports.bothArraysHasSameValues = void 0;
4
4
  function bothArraysHasSameValues(a, b) {
5
5
  if ((a && !b) || (!a && b)) {
6
6
  return false;
@@ -85,6 +85,7 @@ function getEnvVariableOr(key, fn) {
85
85
  }
86
86
  return fn();
87
87
  }
88
+ exports.getEnvVariableOr = getEnvVariableOr;
88
89
  /**
89
90
  * Gets environment variable. If environment variable is undefined, returns given value.
90
91
  * Use to return an explicit alternative value e.g. in cases where environment variable may be undefined.
@@ -95,4 +96,5 @@ function getEnvVariableOr(key, fn) {
95
96
  function getEnvVariableOrElse(key, orElse) {
96
97
  return getEnvVariableOr(key, () => orElse);
97
98
  }
99
+ exports.getEnvVariableOrElse = getEnvVariableOrElse;
98
100
  //# sourceMappingURL=utils.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitraffic/common",
3
- "version": "2023.01.18-1",
3
+ "version": "2023.01.18-2",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -110,7 +110,7 @@ export function getEnvVariableSafe(key: string): Either<string> {
110
110
  * @param key Environment key
111
111
  * @param fn Alternative function
112
112
  */
113
- function getEnvVariableOr<T>(key: string, fn: () => T): string | T {
113
+ export function getEnvVariableOr<T>(key: string, fn: () => T): string | T {
114
114
  const either = getEnvVariableSafe(key);
115
115
  if (either.result === "ok") {
116
116
  return either.value;
@@ -125,6 +125,6 @@ function getEnvVariableOr<T>(key: string, fn: () => T): string | T {
125
125
  * @param key Environment key
126
126
  * @param orElse Alternative value
127
127
  */
128
- function getEnvVariableOrElse<T>(key: string, orElse: T): string | T {
128
+ export function getEnvVariableOrElse<T>(key: string, orElse: T): string | T {
129
129
  return getEnvVariableOr(key, () => orElse);
130
130
  }