@kawalir/extension-node 0.0.0 → 0.2.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/CHANGELOG.md +1 -1
- package/Core/Classes/FileSystem/File.ts +9 -0
- package/Core/Classes/FileSystem/Folder.ts +19 -0
- package/Core/Classes/FileSystem/JsonFile.ts +18 -0
- package/Core/Classes/FileSystem/TextFile.ts +10 -0
- package/Core/Classes/FileSystem/index.ts +3 -0
- package/Core/Classes/index.ts +1 -0
- package/Core/Functions/File/Basic/BasicFunctions.ts +8 -0
- package/Core/Functions/File/Basic/index.ts +1 -0
- package/Core/Functions/File/File/FileFunctions.ts +30 -0
- package/Core/Functions/File/File/index.ts +1 -0
- package/Core/Functions/File/FileFunctions.ts +7 -0
- package/Core/Functions/File/Folder/FolderFunctions.ts +22 -0
- package/Core/Functions/File/Folder/index.ts +1 -0
- package/Core/Functions/File/index.ts +1 -0
- package/Core/Functions/index.ts +1 -0
- package/External/index.ts +5 -0
- package/Global/Classes/GlobalClasses.d.ts +12 -1
- package/Global/Classes/index.ts +5 -0
- package/Global/Modules/GlobalModules.d.ts +8 -0
- package/Global/Modules/index.ts +4 -0
- package/Global/index.ts +1 -0
- package/index.d.ts +2 -1
- package/index.ts +3 -2
- package/package.json +10 -3
- package/tsconfig.json +3 -6
package/CHANGELOG.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
Global Node modules
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { FileFunctions } from "@kawalir/extension-node/Core/Functions";
|
|
2
|
+
import { TextFile } from "./TextFile";
|
|
3
|
+
|
|
4
|
+
export class Folder {
|
|
5
|
+
constructor(public path: string) {}
|
|
6
|
+
|
|
7
|
+
public getFile = (name: string) => new TextFile(this.getPath(name));
|
|
8
|
+
|
|
9
|
+
public getSubFolder = (relativePath: string) =>
|
|
10
|
+
new Folder(this.getPath(relativePath));
|
|
11
|
+
|
|
12
|
+
public getPath = (relative: string) => Path.join(this.path, relative);
|
|
13
|
+
|
|
14
|
+
public ensure = () => FileFunctions.Folder.ensure(this.path);
|
|
15
|
+
|
|
16
|
+
public get parent(): Folder {
|
|
17
|
+
return new Folder(Path.dirname(this.path));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TextFile } from "./TextFile";
|
|
2
|
+
import { File } from "./File";
|
|
3
|
+
|
|
4
|
+
export class JsonFile<T> extends File {
|
|
5
|
+
private textFile: TextFile;
|
|
6
|
+
constructor(path: string) {
|
|
7
|
+
super(path);
|
|
8
|
+
this.textFile = new TextFile(path);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public write = (data: T, pretty: boolean = true) =>
|
|
12
|
+
this.textFile.write(JSON.stringify(data, null, pretty ? 2 : undefined));
|
|
13
|
+
|
|
14
|
+
public readOrNull = (): Nullable<T> =>
|
|
15
|
+
this.testExistence() ? this.read() : null;
|
|
16
|
+
|
|
17
|
+
public read = (): T => JSON.parse(this.textFile.read());
|
|
18
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FileFunctions as FF } from "@kawalir/extension-node/Core/Functions";
|
|
2
|
+
import { File } from "./File";
|
|
3
|
+
|
|
4
|
+
export class TextFile extends File {
|
|
5
|
+
public write = (content: string) => FF.File.write(this.path, content);
|
|
6
|
+
|
|
7
|
+
public readOrNull = (): StringOrNull => FF.File.readOrNull(this.path);
|
|
8
|
+
|
|
9
|
+
public read = (): string => FF.File.read(this.path);
|
|
10
|
+
}
|
package/Core/Classes/index.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./FileSystem";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./BasicFunctions";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Path, FileSystem as FS } from "@kawalir/extension-node/External";
|
|
2
|
+
import { FolderFunctions as FF } from "../Folder";
|
|
3
|
+
import { BasicFunctions as BF } from "../Basic";
|
|
4
|
+
|
|
5
|
+
type Content = string | NodeJS.ArrayBufferView;
|
|
6
|
+
|
|
7
|
+
export class FileFunctions {
|
|
8
|
+
public static rewrite = (path: string, content: Content) => {
|
|
9
|
+
this.delete(path);
|
|
10
|
+
this.write(path, content);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
public static write = (path: string, content: Content) => {
|
|
14
|
+
FF.ensureContaining(path);
|
|
15
|
+
FS.writeFileSync(path, content, "utf8");
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
public static delete = (path: string) =>
|
|
19
|
+
FS.rmSync(path, {
|
|
20
|
+
force: true,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
public static readOrNull = (path: string): StringOrNull =>
|
|
24
|
+
this.testExistence(path) ? this.read(path) : null;
|
|
25
|
+
|
|
26
|
+
public static read = (path: string): string => FS.readFileSync(path, "utf-8");
|
|
27
|
+
|
|
28
|
+
public static testExistence = (path: string) =>
|
|
29
|
+
BF.testExistence(path, (e) => e.isFile());
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./FileFunctions";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BasicFunctions as BF } from "../Basic";
|
|
2
|
+
|
|
3
|
+
export class FolderFunctions {
|
|
4
|
+
public static ensureContaining = (path: string) =>
|
|
5
|
+
this.ensure(Path.dirname(path));
|
|
6
|
+
|
|
7
|
+
public static ensure = (path: string) => {
|
|
8
|
+
if (this.testExistence(path)) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
this.create(path);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
public static create = (path: string) => {
|
|
15
|
+
FileSystem.mkdirSync(path, {
|
|
16
|
+
recursive: true,
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
public static testExistence = (path: string) =>
|
|
21
|
+
BF.testExistence(path, (stats) => stats.isDirectory());
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./FolderFunctions";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./FileFunctions";
|
package/Core/Functions/index.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./File";
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import * as CORE from "@kawalir/extension-node/Core";
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
interface TextFile extends CORE.TextFile {}
|
|
5
|
+
var TextFile: typeof CORE.TextFile;
|
|
6
|
+
|
|
7
|
+
interface JsonFile<T> extends CORE.JsonFile<T> {}
|
|
8
|
+
var JsonFile: typeof CORE.JsonFile;
|
|
9
|
+
|
|
10
|
+
interface Folder extends CORE.Folder {}
|
|
11
|
+
var Folder: typeof CORE.Folder;
|
|
12
|
+
}
|
|
2
13
|
|
|
3
14
|
export {};
|
package/Global/Classes/index.ts
CHANGED
package/Global/index.ts
CHANGED
package/index.d.ts
CHANGED
package/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -7,16 +7,17 @@
|
|
|
7
7
|
"Node",
|
|
8
8
|
"Node Extension"
|
|
9
9
|
],
|
|
10
|
-
"version": "0.
|
|
10
|
+
"version": "0.2.0",
|
|
11
11
|
"author": "Denis Mijatovic",
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"type": "commonjs",
|
|
14
14
|
"main": "index.ts",
|
|
15
15
|
"types": "index.d.ts",
|
|
16
16
|
"files": [
|
|
17
|
-
"Structures",
|
|
18
|
-
"Core",
|
|
19
17
|
"Global",
|
|
18
|
+
"Core",
|
|
19
|
+
"Structures",
|
|
20
|
+
"External",
|
|
20
21
|
"index.ts",
|
|
21
22
|
"index.d.ts",
|
|
22
23
|
"tsconfig.json",
|
|
@@ -30,5 +31,11 @@
|
|
|
30
31
|
"patch": "npm run script Publish patch",
|
|
31
32
|
"script": "cd Scripts && npm start",
|
|
32
33
|
"test": "cd Test && npm start"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/node": "^25.3.0"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@kawalir/extension": "^0.8.0"
|
|
33
40
|
}
|
|
34
41
|
}
|
package/tsconfig.json
CHANGED
|
@@ -9,11 +9,8 @@
|
|
|
9
9
|
// See also https://aka.ms/tsconfig/module
|
|
10
10
|
"module": "nodenext",
|
|
11
11
|
"target": "esnext",
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
// "lib": ["esnext"],
|
|
15
|
-
// "types": ["node"],
|
|
16
|
-
// and npm install -D @types/node
|
|
12
|
+
"lib": ["esnext"],
|
|
13
|
+
"types": ["node", "@kawalir/extension"],
|
|
17
14
|
|
|
18
15
|
// Other Outputs
|
|
19
16
|
"sourceMap": true,
|
|
@@ -47,5 +44,5 @@
|
|
|
47
44
|
"@kawalir/extension-node/*": ["./*"]
|
|
48
45
|
}
|
|
49
46
|
},
|
|
50
|
-
"include": ["Structures", "Core", "Global"]
|
|
47
|
+
"include": ["External", "Structures", "Core", "Global"]
|
|
51
48
|
}
|