@jdeighan/coffee-utils 2.1.8 → 2.1.12

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": "2.1.8",
4
+ "version": "2.1.12",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
@@ -351,6 +351,8 @@ export oneline = (obj) ->
351
351
  else
352
352
  return 'undef'
353
353
 
354
+ export OL = oneline
355
+
354
356
  # ---------------------------------------------------------------------------
355
357
  # truncateBlock - limit block to a certain number of lines
356
358
 
@@ -383,6 +383,8 @@ export var oneline = function(obj) {
383
383
  }
384
384
  };
385
385
 
386
+ export var OL = oneline;
387
+
386
388
  // ---------------------------------------------------------------------------
387
389
  // truncateBlock - limit block to a certain number of lines
388
390
  export var truncateBlock = function(str, numLines) {
@@ -26,6 +26,12 @@ lDebugFuncs = undef
26
26
 
27
27
  # ---------------------------------------------------------------------------
28
28
 
29
+ stripArrow = (prefix) ->
30
+
31
+ return prefix.replace(arrow, ' ')
32
+
33
+ # ---------------------------------------------------------------------------
34
+
29
35
  export debugIfLineMatches = (regexp=undef) ->
30
36
 
31
37
  ifMatches = regexp
@@ -92,20 +98,6 @@ export resetDebugging = () ->
92
98
  lDebugStack = []
93
99
  return
94
100
 
95
- # ---------------------------------------------------------------------------
96
- # --- export only to allow unit testing
97
-
98
- export patchDebugStr = (str) ->
99
-
100
- # --- Match things like "$varname$" to "'#{escapeStr(varname)}'"
101
- re = /\$([A-Za-z_][A-Za-z0-9_]*)\$/g
102
-
103
- replacer = (match, ident) ->
104
-
105
- return "'\#\{escapeStr(#{ident})\}'"
106
-
107
- return str.replace(re, replacer)
108
-
109
101
  # ---------------------------------------------------------------------------
110
102
 
111
103
  export debug = (lArgs...) ->
@@ -128,13 +120,13 @@ export debug = (lArgs...) ->
128
120
  item = lArgs[1]
129
121
 
130
122
  # --- determine if we're entering or returning from a function
131
- entering = exiting = false
123
+ entering = returning = false
132
124
  curFunc = undef
133
125
  if (lMatches = str.match(///^
134
126
  \s*
135
127
  enter
136
128
  \s+
137
- ([A-Za-z_][A-Za-z0-9_]*)
129
+ ([A-Za-z_][A-Za-z0-9_\.]*)
138
130
  ///))
139
131
  entering = true
140
132
  curFunc = lMatches[1]
@@ -144,9 +136,9 @@ export debug = (lArgs...) ->
144
136
  .*
145
137
  from
146
138
  \s+
147
- ([A-Za-z_][A-Za-z0-9_]*)
139
+ ([A-Za-z_][A-Za-z0-9_\.]*)
148
140
  ///))
149
- exiting = true
141
+ returning = true
150
142
  curFunc = lMatches[1]
151
143
 
152
144
  if entering && lDebugFuncs && funcMatch(curFunc)
@@ -155,7 +147,7 @@ export debug = (lArgs...) ->
155
147
  if debugging && (not ifMatches? || str.match(ifMatches))
156
148
 
157
149
  # --- set the prefix, i.e. indentation to use
158
- if exiting
150
+ if returning
159
151
  if (debugLevel==0)
160
152
  prefix = arrow
161
153
  else
@@ -166,15 +158,19 @@ export debug = (lArgs...) ->
166
158
  if (nArgs==1)
167
159
  log str, item, {prefix}
168
160
  else
169
- log str, item, {prefix, logItem: true}
161
+ log str, item, {
162
+ prefix,
163
+ logItem: true,
164
+ itemPrefix: stripArrow(prefix),
165
+ }
170
166
 
171
- if exiting && lDebugFuncs && funcMatch(curFunc)
167
+ if returning && lDebugFuncs && funcMatch(curFunc)
172
168
  setDebugging false # revert to previous setting - might still be on
173
169
 
174
170
  if debugging
175
171
  if entering
176
172
  debugLevel += 1
177
- if exiting && (debugLevel > 0)
173
+ if returning && (debugLevel > 0)
178
174
  debugLevel -= 1
179
175
  return
180
176
 
@@ -1,6 +1,6 @@
1
1
  // Generated by CoffeeScript 2.5.1
2
2
  // debug_utils.coffee
3
- var arrow, arrowhead, corner, debugLevel, getPrefix, hbar, ifMatches, indent, lDebugFuncs, lDebugStack, reMethod, restoreDebugEnv, saveDebugEnv, vbar;
3
+ var arrow, arrowhead, corner, debugLevel, getPrefix, hbar, ifMatches, indent, lDebugFuncs, lDebugStack, reMethod, restoreDebugEnv, saveDebugEnv, stripArrow, vbar;
4
4
 
5
5
  import {
6
6
  strict as assert
@@ -48,6 +48,11 @@ ifMatches = undef;
48
48
 
49
49
  lDebugFuncs = undef;
50
50
 
51
+ // ---------------------------------------------------------------------------
52
+ stripArrow = function(prefix) {
53
+ return prefix.replace(arrow, ' ');
54
+ };
55
+
51
56
  // ---------------------------------------------------------------------------
52
57
  export var debugIfLineMatches = function(regexp = undef) {
53
58
  ifMatches = regexp;
@@ -106,21 +111,9 @@ export var resetDebugging = function() {
106
111
  lDebugStack = [];
107
112
  };
108
113
 
109
- // ---------------------------------------------------------------------------
110
- // --- export only to allow unit testing
111
- export var patchDebugStr = function(str) {
112
- var re, replacer;
113
- // --- Match things like "$varname$" to "'#{escapeStr(varname)}'"
114
- re = /\$([A-Za-z_][A-Za-z0-9_]*)\$/g;
115
- replacer = function(match, ident) {
116
- return `'\#\{escapeStr(${ident})\}'`;
117
- };
118
- return str.replace(re, replacer);
119
- };
120
-
121
114
  // ---------------------------------------------------------------------------
122
115
  export var debug = function(...lArgs) {
123
- var curFunc, entering, exiting, item, lMatches, nArgs, prefix, str;
116
+ var curFunc, entering, item, lMatches, nArgs, prefix, returning, str;
124
117
  // --- either 1 or 2 args
125
118
  if (!debugging && (lDebugFuncs == null)) {
126
119
  return;
@@ -135,13 +128,13 @@ export var debug = function(...lArgs) {
135
128
  item = lArgs[1];
136
129
  }
137
130
  // --- determine if we're entering or returning from a function
138
- entering = exiting = false;
131
+ entering = returning = false;
139
132
  curFunc = undef;
140
- if ((lMatches = str.match(/^\s*enter\s+([A-Za-z_][A-Za-z0-9_]*)/))) {
133
+ if ((lMatches = str.match(/^\s*enter\s+([A-Za-z_][A-Za-z0-9_\.]*)/))) {
141
134
  entering = true;
142
135
  curFunc = lMatches[1];
143
- } else if ((lMatches = str.match(/^\s*return.*from\s+([A-Za-z_][A-Za-z0-9_]*)/))) {
144
- exiting = true;
136
+ } else if ((lMatches = str.match(/^\s*return.*from\s+([A-Za-z_][A-Za-z0-9_\.]*)/))) {
137
+ returning = true;
145
138
  curFunc = lMatches[1];
146
139
  }
147
140
  if (entering && lDebugFuncs && funcMatch(curFunc)) {
@@ -149,7 +142,7 @@ export var debug = function(...lArgs) {
149
142
  }
150
143
  if (debugging && ((ifMatches == null) || str.match(ifMatches))) {
151
144
  // --- set the prefix, i.e. indentation to use
152
- if (exiting) {
145
+ if (returning) {
153
146
  if (debugLevel === 0) {
154
147
  prefix = arrow;
155
148
  } else {
@@ -163,18 +156,19 @@ export var debug = function(...lArgs) {
163
156
  } else {
164
157
  log(str, item, {
165
158
  prefix,
166
- logItem: true
159
+ logItem: true,
160
+ itemPrefix: stripArrow(prefix)
167
161
  });
168
162
  }
169
163
  }
170
- if (exiting && lDebugFuncs && funcMatch(curFunc)) {
164
+ if (returning && lDebugFuncs && funcMatch(curFunc)) {
171
165
  setDebugging(false); // revert to previous setting - might still be on
172
166
  }
173
167
  if (debugging) {
174
168
  if (entering) {
175
169
  debugLevel += 1;
176
170
  }
177
- if (exiting && (debugLevel > 0)) {
171
+ if (returning && (debugLevel > 0)) {
178
172
  debugLevel -= 1;
179
173
  }
180
174
  }
@@ -77,10 +77,10 @@ export log = (lArgs...) ->
77
77
  # valid options:
78
78
  # prefix
79
79
  # logItem
80
+ # itemPrefix
80
81
 
81
82
  if (lArgs.length==0)
82
83
  return
83
- prefix = ''
84
84
  str = lArgs[0]
85
85
  switch lArgs.length
86
86
  when 1
@@ -92,11 +92,22 @@ export log = (lArgs...) ->
92
92
  item = lArgs[1] # might not be logged, though
93
93
  hOptions = lArgs[2]
94
94
  assert isHash(hOptions), "log(): 3rd arg must be a hash"
95
- if hOptions.prefix?
96
- prefix = hOptions.prefix
97
95
  if hOptions.logItem?
98
96
  logItem = hOptions.logItem
99
97
 
98
+ if hOptions?
99
+ if hOptions.prefix?
100
+ prefix = hOptions.prefix
101
+ else
102
+ prefix = ''
103
+
104
+ if hOptions.itemPrefix?
105
+ itemPrefix = hOptions.itemPrefix
106
+ else
107
+ itemPrefix = ''
108
+ else
109
+ prefix = itemPrefix = ''
110
+
100
111
  if (not logItem)
101
112
  logger "#{prefix}#{str}"
102
113
  else if not item?
@@ -110,7 +121,7 @@ export log = (lArgs...) ->
110
121
  else
111
122
  logger "#{prefix}#{str}:"
112
123
  for line in stringToArray(item)
113
- logger "#{prefix} #{escapeStr(line)}"
124
+ logger "#{itemPrefix} #{escapeStr(line)}"
114
125
  else
115
126
  # --- It's some type of object
116
127
  json = JSON.stringify(item)
@@ -119,7 +130,7 @@ export log = (lArgs...) ->
119
130
  else
120
131
  logger "#{prefix}#{str}:"
121
132
  for str in stringToArray(stringify(item))
122
- logger "#{prefix} #{str}"
133
+ logger "#{itemPrefix} #{str}"
123
134
  return
124
135
 
125
136
  # ---------------------------------------------------------------------------
package/src/log_utils.js CHANGED
@@ -81,15 +81,15 @@ maxOneLine = 32;
81
81
 
82
82
  // ---------------------------------------------------------------------------
83
83
  export var log = function(...lArgs) {
84
- var esc, hOptions, i, item, j, json, len, len1, line, logItem, prefix, ref, ref1, str;
84
+ var esc, hOptions, i, item, itemPrefix, j, json, len, len1, line, logItem, prefix, ref, ref1, str;
85
85
  // --- (str, item, hOptions)
86
86
  // valid options:
87
87
  // prefix
88
88
  // logItem
89
+ // itemPrefix
89
90
  if (lArgs.length === 0) {
90
91
  return;
91
92
  }
92
- prefix = '';
93
93
  str = lArgs[0];
94
94
  switch (lArgs.length) {
95
95
  case 1:
@@ -103,13 +103,24 @@ export var log = function(...lArgs) {
103
103
  item = lArgs[1];
104
104
  hOptions = lArgs[2];
105
105
  assert(isHash(hOptions), "log(): 3rd arg must be a hash");
106
- if (hOptions.prefix != null) {
107
- prefix = hOptions.prefix;
108
- }
109
106
  if (hOptions.logItem != null) {
110
107
  logItem = hOptions.logItem;
111
108
  }
112
109
  }
110
+ if (hOptions != null) {
111
+ if (hOptions.prefix != null) {
112
+ prefix = hOptions.prefix;
113
+ } else {
114
+ prefix = '';
115
+ }
116
+ if (hOptions.itemPrefix != null) {
117
+ itemPrefix = hOptions.itemPrefix;
118
+ } else {
119
+ itemPrefix = '';
120
+ }
121
+ } else {
122
+ prefix = itemPrefix = '';
123
+ }
113
124
  if (!logItem) {
114
125
  logger(`${prefix}${str}`);
115
126
  } else if (item == null) {
@@ -125,7 +136,7 @@ export var log = function(...lArgs) {
125
136
  ref = stringToArray(item);
126
137
  for (i = 0, len = ref.length; i < len; i++) {
127
138
  line = ref[i];
128
- logger(`${prefix} ${escapeStr(line)}`);
139
+ logger(`${itemPrefix} ${escapeStr(line)}`);
129
140
  }
130
141
  }
131
142
  } else {
@@ -138,7 +149,7 @@ export var log = function(...lArgs) {
138
149
  ref1 = stringToArray(stringify(item));
139
150
  for (j = 0, len1 = ref1.length; j < len1; j++) {
140
151
  str = ref1[j];
141
- logger(`${prefix} ${str}`);
152
+ logger(`${itemPrefix} ${str}`);
142
153
  }
143
154
  }
144
155
  }