@jdeighan/coffee-utils 7.0.52 → 7.0.55

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.52",
4
+ "version": "7.0.55",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
@@ -52,6 +52,6 @@
52
52
  "svelte": "^3.48.0"
53
53
  },
54
54
  "devDependencies": {
55
- "@jdeighan/unit-tester": "^2.0.5"
55
+ "@jdeighan/unit-tester": "^2.0.6"
56
56
  }
57
57
  }
@@ -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()
@@ -73,16 +73,18 @@ export debug = (label, lObjects...) ->
73
73
  switch type
74
74
  when 'enter'
75
75
  log label, {prefix}
76
+ prefix = removeLastVbar(prefix)
76
77
  for obj,i in lObjects
77
78
  if (i > 0)
78
- log sep_dash, {prefix: removeLastVbar(prefix)}
79
- logItem undef, obj, {prefix: removeLastVbar(prefix)}
79
+ log dashes(prefix)
80
+ logItem undef, obj, {prefix}
80
81
  when 'return'
81
82
  log label, {prefix: addArrow(prefix)}
83
+ prefix = removeLastVbar(prefix)
82
84
  for obj,i in lObjects
83
85
  if (i > 0)
84
- log sep_dash, {prefix: removeLastVbar(prefix)}
85
- logItem undef, obj, {prefix: removeLastVbar(prefix)}
86
+ log dashes(prefix)
87
+ logItem undef, obj, {prefix}
86
88
  when 'string'
87
89
  log label, {prefix}
88
90
  when 'objects'
@@ -95,7 +97,7 @@ export debug = (label, lObjects...) ->
95
97
  for obj in lObjects
96
98
  logItem undef, obj, {prefix}
97
99
 
98
- if (type == 'enter') && doLog
100
+ if (type == 'enter') && doLog && (label.indexOf('call') == -1)
99
101
  callStack.logCurFunc()
100
102
  else if (type == 'return')
101
103
  callStack.returnFrom funcName
@@ -119,20 +121,25 @@ export stdShouldLog = (label, type, funcName, stack) ->
119
121
  else
120
122
  assert funcName == undef, "func name #{OL(funcName)} not undef"
121
123
  assert stack instanceof CallStack, "not a call stack object"
124
+
122
125
  if doDebugDebug
123
126
  LOG "stdShouldLog(#{OL(label)}, #{OL(type)}, #{OL(funcName)}, stack)"
124
127
  LOG "stack", stack
125
128
  LOG "lFuncList", lFuncList
129
+
126
130
  switch type
127
131
  when 'enter'
128
132
  if funcMatch(stack, lFuncList)
129
133
  return label
130
134
 
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')
135
+ else
136
+ # --- As a special case, if we enter a function where we will not
137
+ # be logging, but we were logging in the calling function,
138
+ # we'll log out the call itself
139
+
140
+ prevLogged = stack.isLoggingPrev()
141
+ if prevLogged
142
+ return label.replace('enter', 'call')
136
143
  else
137
144
  if funcMatch(stack, lFuncList)
138
145
  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();
@@ -107,32 +107,26 @@ export var debug = function(label, ...lObjects) {
107
107
  switch (type) {
108
108
  case 'enter':
109
109
  log(label, {prefix});
110
+ prefix = removeLastVbar(prefix);
110
111
  for (i = j = 0, len1 = lObjects.length; j < len1; i = ++j) {
111
112
  obj = lObjects[i];
112
113
  if (i > 0) {
113
- log(sep_dash, {
114
- prefix: removeLastVbar(prefix)
115
- });
114
+ log(dashes(prefix));
116
115
  }
117
- logItem(undef, obj, {
118
- prefix: removeLastVbar(prefix)
119
- });
116
+ logItem(undef, obj, {prefix});
120
117
  }
121
118
  break;
122
119
  case 'return':
123
120
  log(label, {
124
121
  prefix: addArrow(prefix)
125
122
  });
123
+ prefix = removeLastVbar(prefix);
126
124
  for (i = k = 0, len2 = lObjects.length; k < len2; i = ++k) {
127
125
  obj = lObjects[i];
128
126
  if (i > 0) {
129
- log(sep_dash, {
130
- prefix: removeLastVbar(prefix)
131
- });
127
+ log(dashes(prefix));
132
128
  }
133
- logItem(undef, obj, {
134
- prefix: removeLastVbar(prefix)
135
- });
129
+ logItem(undef, obj, {prefix});
136
130
  }
137
131
  break;
138
132
  case 'string':
@@ -153,7 +147,7 @@ export var debug = function(label, ...lObjects) {
153
147
  }
154
148
  }
155
149
  }
156
- if ((type === 'enter') && doLog) {
150
+ if ((type === 'enter') && doLog && (label.indexOf('call') === -1)) {
157
151
  callStack.logCurFunc();
158
152
  } else if (type === 'return') {
159
153
  callStack.returnFrom(funcName);
@@ -164,6 +158,7 @@ export var debug = function(label, ...lObjects) {
164
158
 
165
159
  // ---------------------------------------------------------------------------
166
160
  export var stdShouldLog = function(label, type, funcName, stack) {
161
+ var prevLogged;
167
162
  // --- if type is 'enter', then funcName won't be on the stack yet
168
163
  // returns the (possibly modified) label to log
169
164
 
@@ -187,11 +182,14 @@ export var stdShouldLog = function(label, type, funcName, stack) {
187
182
  case 'enter':
188
183
  if (funcMatch(stack, lFuncList)) {
189
184
  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');
185
+ } else {
186
+ // --- As a special case, if we enter a function where we will not
187
+ // be logging, but we were logging in the calling function,
188
+ // we'll log out the call itself
189
+ prevLogged = stack.isLoggingPrev();
190
+ if (prevLogged) {
191
+ return label.replace('enter', 'call');
192
+ }
195
193
  }
196
194
  break;
197
195
  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;