@jdeighan/coffee-utils 7.0.53 → 7.0.56

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.53",
4
+ "version": "7.0.56",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
@@ -160,5 +160,5 @@ export class CallStack
160
160
  LOG " <EMPTY>"
161
161
  else
162
162
  for item, i in @lStack
163
- LOG " #{i}: #{JSON.stringify(item)}"
163
+ LOG " #{i}: #{item.fullName} #{item.isLogged}"
164
164
  return
package/src/call_stack.js CHANGED
@@ -168,7 +168,7 @@ export var CallStack = class CallStack {
168
168
  ref = this.lStack;
169
169
  for (i = j = 0, len = ref.length; j < len; i = ++j) {
170
170
  item = ref[i];
171
- LOG(` ${i}: ${JSON.stringify(item)}`);
171
+ LOG(` ${i}: ${item.fullName} ${item.isLogged}`);
172
172
  }
173
173
  }
174
174
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
  import {
4
4
  assert, undef, error, croak, warn, defined,
5
- isString, isFunction, isBoolean, sep_dash,
5
+ isString, isFunction, isBoolean,
6
6
  OL, escapeStr, isNumber, isArray, words, pass,
7
7
  } from '@jdeighan/coffee-utils'
8
8
  import {blockToArray} from '@jdeighan/coffee-utils/block'
@@ -13,7 +13,7 @@ import {
13
13
  getPrefix, addArrow, removeLastVbar,
14
14
  } from '@jdeighan/coffee-utils/arrow'
15
15
  import {
16
- log, logItem, LOG, shortEnough,
16
+ log, logItem, LOG, shortEnough, dashes,
17
17
  } from '@jdeighan/coffee-utils/log'
18
18
 
19
19
  callStack = new CallStack()
@@ -38,6 +38,9 @@ export debug = (label, lObjects...) ->
38
38
  LOG "debug(): type = #{OL(type)}"
39
39
  LOG "debug(): funcName = #{OL(funcName)}"
40
40
 
41
+ # --- function shouldLog() returns the (possibly modified) label
42
+ # if we should log this, else it returns undef
43
+
41
44
  switch type
42
45
  when 'enter'
43
46
  callStack.enter funcName
@@ -64,25 +67,27 @@ export debug = (label, lObjects...) ->
64
67
  if doLog
65
68
  level = callStack.getLevel()
66
69
  prefix = getPrefix(level)
70
+ itemPrefix = removeLastVbar(prefix)
67
71
 
68
72
  if doDebugDebug
69
73
  LOG "callStack", callStack
70
74
  LOG "level = #{OL(level)}"
71
75
  LOG "prefix = #{OL(prefix)}"
76
+ LOG "itemPrefix = #{OL(itemPrefix)}"
72
77
 
73
78
  switch type
74
79
  when 'enter'
75
80
  log label, {prefix}
76
81
  for obj,i in lObjects
77
82
  if (i > 0)
78
- log sep_dash, {prefix: removeLastVbar(prefix)}
79
- logItem undef, obj, {prefix: removeLastVbar(prefix)}
83
+ log dashes(itemPrefix, 40)
84
+ logItem undef, obj, {itemPrefix}
80
85
  when 'return'
81
86
  log label, {prefix: addArrow(prefix)}
82
87
  for obj,i in lObjects
83
88
  if (i > 0)
84
- log sep_dash, {prefix: removeLastVbar(prefix)}
85
- logItem undef, obj, {prefix: removeLastVbar(prefix)}
89
+ log dashes(itemPrefix, 40)
90
+ logItem undef, obj, {itemPrefix}
86
91
  when 'string'
87
92
  log label, {prefix}
88
93
  when 'objects'
@@ -95,7 +100,7 @@ export debug = (label, lObjects...) ->
95
100
  for obj in lObjects
96
101
  logItem undef, obj, {prefix}
97
102
 
