@jdeighan/coffee-utils 7.0.12 → 7.0.15

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jdeighan/coffee-utils",
3
3
  "type": "module",
4
- "version": "7.0.12",
4
+ "version": "7.0.15",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
@@ -379,3 +379,11 @@ export strcat = (lItems...) ->
379
379
  for item in lItems
380
380
  str += item.toString()
381
381
  return str
382
+
383
+ # ---------------------------------------------------------------------------
384
+
385
+ export replaceVars = (line, hVars={}, regexp=/__(env\.)?([A-Za-z_]\w*)__/) ->
386
+
387
+ replacerFunc = (match, prefix, name) =>
388
+ return if prefix then process.env[name] else hVars[name].toString()
389
+ return line.replace(regexp, replacerFunc)
@@ -408,3 +408,16 @@ export var strcat = function(...lItems) {
408
408
  }
409
409
  return str;
410
410
  };
411
+
412
+ // ---------------------------------------------------------------------------
413
+ export var replaceVars = function(line, hVars = {}, regexp = /__(env\.)?([A-Za-z_]\w*)__/) {
414
+ var replacerFunc;
415
+ replacerFunc = (match, prefix, name) => {
416
+ if (prefix) {
417
+ return process.env[name];
418
+ } else {
419
+ return hVars[name].toString();
420
+ }
421
+ };
422
+ return line.replace(regexp, replacerFunc);
423
+ };
@@ -21,13 +21,17 @@ export LOG = (lArgs...) ->
21
21
 
22
22
  [label, item] = lArgs
23
23
  if lArgs.length > 1
24
- console.log sep_dash
25
- if item?
26
- console.log "#{label}:"
27
- console.log untabify(orderedStringify(item))
28
- else
24
+ # --- There's both a label and an item
25
+ if ! item?
29
26
  console.log "#{label}: UNDEFINED"
30
- console.log sep_dash
27
+ else
28
+ console.log sep_dash
29
+ console.log "#{label}:"
30
+ if isString(item)
31
+ console.log untabify(item)
32
+ else
33
+ console.log untabify(orderedStringify(item))
34
+ console.log sep_dash
31
35
  else
32
36
  console.log label
33
37
  return
package/src/log_utils.js CHANGED
@@ -39,14 +39,18 @@ export var LOG = function(...lArgs) {
39
39
  var item, label;
40
40
  [label, item] = lArgs;
41
41
  if (lArgs.length > 1) {
42
- console.log(sep_dash);
43
- if (item != null) {
44
- console.log(`${label}:`);
45
- console.log(untabify(orderedStringify(item)));
46
- } else {
42
+ if (item == null) {
47
43
  console.log(`${label}: UNDEFINED`);
44
+ } else {
45
+ console.log(sep_dash);
46
+ console.log(`${label}:`);
47
+ if (isString(item)) {
48
+ console.log(untabify(item));
49
+ } else {
50
+ console.log(untabify(orderedStringify(item)));
51
+ }
52
+ console.log(sep_dash);
48
53
  }
49
- console.log(sep_dash);
50
54
  } else {
51
55
  console.log(label);
52
56
  }