@jdeighan/coffee-utils 7.0.31 → 7.0.32

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": "7.0.31",
4
+ "version": "7.0.32",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
@@ -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
- return (getClassName(x) == 'Object')
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
 
@@ -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
- return getClassName(x) === 'Object';
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
  // ---------------------------------------------------------------------------
@@ -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;