@brianbuie/node-kit 0.5.0 → 0.5.1
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/dist/Cache.d.ts +1 -0
- package/dist/File.d.ts +4 -2
- package/dist/File.js +11 -5
- package/package.json +1 -1
- package/src/File.test.ts +9 -1
- package/src/File.ts +12 -4
package/dist/Cache.d.ts
CHANGED
package/dist/File.d.ts
CHANGED
|
@@ -13,10 +13,11 @@ export declare class File {
|
|
|
13
13
|
* @returns lines as strings, removes trailing '\n'
|
|
14
14
|
*/
|
|
15
15
|
lines(): string[];
|
|
16
|
+
delete(): void;
|
|
16
17
|
static get Adaptor(): typeof FileAdaptor;
|
|
17
18
|
json<T>(contents?: T): JsonFile<T>;
|
|
18
19
|
static get json(): typeof JsonFile;
|
|
19
|
-
ndjson<T>(
|
|
20
|
+
ndjson<T>(lines?: T | T[]): NdjsonFile<T>;
|
|
20
21
|
static get ndjson(): typeof NdjsonFile;
|
|
21
22
|
}
|
|
22
23
|
declare class FileAdaptor<T = string> {
|
|
@@ -24,6 +25,7 @@ declare class FileAdaptor<T = string> {
|
|
|
24
25
|
constructor(filepath: string, contents?: T);
|
|
25
26
|
get exists(): boolean;
|
|
26
27
|
get path(): string;
|
|
28
|
+
delete(): void;
|
|
27
29
|
}
|
|
28
30
|
declare class JsonFile<T> extends FileAdaptor {
|
|
29
31
|
constructor(filepath: string, contents?: T);
|
|
@@ -31,7 +33,7 @@ declare class JsonFile<T> extends FileAdaptor {
|
|
|
31
33
|
write(contents: T): void;
|
|
32
34
|
}
|
|
33
35
|
declare class NdjsonFile<T> extends FileAdaptor {
|
|
34
|
-
constructor(filepath: string,
|
|
36
|
+
constructor(filepath: string, lines?: T | T[]);
|
|
35
37
|
append(lines: T | T[]): void;
|
|
36
38
|
lines(): T[];
|
|
37
39
|
}
|
package/dist/File.js
CHANGED
|
@@ -33,6 +33,9 @@ export class File {
|
|
|
33
33
|
const contents = (this.read() || '').split('\n');
|
|
34
34
|
return contents.slice(0, contents.length - 1);
|
|
35
35
|
}
|
|
36
|
+
delete() {
|
|
37
|
+
fs.rmSync(this.path, { force: true });
|
|
38
|
+
}
|
|
36
39
|
static get Adaptor() {
|
|
37
40
|
return FileAdaptor;
|
|
38
41
|
}
|
|
@@ -42,8 +45,8 @@ export class File {
|
|
|
42
45
|
static get json() {
|
|
43
46
|
return JsonFile;
|
|
44
47
|
}
|
|
45
|
-
ndjson(
|
|
46
|
-
return new NdjsonFile(this.path,
|
|
48
|
+
ndjson(lines) {
|
|
49
|
+
return new NdjsonFile(this.path, lines);
|
|
47
50
|
}
|
|
48
51
|
static get ndjson() {
|
|
49
52
|
return NdjsonFile;
|
|
@@ -66,6 +69,9 @@ class FileAdaptor {
|
|
|
66
69
|
get path() {
|
|
67
70
|
return this.file.path;
|
|
68
71
|
}
|
|
72
|
+
delete() {
|
|
73
|
+
this.file.delete();
|
|
74
|
+
}
|
|
69
75
|
}
|
|
70
76
|
class JsonFile extends FileAdaptor {
|
|
71
77
|
constructor(filepath, contents) {
|
|
@@ -82,10 +88,10 @@ class JsonFile extends FileAdaptor {
|
|
|
82
88
|
}
|
|
83
89
|
}
|
|
84
90
|
class NdjsonFile extends FileAdaptor {
|
|
85
|
-
constructor(filepath,
|
|
91
|
+
constructor(filepath, lines) {
|
|
86
92
|
super(filepath.endsWith('.ndjson') ? filepath : filepath + '.ndjson');
|
|
87
|
-
if (
|
|
88
|
-
this.append(
|
|
93
|
+
if (lines)
|
|
94
|
+
this.append(lines);
|
|
89
95
|
}
|
|
90
96
|
append(lines) {
|
|
91
97
|
this.file.append(Array.isArray(lines) ? lines.map((l) => JSON.stringify(snapshot(l))) : JSON.stringify(snapshot(lines)));
|
package/package.json
CHANGED
package/src/File.test.ts
CHANGED
|
@@ -15,7 +15,7 @@ const thing = {
|
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
describe('FileAdaptor', () => {
|
|
18
|
-
it('
|
|
18
|
+
it('Creates instances', () => {
|
|
19
19
|
const test1 = new File.Adaptor(testDir.filepath('test1.txt'));
|
|
20
20
|
assert(test1.file.path.includes('test1.txt'));
|
|
21
21
|
|
|
@@ -26,6 +26,14 @@ describe('FileAdaptor', () => {
|
|
|
26
26
|
const eg3 = eg3File.json();
|
|
27
27
|
assert(eg1.path === eg2.path && eg2.path === eg3.path);
|
|
28
28
|
});
|
|
29
|
+
|
|
30
|
+
it('Deletes files', () => {
|
|
31
|
+
const test = testDir.file('delete-test.txt');
|
|
32
|
+
test.write('test');
|
|
33
|
+
assert.equal(test.read(), 'test');
|
|
34
|
+
test.delete();
|
|
35
|
+
assert.equal(test.exists, false);
|
|
36
|
+
});
|
|
29
37
|
});
|
|
30
38
|
|
|
31
39
|
describe('File.ndjson', () => {
|
package/src/File.ts
CHANGED
|
@@ -40,6 +40,10 @@ export class File {
|
|
|
40
40
|
return contents.slice(0, contents.length - 1);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
delete() {
|
|
44
|
+
fs.rmSync(this.path, { force: true });
|
|
45
|
+
}
|
|
46
|
+
|
|
43
47
|
static get Adaptor() {
|
|
44
48
|
return FileAdaptor;
|
|
45
49
|
}
|
|
@@ -52,8 +56,8 @@ export class File {
|
|
|
52
56
|
return JsonFile;
|
|
53
57
|
}
|
|
54
58
|
|
|
55
|
-
ndjson<T>(
|
|
56
|
-
return new NdjsonFile<T>(this.path,
|
|
59
|
+
ndjson<T>(lines?: T | T[]) {
|
|
60
|
+
return new NdjsonFile<T>(this.path, lines);
|
|
57
61
|
}
|
|
58
62
|
|
|
59
63
|
static get ndjson() {
|
|
@@ -81,6 +85,10 @@ class FileAdaptor<T = string> {
|
|
|
81
85
|
get path() {
|
|
82
86
|
return this.file.path;
|
|
83
87
|
}
|
|
88
|
+
|
|
89
|
+
delete() {
|
|
90
|
+
this.file.delete();
|
|
91
|
+
}
|
|
84
92
|
}
|
|
85
93
|
|
|
86
94
|
class JsonFile<T> extends FileAdaptor {
|
|
@@ -100,9 +108,9 @@ class JsonFile<T> extends FileAdaptor {
|
|
|
100
108
|
}
|
|
101
109
|
|
|
102
110
|
class NdjsonFile<T> extends FileAdaptor {
|
|
103
|
-
constructor(filepath: string,
|
|
111
|
+
constructor(filepath: string, lines?: T | T[]) {
|
|
104
112
|
super(filepath.endsWith('.ndjson') ? filepath : filepath + '.ndjson');
|
|
105
|
-
if (
|
|
113
|
+
if (lines) this.append(lines);
|
|
106
114
|
}
|
|
107
115
|
|
|
108
116
|
append(lines: T | T[]) {
|