@brianbuie/node-kit 0.9.1 → 0.10.0

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/src/Dir.test.ts CHANGED
@@ -18,8 +18,8 @@ describe('Dir', () => {
18
18
  assert(sub.path.includes(subPath));
19
19
  });
20
20
 
21
- it('TempDir.dir returns instance of TempDir', () => {
22
- const sub = temp.dir('example');
21
+ it('TempDir.tempDir returns instance of TempDir', () => {
22
+ const sub = temp.tempDir('example');
23
23
  assert(sub instanceof TempDir);
24
24
  });
25
25
 
package/src/Dir.ts CHANGED
@@ -13,8 +13,8 @@ export class Dir {
13
13
  /**
14
14
  * @param path can be relative to workspace or absolute
15
15
  */
16
- constructor(_path: string) {
17
- this.path = _path;
16
+ constructor(_path = './') {
17
+ this.path = path.resolve(_path);
18
18
  }
19
19
 
20
20
  create() {
@@ -27,13 +27,17 @@ export class Dir {
27
27
  * @example
28
28
  * const folder = new Dir('example');
29
29
  * // folder.path = './example'
30
- * const child = folder.subDir('path/to/dir');
30
+ * const child = folder.dir('path/to/dir');
31
31
  * // child.path = './example/path/to/dir'
32
32
  */
33
33
  dir(subPath: string) {
34
34
  return new Dir(path.resolve(this.path, subPath));
35
35
  }
36
36
 
37
+ tempDir(subPath: string) {
38
+ return new TempDir(path.resolve(this.path, subPath));
39
+ }
40
+
37
41
  sanitize(name: string) {
38
42
  return sanitizeFilename(name.replace('https://', '').replace('www.', ''), { replacement: '_' }).slice(-200);
39
43
  }
@@ -58,10 +62,6 @@ export class Dir {
58
62
  * Extends Dir class with method to `clear()` contents
59
63
  */
60
64
  export class TempDir extends Dir {
61
- dir(subPath: string) {
62
- return new TempDir(path.resolve(this.path, subPath));
63
- }
64
-
65
65
  clear() {
66
66
  fs.rmSync(this.path, { recursive: true, force: true });
67
67
  this.create();
package/src/File.test.ts CHANGED
@@ -3,7 +3,7 @@ import assert from 'node:assert';
3
3
  import { temp } from './Dir.ts';
4
4
  import { File } from './File.ts';
5
5
 
6
- const testDir = temp.dir('file-test');
6
+ const testDir = temp.tempDir('file-test');
7
7
  testDir.clear();
8
8
 
9
9
  const thing = {
package/src/File.ts CHANGED
@@ -10,9 +10,20 @@ import { snapshot } from './snapshot.ts';
10
10
  */
11
11
  export class File {
12
12
  path;
13
+ root;
14
+ dir;
15
+ base;
16
+ ext;
17
+ name;
13
18
 
14
19
  constructor(filepath: string) {
15
20
  this.path = filepath;
21
+ const { root, dir, base, ext, name } = path.parse(filepath);
22
+ this.root = root;
23
+ this.dir = dir;
24
+ this.base = base;
25
+ this.ext = ext;
26
+ this.name = name;
16
27
  }
17
28
 
18
29
  get exists() {