98
- if (type == 'enter') && doLog
103
+ if (type == 'enter') && doLog && (label.indexOf('call') == -1)
99
104
  callStack.logCurFunc()
100
105
  else if (type == 'return')
101
106
  callStack.returnFrom funcName
@@ -119,20 +124,25 @@ export stdShouldLog = (label, type, funcName, stack) ->
119
124
  else
120
125
  assert funcName == undef, "func name #{OL(funcName)} not undef"
121
126
  assert stack instanceof CallStack, "not a call stack object"
127
+
122
128
  if doDebugDebug
123
129
  LOG "stdShouldLog(#{OL(label)}, #{OL(type)}, #{OL(funcName)}, stack)"
124
130
  LOG "stack", stack
125
131
  LOG "lFuncList", lFuncList
132
+
126
133
  switch type
127
134
  when 'enter'
128
135
  if funcMatch(stack, lFuncList)
129
136
  return label
130
137
 
131
- # --- As a special case, if we enter a function where we will not
132
- # be logging, but we were logging in the calling function,
133
- # we'll log out the call itself
134
- else if stack.isLoggingPrev()
135
- return label.replace('enter', 'call')
138
+ else
139
+ # --- As a special case, if we enter a function where we will not
140
+ # be logging, but we were logging in the calling function,
141
+ # we'll log out the call itself
142
+
143
+ prevLogged = stack.isLoggingPrev()
144
+ if prevLogged
145
+ return label.replace('enter', 'call')
136
146
  else
137
147
  if funcMatch(stack, lFuncList)
138
148
  return label
