@jdeighan/coffee-utils 4.1.0 → 4.1.4

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": "4.1.0",
4
+ "version": "4.1.4",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
@@ -42,6 +42,7 @@
42
42
  "dependencies": {
43
43
  "ava": "^3.15.0",
44
44
  "cross-env": "^7.0.3",
45
- "js-yaml": "^4.1.0"
45
+ "js-yaml": "^4.1.0",
46
+ "readline-sync": "^1.4.10"
46
47
  }
47
48
  }
@@ -14,9 +14,9 @@ import {debug, debugging, setDebugging} from '@jdeighan/coffee-utils/debug'
14
14
 
15
15
  export class UnitTester
16
16
 
17
- constructor: (whichTest='deepEqual', @fulltest=false) ->
17
+ constructor: (@file='unknown file') ->
18
18
  @hFound = {}
19
- @setWhichTest whichTest
19
+ @whichTest = 'deepEqual'
20
20
  @justshow = false
21
21
  @testing = true
22
22
  @maxLineNum = undef
@@ -180,7 +180,7 @@ export class UnitTester
180
180
  @lineNum = lineNum # set an object property
181
181
 
182
182
  if (lineNum < 0) && process.env.FINALTEST
183
- error "Negative line numbers not allowed in FINALTEST"
183
+ error "Negative line numbers not allowed in FINALTEST in #{@file}"
184
184
 
185
185
  if ! @testing || (@maxLineNum && (lineNum > @maxLineNum))
186
186
  return
@@ -242,9 +242,6 @@ export class UnitTester
242
242
 
243
243
  getLineNum: (lineNum) ->
244
244
 
245
- if @fulltest && (lineNum < 0)
246
- error "UnitTester(): negative line number during full test!!!"
247
-
248
245
  # --- patch lineNum to avoid duplicates
249
246
  while @hFound[lineNum]
250
247
  if lineNum < 0
