@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 CHANGED
@@ -1 +1 @@
1
- Initial Publication
1
+ Global Node modules
@@ -0,0 +1,9 @@
1
+ import { FileFunctions as FF } from "@kawalir/extension-node/Core/Functions";
2
+
3
+ export class File {
4
+ constructor(public path: string) {}
5
+
6
+ public testExistence = () => FF.File.testExistence(this.path);
7
+
8
+ public delete = () => FF.File.delete(this.path);
9
+ }
@@ -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
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./Folder";
2
+ export * from "./JsonFile";
3
+ export * from "./TextFile";
@@ -0,0 +1 @@
1
+ export * from "./FileSystem";
@@ -0,0 +1,8 @@
1
+ import { FileSystem as FS } from "@kawalir/extension-node/External";
2
+
3
+ export class BasicFunctions {
4
+ public static testExistence = (
5
+ path: string,
6
+ test: (stats: FS.Stats) => boolean,
7
+ ) => FS.existsSync(path) && test(FS.lstatSync(path));
8
+ }
@@ -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,7 @@
1
+ import { FileFunctions as FF } from "./File";
2
+ import { FolderFunctions } from "./Folder";
3
+
4
+ export class FileFunctions {
5
+ public static Folder = FolderFunctions;
6
+ public static File = FF;
7
+ }
@@ -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";
@@ -0,0 +1 @@
1
+ export * from "./File";
@@ -0,0 +1,5 @@
1
+ export * as ReadLine from "readline/promises";
2
+ export * as FileSystem from "fs";
3
+
4
+ import * as Path from "path";
5
+ export { Path };
@@ -1,3 +1,14 @@
1
- declare global {}
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 {};
@@ -0,0 +1,5 @@
1
+ import * as CORE from "@kawalir/extension-node/Core";
2
+
3
+ globalThis.TextFile = CORE.TextFile;
4
+ globalThis.JsonFile = CORE.JsonFile;
5
+ globalThis.Folder = CORE.Folder;
@@ -0,0 +1,8 @@
1
+ import * as EXT from "@kawalir/extension-node/External";
2
+
3
+ declare global {
4
+ var Path: typeof EXT.Path;
5
+ var FileSystem: typeof EXT.FileSystem;
6
+ }
7
+
8
+ export {};
@@ -0,0 +1,4 @@
1
+ import * as EXT from "@kawalir/extension-node/External";
2
+
3
+ globalThis.Path = EXT.Path;
4
+ globalThis.FileSystem = EXT.FileSystem;
package/Global/index.ts CHANGED
@@ -1,2 +1,3 @@
1
+ import "./Modules";
1
2
  import "./Classes";
2
3
  import "./Methods";
package/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  //? [Global]
2
- /// <reference path="Global/Classes/GlobalClasses.d.ts" />
2
+ /// <reference path="Global/Classes/GlobalClasses.d.ts" />
3
+ /// <reference path="Global/Modules/GlobalModules.d.ts" />
package/index.ts CHANGED
@@ -1,3 +1,4 @@
1
- export * from "./Core";
2
-
1
+ import "@kawalir/extension";
3
2
  import "./Global";
3
+
4
+ export * from "./Core";
package/package.json CHANGED
@@ -7,16 +7,17 @@
7
7
  "Node",
8
8
  "Node Extension"
9
9
  ],
10
- "version": "0.0.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
- "types": [],
13
- // For nodejs:
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
  }