@jdeighan/coffee-utils 7.0.21 → 7.0.22

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.21",
4
+ "version": "7.0.22",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
@@ -62,7 +62,12 @@ export isFile = (fullpath) ->
62
62
 
63
63
  export isDir = (fullpath) ->
64
64
 
65
- return fs.lstatSync(fullpath).isDirectory()
65
+ try
66
+ obj = fs.lstatSync(fullpath)
67
+ if !obj? then return false
68
+ return obj.isDirectory()
69
+ catch
70
+ return false
66
71
 
67
72
  # ---------------------------------------------------------------------------
68
73
 
@@ -73,6 +78,16 @@ export isSimpleFileName = (path) ->
73
78
 
74
79
  # ---------------------------------------------------------------------------
75
80
 
81
+ export fileStub = (path) ->
82
+
83
+ assert isString(path), "fileExt(): path not a string"
84
+ if lMatches = path.match(/^(.*)\.[A-Za-z0-9_]+$/)
85
+ return lMatches[1]
86
+ else
87
+ return ''
88
+
89
+ # ---------------------------------------------------------------------------
90
+
76
91
  export fileExt = (path) ->
77
92
 
78
93
  assert isString(path), "fileExt(): path not a string"
@@ -343,6 +358,7 @@ export parseSource = (source) ->
343
358
  # --- returns {
344
359
  # dir
345
360
  # filename
361
+ # fullpath
346
362
  # stub
347
363
  # ext
348
364
  # }
@@ -356,22 +372,28 @@ export parseSource = (source) ->
356
372
  if source.match(/^file\:\/\//)
357
373
  source = urllib.fileURLToPath(source)
358
374
 
359
- hInfo = pathlib.parse(source)
360
- if hInfo.dir
361
- dir = mkpath(hInfo.dir) # change \ to /
375
+ if isDir(source)
362
376
  hSourceInfo = {
363
- dir
364
- fullpath: mkpath(dir, hInfo.base)
365
- filename: hInfo.base
366
- stub: hInfo.name
367
- ext: hInfo.ext
377
+ dir: source
378
+ fullpath: source
368
379
  }
369
380
  else
370
- hSourceInfo = {
371
- filename: hInfo.base
372
- stub: hInfo.name
373
- ext: hInfo.ext
374
- }
381
+ hInfo = pathlib.parse(source)
382
+ if hInfo.dir
383
+ dir = mkpath(hInfo.dir) # change \ to /
384
+ hSourceInfo = {
385
+ dir
386
+ fullpath: mkpath(dir, hInfo.base)
387
+ filename: hInfo.base
388
+ stub: hInfo.name
389
+ ext: hInfo.ext
390
+ }
391
+ else
392
+ hSourceInfo = {
393
+ filename: hInfo.base
394
+ stub: hInfo.name
395
+ ext: hInfo.ext
396
+ }
375
397
  debug "return from parseSource()", hSourceInfo
376
398
  return hSourceInfo
377
399
 
package/src/fs_utils.js CHANGED
@@ -85,7 +85,16 @@ export var isFile = function(fullpath) {
85
85
 
86
86
  // ---------------------------------------------------------------------------
87
87
  export var isDir = function(fullpath) {
88
- return fs.lstatSync(fullpath).isDirectory();
88
+ var obj;
89
+ try {
90
+ obj = fs.lstatSync(fullpath);
91
+ if (obj == null) {
92
+ return false;
93
+ }
94
+ return obj.isDirectory();
95
+ } catch (error1) {
96
+ return false;
97
+ }
89
98
  };
90
99
 
91
100
  // ---------------------------------------------------------------------------
@@ -95,6 +104,17 @@ export var isSimpleFileName = function(path) {
95
104
  return !h.root && !h.dir && h.base;
96
105
  };
97
106
 
107
+ // ---------------------------------------------------------------------------
108
+ export var fileStub = function(path) {
109
+ var lMatches;
110
+ assert(isString(path), "fileExt(): path not a string");
111
+ if (lMatches = path.match(/^(.*)\.[A-Za-z0-9_]+$/)) {
112
+ return lMatches[1];
113
+ } else {
114
+ return '';
115
+ }
116
+ };
117
+
98
118
  // ---------------------------------------------------------------------------
99
119
  export var fileExt = function(path) {
100
120
  var lMatches;
@@ -406,6 +426,7 @@ export var parseSource = function(source) {
406
426
  // --- returns {
407
427
  // dir
408
428
  // filename
429
+ // fullpath
409
430
  // stub
410
431
  // ext
411
432
  // }
@@ -418,22 +439,29 @@ export var parseSource = function(source) {
418
439
  if (source.match(/^file\:\/\//)) {
419
440
  source = urllib.fileURLToPath(source);
420
441
  }
421
- hInfo = pathlib.parse(source);
422
- if (hInfo.dir) {
423
- dir = mkpath(hInfo.dir); // change \ to /
442
+ if (isDir(source)) {
424
443
  hSourceInfo = {
425
- dir,
426
- fullpath: mkpath(dir, hInfo.base),
427
- filename: hInfo.base,
428
- stub: hInfo.name,
429
- ext: hInfo.ext
444
+ dir: source,
445
+ fullpath: source
430
446
  };
431
447
  } else {
432
- hSourceInfo = {
433
- filename: hInfo.base,
434
- stub: hInfo.name,
435
- ext: hInfo.ext
436
- };
448
+ hInfo = pathlib.parse(source);
449
+ if (hInfo.dir) {
450
+ dir = mkpath(hInfo.dir); // change \ to /
451
+ hSourceInfo = {
452
+ dir,
453
+ fullpath: mkpath(dir, hInfo.base),
454
+ filename: hInfo.base,
455
+ stub: hInfo.name,
456
+ ext: hInfo.ext
457
+ };
458
+ } else {
459
+ hSourceInfo = {
460
+ filename: hInfo.base,
461
+ stub: hInfo.name,
462
+ ext: hInfo.ext
463
+ };
464
+ }
437
465
  }
438
466
  debug("return from parseSource()", hSourceInfo);
439
467
  return hSourceInfo;