@jdeighan/coffee-utils 7.0.49 → 7.0.50

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.49",
4
+ "version": "7.0.50",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
@@ -1,6 +1,8 @@
1
1
  # call_stack.coffee
2
2
 
3
- import {undef, croak, assert} from '@jdeighan/coffee-utils'
3
+ import {
4
+ undef, defined, croak, assert, isBoolean,
5
+ } from '@jdeighan/coffee-utils'
4
6
  import {log, LOG} from '@jdeighan/coffee-utils/log'
5
7
  import {getPrefix} from '@jdeighan/coffee-utils/arrow'
6
8
 
@@ -64,9 +66,9 @@ export class CallStack
64
66
  # ........................................................................
65
67
  # ........................................................................
66
68
 
67
- call: (funcName, hInfo, isLogged=undef) ->
69
+ doCall: (funcName, hInfo, isLogged) ->
68
70
 
69
- assert isLogged != undef, "CallStack.call(): 3 args required"
71
+ assert isBoolean(isLogged), "CallStack.call(): 3 args required"
70
72
  mainPre = getPrefix(@level)
71
73
 
72
74
  if doDebugStack
@@ -75,7 +77,7 @@ export class CallStack
75
77
 
76
78
  @addCall funcName, hInfo, isLogged
77
79
  auxPre = getPrefix(@level)
78
- return [mainPre, auxPre, undef]
80
+ return [mainPre, auxPre]
79
81
 
80
82
  # ........................................................................
81
83
 
package/src/call_stack.js CHANGED
@@ -4,8 +4,10 @@ var doDebugStack;
4
4
 
5
5
  import {
6
6
  undef,
7
+ defined,
7
8
  croak,
8
- assert
9
+ assert,
10
+ isBoolean
9
11
  } from '@jdeighan/coffee-utils';
10
12
 
