@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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jdeighan/coffee-utils",
3
3
  "type": "module",
4
- "version": "7.0.23",
4
+ "version": "7.0.24",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
@@ -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
- return if prefix then process.env[name] else hVars[name].toString()
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)
@@ -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
- return process.env[name];
436
+ result = process.env[name];
437
+ } else if (hVars[name] == null) {
438
+ result = 'undef';
435
439
  } else {
436
- return hVars[name].toString();
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
  };