@@ -12,7 +12,6 @@ import {
12
12
  isString,
13
13
  isFunction,
14
14
  isBoolean,
15
- sep_dash,
16
15
  OL,
17
16
  escapeStr,
18
17
  isNumber,
@@ -47,7 +46,8 @@ import {
47
46
  log,
48
47
  logItem,
49
48
  LOG,
50
- shortEnough
49
+ shortEnough,
50
+ dashes
51
51
  } from '@jdeighan/coffee-utils/log';
52
52
 
53
53
  callStack = new CallStack();
@@ -60,7 +60,7 @@ export var lFuncList = [];
60
60
 
61
61
  // ---------------------------------------------------------------------------
62
62
  export var debug = function(label, ...lObjects) {
63
- var doLog, funcName, i, j, k, l, len1, len2, len3, level, nObjects, obj, prefix, type;
63
+ var doLog, funcName, i, itemPrefix, j, k, l, len1, len2, len3, level, nObjects, obj, prefix, type;
64
64
  assert(isString(label), `1st arg ${OL(label)} should be a string`);
65
65
  // --- We want to allow objects to be undef. Therefore, we need to
66
66
  // distinguish between 1 arg sent vs. 2 or more args sent
@@ -71,6 +71,8 @@ export var debug = function(label, ...lObjects) {
71
71
  LOG(`debug(): type = ${OL(type)}`);
72
72
  LOG(`debug(): funcName = ${OL(funcName)}`);
73
73
  }
74
+ // --- function shouldLog() returns the (possibly modified) label
75
+ // if we should log this, else it returns undef
74
76
  switch (type) {
75
77
  case 'enter':
76
78
  callStack.enter(funcName);
@@ -99,10 +101,12 @@ export var debug = function(label, ...lObjects) {
99
101
  if (doLog) {
100
102
  level = callStack.getLevel();
101
103
  prefix = getPrefix(level);
104
+ itemPrefix = removeLastVbar(prefix);
102
105
  if (doDebugDebug) {
103
106
  LOG("callStack", callStack);
104
107
  LOG(`level = ${OL(level)}`);
105
108
  LOG(`prefix = ${OL(prefix)}`);
109
+ LOG(`itemPrefix = ${OL(itemPrefix)}`);
106
110
  }
107
111
  switch (type) {
108
112
  case 'enter':
@@ -110,13 +114,9 @@ export var debug = function(label, ...lObjects) {
110
114
  for (i = j = 0, len1 = lObjects.length; j < len1; i = ++j) {
111
115
  obj = lObjects[i];
112
116
  if (i > 0) {
113
- log(sep_dash, {
114
- prefix: removeLastVbar(prefix)
115
- });
117
+ log(dashes(itemPrefix, 40));
116
118
  }
117
- logItem(undef, obj, {
118
- prefix: removeLastVbar(prefix)
119
- });
119
+ logItem(undef, obj, {itemPrefix});
120
120
  }
121
121
  break;
122
122
  case 'return':
@@ -126,13 +126,9 @@ export var debug = function(label, ...lObjects) {
126
126
  for (i = k = 0, len2 = lObjects.length; k < len2; i = ++k) {
127
127
  obj = lObjects[i];
128
128
  if (i > 0) {
129
- log(sep_dash, {
130
- prefix: removeLastVbar(prefix)
131
- });
129
+ log(dashes(itemPrefix, 40));
132
130
  }
133
- logItem(undef, obj, {
134
- prefix: removeLastVbar(prefix)
135
- });
131
+ logItem(undef, obj, {itemPrefix});
136
132
  }
137
133
  break;
138
134
  case 'string':
@@ -153,7 +149,7 @@ export var debug = function(label, ...lObjects) {
153
149
  }
154
150
  }
155
151
  }
156
- if ((type === 'enter') && doLog) {
152
+ if ((type === 'enter') && doLog && (label.indexOf('call') === -1)) {
157
153
  callStack.logCurFunc();
158
154
  } else if (type === 'return') {
159
155
  callStack.returnFrom(funcName);
@@ -164,6 +160,7 @@ export var debug = function(label, ...lObjects) {
164
160
 
165
161
  // ---------------------------------------------------------------------------
166
162
  export var stdShouldLog = function(label, type, funcName, stack) {
163
+ var prevLogged;
167
164
  // --- if type is 'enter', then funcName won't be on the stack yet
168
165
  // returns the (possibly modified) label to log
169
166
 
@@ -187,11 +184,14 @@ export var stdShouldLog = function(label, type, funcName, stack) {
187
184
  case 'enter':
188
185
  if (funcMatch(stack, lFuncList)) {
189
186
  return label;
190
- // --- As a special case, if we enter a function where we will not
191
- // be logging, but we were logging in the calling function,
192
- // we'll log out the call itself
193
- } else if (stack.isLoggingPrev()) {
194
- return label.replace('enter', 'call');
187
+ } else {
188
+ // --- As a special case, if we enter a function where we will not
189
+ // be logging, but we were logging in the calling function,
190
+ // we'll log out the call itself
191
+ prevLogged = stack.isLoggingPrev();
192
+ if (prevLogged) {
193
+ return label.replace('enter', 'call');
194
+ }
195
195
  }
196
196
  break;
197
197
  default:
@@ -20,6 +20,12 @@ fourSpaces = ' '
20
20
 
21
21
  # ---------------------------------------------------------------------------
22
22
 
23
+ export dashes = (prefix, totalLen=64, ch='-') ->
24
+
25
+ return prefix + ch.repeat(totalLen - prefix.length)
26
+
27
+ # ---------------------------------------------------------------------------
28
+
23
29
  export debugLog = (flag=true) ->
24
30
 
25
31
  doDebugLog = flag
package/src/log_utils.js CHANGED
@@ -39,6 +39,11 @@ export var stringify = undef;
39
39
 
40
40
  fourSpaces = ' ';
41
41
 
42
+ // ---------------------------------------------------------------------------
43
+ export var dashes = function(prefix, totalLen = 64, ch = '-') {
44
+ return prefix + ch.repeat(totalLen - prefix.length);
45
+ };
46
+
42
47
  // ---------------------------------------------------------------------------
43
48
  export var debugLog = function(flag = true) {
44
49
  doDebugLog = flag;