@jdeighan/coffee-utils 4.1.2 → 4.1.6
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +3 -2
- package/src/UnitTester.coffee +3 -6
- package/src/UnitTester.js +4 -7
- package/src/coffee_utils.coffee +21 -3
- package/src/coffee_utils.js +22 -3
- package/src/debug_utils.coffee +1 -1
- package/src/debug_utils.js +1 -1
- package/temp.js +16 -0
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@jdeighan/coffee-utils",
|
3
3
|
"type": "module",
|
4
|
-
"version": "4.1.
|
4
|
+
"version": "4.1.6",
|
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
|
}
|
package/src/UnitTester.coffee
CHANGED
@@ -14,9 +14,9 @@ import {debug, debugging, setDebugging} from '@jdeighan/coffee-utils/debug'
|
|
14
14
|
|
15
15
|
export class UnitTester
|
16
16
|
|
17
|
-
constructor: (
|
17
|
+
constructor: (@file='unknown file') ->
|
18
18
|
@hFound = {}
|
19
|
-
@
|
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(
|
36
|
-
this.
|
35
|
+
constructor(file = 'unknown file') {
|
36
|
+
this.file = file;
|
37
37
|
this.hFound = {};
|
38
|
-
this.
|
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(
|
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) {
|
package/src/coffee_utils.coffee
CHANGED
@@ -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)
|
@@ -201,6 +202,12 @@ export isInteger = (x) ->
|
|
201
202
|
else
|
202
203
|
return false
|
203
204
|
|
205
|
+
# ---------------------------------------------------------------------------
|
206
|
+
|
207
|
+
export uniq = (lItems) ->
|
208
|
+
|
209
|
+
return [...new Set(lItems)]
|
210
|
+
|
204
211
|
# ---------------------------------------------------------------------------
|
205
212
|
# warn - issue a warning
|
206
213
|
|
@@ -208,13 +215,23 @@ export warn = (message) ->
|
|
208
215
|
|
209
216
|
log "WARNING: #{message}"
|
210
217
|
|
218
|
+
# ---------------------------------------------------------------------------
|
219
|
+
# hashToStr - stringify a hash
|
220
|
+
|
221
|
+
export hashToStr = (h) ->
|
222
|
+
|
223
|
+
return JSON.stringify(h, Object.keys(h).sort(), 3)
|
224
|
+
|
211
225
|
# ---------------------------------------------------------------------------
|
212
226
|
# say - print to the console (for now)
|
213
227
|
# later, on a web page, call alert(str)
|
214
228
|
|
215
|
-
export say = (
|
229
|
+
export say = (x) ->
|
216
230
|
|
217
|
-
|
231
|
+
if isHash(x)
|
232
|
+
console.log hashToStr(x)
|
233
|
+
else
|
234
|
+
console.log x
|
218
235
|
return
|
219
236
|
|
220
237
|
# ---------------------------------------------------------------------------
|
@@ -223,7 +240,8 @@ export say = (str, obj=undef) ->
|
|
223
240
|
|
224
241
|
export ask = (prompt) ->
|
225
242
|
|
226
|
-
|
243
|
+
answer = getline.question("{prompt}? ")
|
244
|
+
return answer
|
227
245
|
|
228
246
|
# ---------------------------------------------------------------------------
|
229
247
|
|
package/src/coffee_utils.js
CHANGED
@@ -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';
|
@@ -208,24 +210,41 @@ export var isInteger = function(x) {
|
|
208
210
|
}
|
209
211
|
};
|
210
212
|
|
213
|
+
// ---------------------------------------------------------------------------
|
214
|
+
export var uniq = function(lItems) {
|
215
|
+
return [...new Set(lItems)];
|
216
|
+
};
|
217
|
+
|
211
218
|
// ---------------------------------------------------------------------------
|
212
219
|
// warn - issue a warning
|
213
220
|
export var warn = function(message) {
|
214
221
|
return log(`WARNING: ${message}`);
|
215
222
|
};
|
216
223
|
|
224
|
+
// ---------------------------------------------------------------------------
|
225
|
+
// hashToStr - stringify a hash
|
226
|
+
export var hashToStr = function(h) {
|
227
|
+
return JSON.stringify(h, Object.keys(h).sort(), 3);
|
228
|
+
};
|
229
|
+
|
217
230
|
// ---------------------------------------------------------------------------
|
218
231
|
// say - print to the console (for now)
|
219
232
|
// later, on a web page, call alert(str)
|
220
|
-
export var say = function(
|
221
|
-
|
233
|
+
export var say = function(x) {
|
234
|
+
if (isHash(x)) {
|
235
|
+
console.log(hashToStr(x));
|
236
|
+
} else {
|
237
|
+
console.log(x);
|
238
|
+
}
|
222
239
|
};
|
223
240
|
|
224
241
|
// ---------------------------------------------------------------------------
|
225
242
|
// ask - ask a question
|
226
243
|
// later, on a web page, prompt the user for answer to question
|
227
244
|
export var ask = function(prompt) {
|
228
|
-
|
245
|
+
var answer;
|
246
|
+
answer = getline.question("{prompt}? ");
|
247
|
+
return answer;
|
229
248
|
};
|
230
249
|
|
231
250
|
// ---------------------------------------------------------------------------
|
package/src/debug_utils.coffee
CHANGED
package/src/debug_utils.js
CHANGED
package/temp.js
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
// Generated by CoffeeScript 2.6.1
|
2
|
+
// temp.coffee
|
3
|
+
var str;
|
4
|
+
|
5
|
+
import {
|
6
|
+
hashToStr
|
7
|
+
} from '@jdeighan/coffee-utils';
|
8
|
+
|
9
|
+
// ---------------------------------------------------------------------------
|
10
|
+
str = hashToStr({
|
11
|
+
c: 3,
|
12
|
+
b: 2,
|
13
|
+
a: 1
|
14
|
+
});
|
15
|
+
|
16
|
+
console.log(str);
|