@jdeighan/coffee-utils 7.0.29 → 7.0.32
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/src/coffee_utils.coffee +19 -5
- package/src/coffee_utils.js +29 -4
- package/src/fs_utils.coffee +8 -0
- package/src/fs_utils.js +6 -1
- package/src/indent_utils.coffee +1 -1
- package/src/indent_utils.js +1 -1
package/package.json
CHANGED
package/src/coffee_utils.coffee
CHANGED
@@ -19,12 +19,13 @@ export error = (message) ->
|
|
19
19
|
|
20
20
|
# ---------------------------------------------------------------------------
|
21
21
|
# assert - mimic nodejs's assert
|
22
|
+
# return true so we can use it in boolean expressions
|
22
23
|
|
23
24
|
export assert = (cond, msg) ->
|
24
25
|
|
25
26
|
if ! cond
|
26
27
|
error(msg)
|
27
|
-
return
|
28
|
+
return true
|
28
29
|
|
29
30
|
# ---------------------------------------------------------------------------
|
30
31
|
# croak - throws an error after possibly printing useful info
|
@@ -85,9 +86,16 @@ export isArray = (x) ->
|
|
85
86
|
|
86
87
|
# ---------------------------------------------------------------------------
|
87
88
|
|
88
|
-
export isHash = (x) ->
|
89
|
+
export isHash = (x, lKeys) ->
|
89
90
|
|
90
|
-
|
91
|
+
if ! x || (getClassName(x) != 'Object')
|
92
|
+
return false
|
93
|
+
if defined(lKeys)
|
94
|
+
assert isArray(lKeys), "isHash(): lKeys not an array"
|
95
|
+
for key in lKeys
|
96
|
+
if ! x.hasOwnProperty(key)
|
97
|
+
return false
|
98
|
+
return true
|
91
99
|
|
92
100
|
# ---------------------------------------------------------------------------
|
93
101
|
|
@@ -103,7 +111,7 @@ export hashHasKey = (x, key) ->
|
|
103
111
|
|
104
112
|
export isEmpty = (x) ->
|
105
113
|
|
106
|
-
if
|
114
|
+
if (x == undef) || (x == null)
|
107
115
|
return true
|
108
116
|
if isString(x)
|
109
117
|
return x.match(/^\s*$/)
|
@@ -112,7 +120,7 @@ export isEmpty = (x) ->
|
|
112
120
|
if isHash(x)
|
113
121
|
return Object.keys(x).length == 0
|
114
122
|
else
|
115
|
-
|
123
|
+
return false
|
116
124
|
|
117
125
|
# ---------------------------------------------------------------------------
|
118
126
|
# nonEmpty
|
@@ -422,3 +430,9 @@ export className = (aClass) ->
|
|
422
430
|
return lMatches[1]
|
423
431
|
else
|
424
432
|
croak "className(): Bad input class"
|
433
|
+
|
434
|
+
# ---------------------------------------------------------------------------
|
435
|
+
|
436
|
+
export range = (n) ->
|
437
|
+
|
438
|
+
return [0..n-1]
|
package/src/coffee_utils.js
CHANGED
@@ -25,10 +25,12 @@ export var error = function(message) {
|
|
25
25
|
|
26
26
|
// ---------------------------------------------------------------------------
|
27
27
|
// assert - mimic nodejs's assert
|
28
|
+
// return true so we can use it in boolean expressions
|
28
29
|
export var assert = function(cond, msg) {
|
29
30
|
if (!cond) {
|
30
31
|
error(msg);
|
31
32
|
}
|
33
|
+
return true;
|
32
34
|
};
|
33
35
|
|
34
36
|
// ---------------------------------------------------------------------------
|
@@ -77,8 +79,21 @@ export var isArray = function(x) {
|
|
77
79
|
};
|
78
80
|
|
79
81
|
// ---------------------------------------------------------------------------
|
80
|
-
export var isHash = function(x) {
|
81
|
-
|
82
|
+
export var isHash = function(x, lKeys) {
|
83
|
+
var i, key, len;
|
84
|
+
if (!x || (getClassName(x) !== 'Object')) {
|
85
|
+
return false;
|
86
|
+
}
|
87
|
+
if (defined(lKeys)) {
|
88
|
+
assert(isArray(lKeys), "isHash(): lKeys not an array");
|
89
|
+
for (i = 0, len = lKeys.length; i < len; i++) {
|
90
|
+
key = lKeys[i];
|
91
|
+
if (!x.hasOwnProperty(key)) {
|
92
|
+
return false;
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}
|
96
|
+
return true;
|
82
97
|
};
|
83
98
|
|
84
99
|
// ---------------------------------------------------------------------------
|
@@ -92,7 +107,7 @@ export var hashHasKey = function(x, key) {
|
|
92
107
|
// isEmpty
|
93
108
|
// - string is whitespace, array has no elements, hash has no keys
|
94
109
|
export var isEmpty = function(x) {
|
95
|
-
if (x
|
110
|
+
if ((x === undef) || (x === null)) {
|
96
111
|
return true;
|
97
112
|
}
|
98
113
|
if (isString(x)) {
|
@@ -104,7 +119,7 @@ export var isEmpty = function(x) {
|
|
104
119
|
if (isHash(x)) {
|
105
120
|
return Object.keys(x).length === 0;
|
106
121
|
} else {
|
107
|
-
return
|
122
|
+
return false;
|
108
123
|
}
|
109
124
|
};
|
110
125
|
|
@@ -456,3 +471,13 @@ export var className = function(aClass) {
|
|
456
471
|
return croak("className(): Bad input class");
|
457
472
|
}
|
458
473
|
};
|
474
|
+
|
475
|
+
// ---------------------------------------------------------------------------
|
476
|
+
export var range = function(n) {
|
477
|
+
var ref;
|
478
|
+
return (function() {
|
479
|
+
var results = [];
|
480
|
+
for (var i = 0, ref = n - 1; 0 <= ref ? i <= ref : i >= ref; 0 <= ref ? i++ : i--){ results.push(i); }
|
481
|
+
return results;
|
482
|
+
}).apply(this);
|
483
|
+
};
|
package/src/fs_utils.coffee
CHANGED
@@ -361,6 +361,7 @@ export parseSource = (source) ->
|
|
361
361
|
# fullpath
|
362
362
|
# stub
|
363
363
|
# ext
|
364
|
+
# purpose
|
364
365
|
# }
|
365
366
|
# --- NOTE: source may be a file URL, e.g. import.meta.url
|
366
367
|
|
@@ -394,6 +395,13 @@ export parseSource = (source) ->
|
|
394
395
|
stub: hInfo.name
|
395
396
|
ext: hInfo.ext
|
396
397
|
}
|
398
|
+
|
399
|
+
# --- check for a 'purpose'
|
400
|
+
if lMatches = hSourceInfo.stub.match(///
|
401
|
+
\.
|
402
|
+
([A-Za-z_]+)
|
403
|
+
$///)
|
404
|
+
hSourceInfo.purpose = lMatches[1]
|
397
405
|
debug "return from parseSource()", hSourceInfo
|
398
406
|
return hSourceInfo
|
399
407
|
|
package/src/fs_utils.js
CHANGED
@@ -422,13 +422,14 @@ export var shortenPath = function(path) {
|
|
422
422
|
|
423
423
|
// ---------------------------------------------------------------------------
|
424
424
|
export var parseSource = function(source) {
|
425
|
-
var dir, hInfo, hSourceInfo;
|
425
|
+
var dir, hInfo, hSourceInfo, lMatches;
|
426
426
|
// --- returns {
|
427
427
|
// dir
|
428
428
|
// filename
|
429
429
|
// fullpath
|
430
430
|
// stub
|
431
431
|
// ext
|
432
|
+
// purpose
|
432
433
|
// }
|
433
434
|
// --- NOTE: source may be a file URL, e.g. import.meta.url
|
434
435
|
debug("enter parseSource()");
|
@@ -462,6 +463,10 @@ export var parseSource = function(source) {
|
|
462
463
|
ext: hInfo.ext
|
463
464
|
};
|
464
465
|
}
|
466
|
+
// --- check for a 'purpose'
|
467
|
+
if (lMatches = hSourceInfo.stub.match(/\.([A-Za-z_]+)$/)) {
|
468
|
+
hSourceInfo.purpose = lMatches[1];
|
469
|
+
}
|
465
470
|
}
|
466
471
|
debug("return from parseSource()", hSourceInfo);
|
467
472
|
return hSourceInfo;
|
package/src/indent_utils.coffee
CHANGED
@@ -9,7 +9,7 @@ import {arrayToBlock, blockToArray} from '@jdeighan/coffee-utils/block'
|
|
9
9
|
# ---------------------------------------------------------------------------
|
10
10
|
# NOTE: Currently, only TAB indentation is supported
|
11
11
|
# ---------------------------------------------------------------------------
|
12
|
-
# splitLine - separate a line into
|
12
|
+
# splitLine - separate a line into [level, line]
|
13
13
|
|
14
14
|
export splitLine = (line) ->
|
15
15
|
|
package/src/indent_utils.js
CHANGED
@@ -21,7 +21,7 @@ import {
|
|
21
21
|
// ---------------------------------------------------------------------------
|
22
22
|
// NOTE: Currently, only TAB indentation is supported
|
23
23
|
// ---------------------------------------------------------------------------
|
24
|
-
// splitLine - separate a line into
|
24
|
+
// splitLine - separate a line into [level, line]
|
25
25
|
export var splitLine = function(line) {
|
26
26
|
var lMatches;
|
27
27
|
assert(line != null, "splitLine(): line is undef");
|