@mono-labs/cli 0.0.144 → 0.0.146
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.
|
@@ -20,30 +20,27 @@ export function hasData(key) {
|
|
|
20
20
|
return Object.prototype.hasOwnProperty.call(dataLayer, key);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
export function replaceTokens(str, env
|
|
23
|
+
export function replaceTokens(str, env) {
|
|
24
24
|
if (typeof str !== 'string') return str;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
//
|
|
30
|
-
if (hasData(k)) {
|
|
31
|
-
const val = getData(k);
|
|
32
|
-
return String(val);
|
|
25
|
+
|
|
26
|
+
return str.replace(/\$\{([^}]+)\}|\$([A-Z0-9_]+)/g, (m, k1, k2) => {
|
|
27
|
+
const k = k1 || k2;
|
|
28
|
+
|
|
29
|
+
// existing data layer takes priority (guarded in case not defined)
|
|
30
|
+
if (typeof hasData === 'function' && hasData(k)) {
|
|
31
|
+
const val = typeof getData === 'function' ? getData(k) : undefined;
|
|
32
|
+
return val == null ? '' : String(val);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
//
|
|
35
|
+
// environment variables
|
|
36
36
|
if (env && Object.prototype.hasOwnProperty.call(env, k)) {
|
|
37
37
|
const val = env[k];
|
|
38
|
-
return
|
|
38
|
+
return val == null ? '' : String(val);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
//
|
|
41
|
+
// fallback
|
|
42
42
|
return '';
|
|
43
43
|
});
|
|
44
|
-
console.log('rVal:', rVal);
|
|
45
|
-
|
|
46
|
-
return rVal;
|
|
47
44
|
}
|
|
48
45
|
|
|
49
46
|
export default dataLayer;
|