@jdeighan/coffee-utils 4.1.3 → 4.1.7
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -2
- package/src/UnitTester.coffee +3 -6
- package/src/UnitTester.js +4 -7
- package/src/coffee_utils.coffee +18 -2
- package/src/coffee_utils.js +17 -2
- package/src/fs_utils.coffee +8 -2
- package/src/fs_utils.js +9 -3
- package/temp.js +26 -0
- package/src/private_env.coffee +0 -52
- package/src/private_env.js +0 -63
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.7",
|
5
5
|
"description": "A set of utility functions for CoffeeScript",
|
6
6
|
"main": "coffee_utils.js",
|
7
7
|
"exports": {
|
@@ -13,7 +13,6 @@
|
|
13
13
|
"./debug": "./src/debug_utils.js",
|
14
14
|
"./svelte": "./src/svelte_utils.js",
|
15
15
|
"./test": "./src/UnitTester.js",
|
16
|
-
"./privenv": "./src/private_env.js",
|
17
16
|
"./package.json": "./package.json"
|
18
17
|
},
|
19
18
|
"engines": {
|
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
@@ -202,6 +202,12 @@ export isInteger = (x) ->
|
|
202
202
|
else
|
203
203
|
return false
|
204
204
|
|
205
|
+
# ---------------------------------------------------------------------------
|
206
|
+
|
207
|
+
export uniq = (lItems) ->
|
208
|
+
|
209
|
+
return [...new Set(lItems)]
|
210
|
+
|
205
211
|
# ---------------------------------------------------------------------------
|
206
212
|
# warn - issue a warning
|
207
213
|
|
@@ -209,13 +215,23 @@ export warn = (message) ->
|
|
209
215
|
|
210
216
|
log "WARNING: #{message}"
|
211
217
|
|
218
|
+
# ---------------------------------------------------------------------------
|
219
|
+
# hashToStr - stringify a hash
|
220
|
+
|
221
|
+
export hashToStr = (h) ->
|
222
|
+
|
223
|
+
return JSON.stringify(h, Object.keys(h).sort(), 3)
|
224
|
+
|
212
225
|
# ---------------------------------------------------------------------------
|
213
226
|
# say - print to the console (for now)
|
214
227
|
# later, on a web page, call alert(str)
|
215
228
|
|
216
|
-
export say = (
|
229
|
+
export say = (x) ->
|
217
230
|
|
218
|
-
|
231
|
+
if isHash(x)
|
232
|
+
console.log hashToStr(x)
|
233
|
+
else
|
234
|
+
console.log x
|
219
235
|
return
|
220
236
|
|
221
237
|
# ---------------------------------------------------------------------------
|
package/src/coffee_utils.js
CHANGED
@@ -210,17 +210,32 @@ export var isInteger = function(x) {
|
|
210
210
|
}
|
211
211
|
};
|
212
212
|
|
213
|
+
// ---------------------------------------------------------------------------
|
214
|
+
export var uniq = function(lItems) {
|
215
|
+
return [...new Set(lItems)];
|
216
|
+
};
|
217
|
+
|
213
218
|
// ---------------------------------------------------------------------------
|
214
219
|
// warn - issue a warning
|
215
220
|
export var warn = function(message) {
|
216
221
|
return log(`WARNING: ${message}`);
|
217
222
|
};
|
218
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
|
+
|
219
230
|
// ---------------------------------------------------------------------------
|
220
231
|
// say - print to the console (for now)
|
221
232
|
// later, on a web page, call alert(str)
|
222
|
-
export var say = function(
|
223
|
-
|
233
|
+
export var say = function(x) {
|
234
|
+
if (isHash(x)) {
|
235
|
+
console.log(hashToStr(x));
|
236
|
+
} else {
|
237
|
+
console.log(x);
|
238
|
+
}
|
224
239
|
};
|
225
240
|
|
226
241
|
// ---------------------------------------------------------------------------
|
package/src/fs_utils.coffee
CHANGED
@@ -45,8 +45,14 @@ export fileExt = (path) ->
|
|
45
45
|
|
46
46
|
export mydir = (url) ->
|
47
47
|
|
48
|
-
|
49
|
-
|
48
|
+
debug "url = #{url}"
|
49
|
+
path = urllib.fileURLToPath(url)
|
50
|
+
debug "path = #{path}"
|
51
|
+
dir = pathlib.dirname(path)
|
52
|
+
debug "dir = #{dir}"
|
53
|
+
final = mkpath(dir)
|
54
|
+
debug "final = #{final}"
|
55
|
+
return final
|
50
56
|
|
51
57
|
# ---------------------------------------------------------------------------
|
52
58
|
|
package/src/fs_utils.js
CHANGED
@@ -57,9 +57,15 @@ export var fileExt = function(path) {
|
|
57
57
|
// mydir() - pass argument `import.meta.url` and it will return
|
58
58
|
// the directory your file is in
|
59
59
|
export var mydir = function(url) {
|
60
|
-
var dir;
|
61
|
-
|
62
|
-
|
60
|
+
var dir, final, path;
|
61
|
+
debug(`url = ${url}`);
|
62
|
+
path = urllib.fileURLToPath(url);
|
63
|
+
debug(`path = ${path}`);
|
64
|
+
dir = pathlib.dirname(path);
|
65
|
+
debug(`dir = ${dir}`);
|
66
|
+
final = mkpath(dir);
|
67
|
+
debug(`final = ${final}`);
|
68
|
+
return final;
|
63
69
|
};
|
64
70
|
|
65
71
|
// ---------------------------------------------------------------------------
|
package/temp.js
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
// Generated by CoffeeScript 2.6.1
|
2
|
+
// temp.coffee
|
3
|
+
var dir;
|
4
|
+
|
5
|
+
import {
|
6
|
+
say
|
7
|
+
} from '@jdeighan/coffee-utils';
|
8
|
+
|
9
|
+
import {
|
10
|
+
log
|
11
|
+
} from '@jdeighan/coffee-utils/log';
|
12
|
+
|
13
|
+
import {
|
14
|
+
setDebugging
|
15
|
+
} from '@jdeighan/coffee-utils/debug';
|
16
|
+
|
17
|
+
import {
|
18
|
+
mydir,
|
19
|
+
mkpath
|
20
|
+
} from '@jdeighan/coffee-utils/fs';
|
21
|
+
|
22
|
+
setDebugging(true);
|
23
|
+
|
24
|
+
dir = mydir(import.meta.url);
|
25
|
+
|
26
|
+
say(`dir = ${dir}`);
|
package/src/private_env.coffee
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
# private_env.coffee
|
2
|
-
|
3
|
-
import {assert} from '@jdeighan/coffee-utils'
|
4
|
-
import {log} from '@jdeighan/coffee-utils/log'
|
5
|
-
|
6
|
-
# --- Use by simply importing and using hEnvLib
|
7
|
-
# This module does no loading - it merely holds hEnvLib
|
8
|
-
export hPrivEnv = {}
|
9
|
-
|
10
|
-
# --- None of these callbacks should replace variable hEnvLib
|
11
|
-
|
12
|
-
export hPrivEnvCallbacks = {
|
13
|
-
getVar: (name) ->
|
14
|
-
return hPrivEnv[name]
|
15
|
-
setVar: (name, value) ->
|
16
|
-
hPrivEnv[name] = value
|
17
|
-
return
|
18
|
-
clearVar: (name) ->
|
19
|
-
delete hPrivEnv[name]
|
20
|
-
return
|
21
|
-
clearAll: () ->
|
22
|
-
for name in Object.keys(hPrivEnv)
|
23
|
-
delete hPrivEnv[name]
|
24
|
-
return
|
25
|
-
names: () ->
|
26
|
-
return Object.keys(hPrivEnv)
|
27
|
-
}
|
28
|
-
|
29
|
-
# ---------------------------------------------------------------------------
|
30
|
-
|
31
|
-
export setPrivEnvVar = (name, value) ->
|
32
|
-
|
33
|
-
hPrivEnv[name] = value
|
34
|
-
return
|
35
|
-
|
36
|
-
# ---------------------------------------------------------------------------
|
37
|
-
|
38
|
-
export resetPrivEnv = () ->
|
39
|
-
|
40
|
-
for name in Object.keys(hPrivEnv)
|
41
|
-
delete hPrivEnv[name]
|
42
|
-
return
|
43
|
-
|
44
|
-
# ---------------------------------------------------------------------------
|
45
|
-
|
46
|
-
export logPrivEnv = () ->
|
47
|
-
|
48
|
-
log "PRIVATE ENVIRONMENT:"
|
49
|
-
for key,value of hPrivEnv
|
50
|
-
log " #{key} = '#{value}'"
|
51
|
-
log '-'.repeat(40)
|
52
|
-
return
|
package/src/private_env.js
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
// Generated by CoffeeScript 2.6.1
|
2
|
-
// private_env.coffee
|
3
|
-
import {
|
4
|
-
assert
|
5
|
-
} from '@jdeighan/coffee-utils';
|
6
|
-
|
7
|
-
import {
|
8
|
-
log
|
9
|
-
} from '@jdeighan/coffee-utils/log';
|
10
|
-
|
11
|
-
// --- Use by simply importing and using hEnvLib
|
12
|
-
// This module does no loading - it merely holds hEnvLib
|
13
|
-
export var hPrivEnv = {};
|
14
|
-
|
15
|
-
// --- None of these callbacks should replace variable hEnvLib
|
16
|
-
export var hPrivEnvCallbacks = {
|
17
|
-
getVar: function(name) {
|
18
|
-
return hPrivEnv[name];
|
19
|
-
},
|
20
|
-
setVar: function(name, value) {
|
21
|
-
hPrivEnv[name] = value;
|
22
|
-
},
|
23
|
-
clearVar: function(name) {
|
24
|
-
delete hPrivEnv[name];
|
25
|
-
},
|
26
|
-
clearAll: function() {
|
27
|
-
var i, len, name, ref;
|
28
|
-
ref = Object.keys(hPrivEnv);
|
29
|
-
for (i = 0, len = ref.length; i < len; i++) {
|
30
|
-
name = ref[i];
|
31
|
-
delete hPrivEnv[name];
|
32
|
-
}
|
33
|
-
},
|
34
|
-
names: function() {
|
35
|
-
return Object.keys(hPrivEnv);
|
36
|
-
}
|
37
|
-
};
|
38
|
-
|
39
|
-
// ---------------------------------------------------------------------------
|
40
|
-
export var setPrivEnvVar = function(name, value) {
|
41
|
-
hPrivEnv[name] = value;
|
42
|
-
};
|
43
|
-
|
44
|
-
// ---------------------------------------------------------------------------
|
45
|
-
export var resetPrivEnv = function() {
|
46
|
-
var i, len, name, ref;
|
47
|
-
ref = Object.keys(hPrivEnv);
|
48
|
-
for (i = 0, len = ref.length; i < len; i++) {
|
49
|
-
name = ref[i];
|
50
|
-
delete hPrivEnv[name];
|
51
|
-
}
|
52
|
-
};
|
53
|
-
|
54
|
-
// ---------------------------------------------------------------------------
|
55
|
-
export var logPrivEnv = function() {
|
56
|
-
var key, value;
|
57
|
-
log("PRIVATE ENVIRONMENT:");
|
58
|
-
for (key in hPrivEnv) {
|
59
|
-
value = hPrivEnv[key];
|
60
|
-
log(` ${key} = '${value}'`);
|
61
|
-
}
|
62
|
-
log('-'.repeat(40));
|
63
|
-
};
|