@jdeighan/coffee-utils 16.0.14 → 16.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@jdeighan/coffee-utils",
3
3
  "type": "module",
4
- "version": "16.0.14",
4
+ "version": "16.0.16",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
8
+ ".": "./src/lib/browser.js",
8
9
  "./server": "./src/lib/server.js",
9
10
  "./browser": "./src/lib/browser.js",
10
11
  "./fs": "./src/lib/fs.js",
@@ -45,14 +46,14 @@
45
46
  },
46
47
  "homepage": "https://github.com/johndeighan/coffee-utils#readme",
47
48
  "dependencies": {
48
- "@jdeighan/base-utils": "^8.0.7",
49
+ "@jdeighan/base-utils": "^8.0.17",
49
50
  "cross-env": "^7.0.3",
50
51
  "n-readlines": "^1.0.1",
51
52
  "readline-sync": "^1.4.10",
52
53
  "svelte": "^4.1.1"
53
54
  },
54
55
  "devDependencies": {
55
- "@jdeighan/unit-tester": "^3.0.61",
56
- "ava": "^5.3.1"
56
+ "@jdeighan/unit-tester": "^3.0.66",
57
+ "ava": "^6.0.1"
57
58
  }
58
59
  }
package/src/lib/fs.coffee CHANGED
@@ -15,7 +15,8 @@ import {
15
15
  OL, toBlock, getOptions, isArrayOfStrings, deepCopy,
16
16
  } from '@jdeighan/base-utils'
17
17
  import {
18
- mkpath, isFile, isDir, rmFileSync, mkdirSync, forEachLineInFile,
18
+ mydir, mkpath, isFile, isDir, rmFileSync, mkdirSync,
19
+ forEachLineInFile, fixPath,
19
20
  rmFile, rmDir, rmDirSync,
20
21
  } from '@jdeighan/base-utils/fs'
21
22
  import {assert, croak} from '@jdeighan/base-utils/exceptions'
@@ -24,7 +25,7 @@ import {dbg, dbgEnter, dbgReturn} from '@jdeighan/base-utils/debug'
24
25
  import {fromTAML} from '@jdeighan/base-utils/taml'
25
26
 
26
27
  export {
27
- mkpath, isFile, isDir, rmFileSync, mkdirSync,
28
+ mydir, mkpath, isFile, isDir, rmFileSync, mkdirSync,
28
29
  forEachLineInFile, rmDir, rmDirSync, rmFile,
29
30
  }
30
31
 
@@ -107,17 +108,6 @@ export cloneRepo = (user, repo, dir) =>
107
108
  git_repo = "https://github.com/#{user}/#{repo}.git"
108
109
  return execCmd "git clone #{git_repo} #{dir}"
109
110
 
110
- # ---------------------------------------------------------------------------
111
- # mydir() - pass argument import.meta.url and it will return
112
- # the directory your file is in
113
-
114
- export mydir = (url) =>
115
-
116
- path = urllib.fileURLToPath(url)
117
- dir = pathlib.dirname(path)
118
- final = mkpath(dir)
119
- return final
120
-
121
111
  # ---------------------------------------------------------------------------
122
112
 
123
113
  export homeDir = () =>
@@ -362,9 +352,9 @@ export pathTo = (fname, searchDir, options=undef) =>
362
352
  if relative
363
353
  return "./#{fname}"
364
354
  else if directory
365
- return searchDir
355
+ return fixPath(searchDir)
366
356
  else
367
- return filepath
357
+ return fixPath(filepath)
368
358
 
369
359
  if (direction == 'down')
370
360
  # --- Search all directories in this directory
@@ -375,9 +365,9 @@ export pathTo = (fname, searchDir, options=undef) =>
375
365
  if relative
376
366
  return fpath.replace('./', "./#{subdir}/")
377
367
  else if directory
378
- return dirPath
368
+ return fixPath(dirPath)
379
369
  else
380
- return fpath
370
+ return fixPath(fpath)
381
371
  else if (direction == 'up')
382
372
  nLevels = 0
383
373
  while defined(dirPath = getParentDir(searchDir))
@@ -387,9 +377,9 @@ export pathTo = (fname, searchDir, options=undef) =>
387
377
  if relative
388
378
  return "../".repeat(nLevels) + fname
389
379
  else if directory
390
- return dirPath
380
+ return fixPath(dirPath)
391
381
  else
392
- return fpath
382
+ return fixPath(fpath)
393
383
  searchDir = dirPath
394
384
  else
395
385
  croak "pathTo(): Invalid direction '#{direction}'"
package/src/lib/fs.js CHANGED
@@ -43,12 +43,14 @@ import {
43
43
  } from '@jdeighan/base-utils';
44
44
 
45
45
  import {
46
+ mydir,
46
47
  mkpath,
47
48
  isFile,
48
49
  isDir,
49
50
  rmFileSync,
50
51
  mkdirSync,
51
52
  forEachLineInFile,
53
+ fixPath,
52
54
  rmFile,
53
55
  rmDir,
54
56
  rmDirSync
@@ -75,6 +77,7 @@ import {
75
77
  } from '@jdeighan/base-utils/taml';
76
78
 
77
79
  export {
80
+ mydir,
78
81
  mkpath,
79
82
  isFile,
80
83
  isDir,
@@ -176,17 +179,6 @@ export var cloneRepo = (user, repo, dir) => {
176
179
  return execCmd(`git clone ${git_repo} ${dir}`);
177
180
  };
178
181
 
179
- // ---------------------------------------------------------------------------
180
- // mydir() - pass argument import.meta.url and it will return
181
- // the directory your file is in
182
- export var mydir = (url) => {
183
- var dir, final, path;
184
- path = urllib.fileURLToPath(url);
185
- dir = pathlib.dirname(path);
186
- final = mkpath(dir);
187
- return final;
188
- };
189
-
190
182
  // ---------------------------------------------------------------------------
191
183
  export var homeDir = () => {
192
184
  return mkpath(os.homedir());
@@ -448,9 +440,9 @@ export var pathTo = (fname, searchDir, options = undef) => {
448
440
  if (relative) {
449
441
  return `./${fname}`;
450
442
  } else if (directory) {
451
- return searchDir;
443
+ return fixPath(searchDir);
452
444
  } else {
453
- return filepath;
445
+ return fixPath(filepath);
454
446
  }
455
447
  }
456
448
  if (direction === 'down') {
@@ -464,9 +456,9 @@ export var pathTo = (fname, searchDir, options = undef) => {
464
456
  if (relative) {
465
457
  return fpath.replace('./', `./${subdir}/`);
466
458
  } else if (directory) {
467
- return dirPath;
459
+ return fixPath(dirPath);
468
460
  } else {
469
- return fpath;
461
+ return fixPath(fpath);
470
462
  }
471
463
  }
472
464
  }
@@ -479,9 +471,9 @@ export var pathTo = (fname, searchDir, options = undef) => {
479
471
  if (relative) {
480
472
  return "../".repeat(nLevels) + fname;
481
473
  } else if (directory) {
482
- return dirPath;
474
+ return fixPath(dirPath);
483
475
  } else {
484
- return fpath;
476
+ return fixPath(fpath);
485
477
  }
486
478
  }
487
479
  searchDir = dirPath;