package/src/UnitTester.js CHANGED
@@ -32,10 +32,10 @@ import {
32
32
 
33
33
  // ---------------------------------------------------------------------------
34
34
  export var UnitTester = class UnitTester {
35
- constructor(whichTest = 'deepEqual', fulltest = false) {
36
- this.fulltest = fulltest;
35
+ constructor(file = 'unknown file') {
36
+ this.file = file;
37
37
  this.hFound = {};
38
- this.setWhichTest(whichTest);
38
+ this.whichTest = 'deepEqual';
39
39
  this.justshow = false;
40
40
  this.testing = true;
41
41
  this.maxLineNum = undef;
@@ -189,7 +189,7 @@ export var UnitTester = class UnitTester {
189
189
  this.initialize();
190
190
  this.lineNum = lineNum; // set an object property
191
191
  if ((lineNum < 0) && process.env.FINALTEST) {
192
- error("Negative line numbers not allowed in FINALTEST");
192
+ error(`Negative line numbers not allowed in FINALTEST in ${this.file}`);
193
193
  }
194
194
  if (!this.testing || (this.maxLineNum && (lineNum > this.maxLineNum))) {
195
195
  return;
@@ -256,9 +256,6 @@ export var UnitTester = class UnitTester {
256
256
 
257
257
  // ........................................................................
258
258
  getLineNum(lineNum) {
259
- if (this.fulltest && (lineNum < 0)) {
260
- error("UnitTester(): negative line number during full test!!!");
261
- }
262
259
  // --- patch lineNum to avoid duplicates
263
260
  while (this.hFound[lineNum]) {
264
261
  if (lineNum < 0) {
@@ -1,5 +1,6 @@
1
1
  # coffee_utils.coffee
2
2
 
3
+ import getline from 'readline-sync'
3
4
  import {log} from '@jdeighan/coffee-utils/log'
4
5
 
5
6
  export sep_dash = '-'.repeat(42)
@@ -212,9 +213,9 @@ export warn = (message) ->
212
213
  # say - print to the console (for now)
213
214
  # later, on a web page, call alert(str)
214
215
 
215
- export say = (str, obj=undef) ->
216
+ export say = (str) ->
216
217
 
217
- log str, obj
218
+ console.log str
218
219
  return
219
220
 
220
221
  # ---------------------------------------------------------------------------
@@ -223,7 +224,8 @@ export say = (str, obj=undef) ->
223
224
 
224
225
  export ask = (prompt) ->
225
226
 
226
- return 'yes'
227
+ answer = getline.question("{prompt}? ")
228
+ return answer
227
229
 
228
230
  # ---------------------------------------------------------------------------
229
231
 
@@ -2,6 +2,8 @@
2
2
  // coffee_utils.coffee
3
3
  var commentRegExp;
4
4
 
5
+ import getline from 'readline-sync';
6
+
5
7
  import {
6
8
  log
7
9
  } from '@jdeighan/coffee-utils/log';
@@ -217,15 +219,17 @@ export var warn = function(message) {
217
219
  // ---------------------------------------------------------------------------
218
220
  // say - print to the console (for now)
219
221
  // later, on a web page, call alert(str)
220
- export var say = function(str, obj = undef) {
221
- log(str, obj);
222
+ export var say = function(str) {
223
+ console.log(str);
222
224
  };
223
225
 
224
226
  // ---------------------------------------------------------------------------
225
227
  // ask - ask a question
226
228
  // later, on a web page, prompt the user for answer to question
227
229
  export var ask = function(prompt) {
228
- return 'yes';
230
+ var answer;
231
+ answer = getline.question("{prompt}? ");
232
+ return answer;
229
233
  };
230
234
 
231
235
  // ---------------------------------------------------------------------------
@@ -23,7 +23,7 @@ lDebugStack = []
23
23
  # --- These are saved/restored in lDebugStack
24
24
  export debugging = false
25
25
  ifMatches = undef
26
- lDebugFuncs = undef
26
+ lDebugFuncs = undef # --- names of functions to debug
27
27
 
28
28
  stdLogger = false
29
29
 
@@ -51,7 +51,7 @@ export var debugging = false;
51
51
 
52
52
  ifMatches = undef;
53
53
 
54
- lDebugFuncs = undef;
54
+ lDebugFuncs = undef; // --- names of functions to debug
55
55
 
56
56
  stdLogger = false;
57
57
 
@@ -25,7 +25,6 @@ export setLogger = (func) ->
25
25
  return orgLogger
26
26
 
27
27
  # ---------------------------------------------------------------------------
28
- # the default stringifier
29
28
 
30
29
  export tamlStringify = (obj) ->
31
30
 
@@ -39,9 +38,24 @@ export tamlStringify = (obj) ->
39
38
  str = str.replace(/\t/g, ' ') # fr***ing Windows Terminal
40
39
  return str
41
40
 
41
+ # ---------------------------------------------------------------------------
42
+ # the default stringifier
43
+
44
+ export orderedStringify = (obj) ->
45
+
46
+ str = yaml.dump(obj, {
47
+ skipInvalid: true
48
+ indent: 1
49
+ sortKeys: true
50
+ lineWidth: -1
51
+ })
52
+ str = "---\n" + tabify(str)
53
+ str = str.replace(/\t/g, ' ') # fr***ing Windows Terminal
54
+ return str
55
+
42
56
  # ---------------------------------------------------------------------------
43
57
 
44
- export stringify = tamlStringify # for non-strings
58
+ export stringify = orderedStringify # for non-strings
45
59
 
46
60
  # ---------------------------------------------------------------------------
47
61
 
@@ -51,7 +65,7 @@ export setStringifier = (func) ->
51
65
  assert isFunction(func), "setStringifier() not a function"
52
66
  stringify = func
53
67
  else
54
- stringify = tamlStringify
68
+ stringify = orderedStringify
55
69
  return
56
70
 
57
71
  # ---------------------------------------------------------------------------
@@ -75,8 +89,8 @@ maxOneLine = 32
75
89
  export log = (lArgs...) ->
76
90
  # --- (str, item, hOptions)
77
91
  # valid options:
78
- # prefix
79
92
  # logItem
93
+ # prefix
80
94
  # itemPrefix
81
95
 
82
96
  if (lArgs.length==0)
package/src/log_utils.js CHANGED
@@ -41,7 +41,6 @@ export var setLogger = function(func) {
41
41
  };
42
42
 
43
43
  // ---------------------------------------------------------------------------
44
- // the default stringifier
45
44
  export var tamlStringify = function(obj) {
46
45
  var str;
47
46
  str = yaml.dump(obj, {
@@ -56,7 +55,22 @@ export var tamlStringify = function(obj) {
56
55
  };
57
56
 
58
57
  // ---------------------------------------------------------------------------
59
- export var stringify = tamlStringify; // for non-strings
58
+ // the default stringifier
59
+ export var orderedStringify = function(obj) {
60
+ var str;
61
+ str = yaml.dump(obj, {
62
+ skipInvalid: true,
63
+ indent: 1,
64
+ sortKeys: true,
65
+ lineWidth: -1
66
+ });
67
+ str = "---\n" + tabify(str);
68
+ str = str.replace(/\t/g, ' '); // fr***ing Windows Terminal
69
+ return str;
70
+ };
71
+
72
+ // ---------------------------------------------------------------------------
73
+ export var stringify = orderedStringify; // for non-strings
60
74
 
61
75
 
62
76
  // ---------------------------------------------------------------------------
@@ -65,7 +79,7 @@ export var setStringifier = function(func) {
65
79
  assert(isFunction(func), "setStringifier() not a function");
66
80
  stringify = func;
67
81
  } else {
68
- stringify = tamlStringify;
82
+ stringify = orderedStringify;
69
83
  }
70
84
  };
71
85
 
@@ -87,8 +101,8 @@ export var log = function(...lArgs) {
87
101
  var esc, hOptions, i, item, itemPrefix, j, json, len, len1, line, logItem, prefix, ref, ref1, str;
88
102
  // --- (str, item, hOptions)
89
103
  // valid options:
90
- // prefix
91
104
  // logItem
105
+ // prefix
92
106
  // itemPrefix
93
107
  if (lArgs.length === 0) {
94
108
  return;