@jdeighan/coffee-utils 7.0.23 → 7.0.24
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.
- package/package.json +1 -1
- package/src/coffee_utils.coffee +12 -1
- package/src/coffee_utils.js +10 -2
package/package.json
CHANGED
package/src/coffee_utils.coffee
CHANGED
@@ -397,6 +397,17 @@ export strcat = (lItems...) ->
|
|
397
397
|
|
398
398
|
export replaceVars = (line, hVars={}, rx=/__(env\.)?([A-Za-z_]\w*)__/g) ->
|
399
399
|
|
400
|
+
assert isHash(hVars), "replaceVars() hVars is not a hash"
|
401
|
+
|
400
402
|
replacerFunc = (match, prefix, name) =>
|
401
|
-
|
403
|
+
if prefix
|
404
|
+
result = process.env[name]
|
405
|
+
else if ! hVars[name]?
|
406
|
+
result = 'undef'
|
407
|
+
else
|
408
|
+
result = hVars[name]
|
409
|
+
if ! isString(result)
|
410
|
+
result = JSON.stringify(result)
|
411
|
+
return result
|
412
|
+
|
402
413
|
return line.replace(rx, replacerFunc)
|
package/src/coffee_utils.js
CHANGED
@@ -429,12 +429,20 @@ export var strcat = function(...lItems) {
|
|
429
429
|
// ---------------------------------------------------------------------------
|
430
430
|
export var replaceVars = function(line, hVars = {}, rx = /__(env\.)?([A-Za-z_]\w*)__/g) {
|
431
431
|
var replacerFunc;
|
432
|
+
assert(isHash(hVars), "replaceVars() hVars is not a hash");
|
432
433
|
replacerFunc = (match, prefix, name) => {
|
434
|
+
var result;
|
433
435
|
if (prefix) {
|
434
|
-
|
436
|
+
result = process.env[name];
|
437
|
+
} else if (hVars[name] == null) {
|
438
|
+
result = 'undef';
|
435
439
|
} else {
|
436
|
-
|
440
|
+
result = hVars[name];
|
441
|
+
if (!isString(result)) {
|
442
|
+
result = JSON.stringify(result);
|
443
|
+
}
|
437
444
|
}
|
445
|
+
return result;
|
438
446
|
};
|
439
447
|
return line.replace(rx, replacerFunc);
|
440
448
|
};
|