11
13
  import {
@@ -72,9 +74,9 @@ export var CallStack = class CallStack {
72
74
 
73
75
  // ........................................................................
74
76
  // ........................................................................
75
- call(funcName, hInfo, isLogged = undef) {
77
+ doCall(funcName, hInfo, isLogged) {
76
78
  var auxPre, mainPre, prefix;
77
- assert(isLogged !== undef, "CallStack.call(): 3 args required");
79
+ assert(isBoolean(isLogged), "CallStack.call(): 3 args required");
78
80
  mainPre = getPrefix(this.level);
79
81
  if (doDebugStack) {
80
82
  prefix = ' '.repeat(this.lStack.length);
@@ -82,7 +84,7 @@ export var CallStack = class CallStack {
82
84
  }
83
85
  this.addCall(funcName, hInfo, isLogged);
84
86
  auxPre = getPrefix(this.level);
85
- return [mainPre, auxPre, undef];
87
+ return [mainPre, auxPre];
86
88
  }
87
89
 
88
90
  // ........................................................................
@@ -1,7 +1,8 @@
1
1
  # debug_utils.coffee
2
2
 
3
3
  import {
4
- assert, undef, error, croak, warn, isString, isFunction, isBoolean,
4
+ assert, undef, error, croak, warn, defined,
5
+ isString, isFunction, isBoolean,
5
6
  OL, escapeStr, isNumber, isArray, words, pass,
6
7
  } from '@jdeighan/coffee-utils'
7
8
  import {blockToArray} from '@jdeighan/coffee-utils/block'
@@ -14,8 +15,8 @@ import {
14
15
 
15
16
  # --- These are saved/restored on the call stack
16
17
  export debugging = false
17
- shouldLogFunc = (func) -> debugging
18
- shouldLogString = (str) -> debugging
18
+ shouldLogFunc = (func) -> return debugging
19
+ shouldLogString = (str) -> return debugging
19
20
 
20
21
  stack = new CallStack()
21
22
  doDebugDebug = false
@@ -37,8 +38,8 @@ resetDebugging = () ->
37
38
  if doDebugDebug
38
39
  LOG "resetDebugging() - debugging = false"
39
40
  stack.reset()
40
- shouldLogFunc = (func) -> debugging
41
- shouldLogString = (str) -> debugging
41
+ shouldLogFunc = (func) -> return debugging
42
+ shouldLogString = (str) -> return debugging
42
43
  return
43
44
 
44
45
  # ---------------------------------------------------------------------------
@@ -65,7 +66,7 @@ export setDebugging = (funcDoDebug=undef, funcDoLog=undef) ->
65
66
  else
66
67
  croak "setDebugging(): bad parameter #{OL(funcDoDebug)}"
67
68
 
68
- if funcDoLog
69
+ if isFunction(funcDoLog)
69
70
  assert isFunction(funcDoLog), "setDebugging: arg 2 not a function"
70
71
  shouldLogString = funcDoLog
71
72
  return
@@ -89,8 +90,8 @@ export funcMatch = (curFunc, lFuncNames) ->
89
90
  # ---------------------------------------------------------------------------
90
91
  # 1. adjust call stack on 'enter' or 'return from'
91
92
  # 2. adjust debugging flag
92
- # 3. return [mainPrefix, auxPrefix, hEnv] - hEnv can be undef
93
- # 4. disable logging by setting mainPrefix to undef
93
+ # 3. return [mainPrefix, auxPrefix, hEnv, type] - hEnv can be undef
94
+ # 4. disable logging by setting type to undef
94
95
 
95
96
  adjustStack = (str) ->
96
97
 
@@ -100,17 +101,21 @@ adjustStack = (str) ->
100
101
  \s+
101
102
  ([A-Za-z_][A-Za-z0-9_\.]*)
102
103
  ///))
104
+
105
+ # --- We are entering function curFunc
103
106
  curFunc = lMatches[1]
107
+
104
108
  hEnv = {
105
109
  debugging
106
110
  shouldLogFunc
107
111
  shouldLogString
108
112
  }
113
+
109
114
  debugging = shouldLogFunc(curFunc)
110
115
  if doDebugDebug
111
116
  trans = "#{hEnv.debugging} => #{debugging}"
112
117
  LOG " ENTER #{curFunc}, debugging: #{trans}"
113
- [mainPre, auxPre, _] = stack.call(curFunc, hEnv, debugging)
118
+ [mainPre, auxPre] = stack.doCall(curFunc, hEnv, debugging)
114
119
  return [
115
120
  mainPre
116
121
  auxPre
@@ -152,6 +157,9 @@ export debug = (lArgs...) ->
152
157
  # distinguish between 1 arg sent vs. 2 args sent
153
158
  nArgs = lArgs.length
154
159
  assert (nArgs==1) || (nArgs==2), "debug(): #{nArgs} args"
160
+
161
+ # --- label must always be there, and be a string
162
+ # item is optional
155
163
  [label, item] = lArgs
156
164
  assert isString(label),
157
165
  "debug(): 1st arg #{OL(label)} should be a string"
@@ -8,6 +8,7 @@ import {
8
8
  error,
9
9
  croak,
10
10
  warn,
11
+ defined,
11
12
  isString,
12
13
  isFunction,
13
14
  isBoolean,
@@ -108,7 +109,7 @@ export var setDebugging = function(funcDoDebug = undef, funcDoLog = undef) {
108
109
  } else {
109
110
  croak(`setDebugging(): bad parameter ${OL(funcDoDebug)}`);
110
111
  }
111
- if (funcDoLog) {
112
+ if (isFunction(funcDoLog)) {
112
113
  assert(isFunction(funcDoLog), "setDebugging: arg 2 not a function");
113
114
  shouldLogString = funcDoLog;
114
115
  }
@@ -132,11 +133,12 @@ export var funcMatch = function(curFunc, lFuncNames) {
132
133
  // ---------------------------------------------------------------------------
133
134
  // 1. adjust call stack on 'enter' or 'return from'
134
135
  // 2. adjust debugging flag
135
- // 3. return [mainPrefix, auxPrefix, hEnv] - hEnv can be undef
136
- // 4. disable logging by setting mainPrefix to undef
136
+ // 3. return [mainPrefix, auxPrefix, hEnv, type] - hEnv can be undef
137
+ // 4. disable logging by setting type to undef
137
138
  adjustStack = function(str) {
138
139
  var _, auxPre, curFunc, hEnv, lMatches, mainPre, trans;
139
140
  if ((lMatches = str.match(/^\s*enter\s+([A-Za-z_][A-Za-z0-9_\.]*)/))) {
141
+ // --- We are entering function curFunc
140
142
  curFunc = lMatches[1];
141
143
  hEnv = {debugging, shouldLogFunc, shouldLogString};
142
144
  debugging = shouldLogFunc(curFunc);
@@ -144,7 +146,7 @@ adjustStack = function(str) {
144
146
  trans = `${hEnv.debugging} => ${debugging}`;
145
147
  LOG(` ENTER ${curFunc}, debugging: ${trans}`);
146
148
  }
147
- [mainPre, auxPre, _] = stack.call(curFunc, hEnv, debugging);
149
+ [mainPre, auxPre] = stack.doCall(curFunc, hEnv, debugging);
148
150
  return [mainPre, auxPre, undef, shouldLogFunc(curFunc) ? 'enter' : undef];
149
151
  } else if ((lMatches = str.match(/^\s*return.+from\s+([A-Za-z_][A-Za-z0-9_\.]*)/))) {
150
152
  curFunc = lMatches[1];
@@ -166,6 +168,8 @@ export var debug = function(...lArgs) {
166
168
  // distinguish between 1 arg sent vs. 2 args sent
167
169
  nArgs = lArgs.length;
168
170
  assert((nArgs === 1) || (nArgs === 2), `debug(): ${nArgs} args`);
171
+ // --- label must always be there, and be a string
172
+ // item is optional
169
173
  [label, item] = lArgs;
170
174
  assert(isString(label), `debug(): 1st arg ${OL(label)} should be a string`);
171
175
  if (doDebugDebug) {