@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/README.md +9 -4
- package/dist/index.d.mts +726 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +573 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +3 -3
- package/src/Dir.test.ts +2 -2
- package/src/Dir.ts +7 -7
- package/src/File.test.ts +1 -1
- package/src/File.ts +11 -0
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.
|
|
22
|
-
const sub = temp.
|
|
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
|
|
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.
|
|
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
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() {
|