namirasoft-core 1.2.1 → 1.2.2

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.
@@ -0,0 +1,4 @@
1
+ export declare class FileOperation {
2
+ static findUp(fileName: string): string[];
3
+ static foreachFolder(base: string, handler: (base: string, sub: string, full: string) => Promise<void>, folders?: boolean, files?: boolean): Promise<void>;
4
+ }
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.FileOperation = void 0;
36
+ const fs = __importStar(require("fs"));
37
+ const path = __importStar(require("path"));
38
+ class FileOperation {
39
+ static findUp(fileName) {
40
+ let currentDir = __dirname;
41
+ const rootDir = process.cwd();
42
+ const foundFilePaths = [];
43
+ function searchRecursively(dir) {
44
+ const files = fs.readdirSync(dir);
45
+ if (files.includes(fileName))
46
+ foundFilePaths.push(path.join(dir, fileName));
47
+ if (rootDir === dir)
48
+ return;
49
+ searchRecursively(path.dirname(dir));
50
+ }
51
+ searchRecursively(currentDir);
52
+ return foundFilePaths;
53
+ }
54
+ static foreachFolder(base, handler, folders = true, files = true) {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ function recursive(base, sub) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ let files_folders = fs.readdirSync(path.join(base, sub));
59
+ for (let folder of files_folders) {
60
+ let s = path.join(sub, folder);
61
+ let p = path.join(base, s);
62
+ if (fs.statSync(p).isDirectory()) {
63
+ if (folders)
64
+ yield handler(base, sub, folder);
65
+ yield recursive(base, s);
66
+ }
67
+ else {
68
+ if (files)
69
+ yield handler(base, sub, folder);
70
+ }
71
+ }
72
+ });
73
+ }
74
+ yield recursive(base, "");
75
+ });
76
+ }
77
+ }
78
+ exports.FileOperation = FileOperation;
79
+ //# sourceMappingURL=FileOperation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FileOperation.js","sourceRoot":"","sources":["../src/FileOperation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;AAC7B,MAAa,aAAa;IAEtB,MAAM,CAAC,MAAM,CAAC,QAAgB;QAE1B,IAAI,UAAU,GAAW,SAAS,CAAC;QACnC,MAAM,OAAO,GAAW,OAAO,CAAC,GAAG,EAAE,CAAC;QACtC,MAAM,cAAc,GAAa,EAAE,CAAC;QACpC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MAAM,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC9B,CAAC;KAAA;CACJ;AA3CD,sCA2CC"}
@@ -0,0 +1,15 @@
1
+ export declare class PackageService {
2
+ static get(path: string): PackageService;
3
+ static getMain(): PackageService;
4
+ static getThis(): PackageService;
5
+ private path;
6
+ private json;
7
+ constructor(path: string, json: any);
8
+ getPath(): string;
9
+ getName(): string;
10
+ getTitle(): string;
11
+ getDescription(): string;
12
+ getIcon(): string;
13
+ getLogo(): string;
14
+ getVersion(): string;
15
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PackageService = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const FileOperation_1 = require("./FileOperation");
9
+ class PackageService {
10
+ static get(path) {
11
+ if (path) {
12
+ const json = JSON.parse(fs_1.default.readFileSync(path, 'utf8'));
13
+ if (json)
14
+ return new PackageService(path, json);
15
+ }
16
+ throw new Error("Coundn't find package");
17
+ }
18
+ static getMain() {
19
+ const paths = FileOperation_1.FileOperation.findUp('package.json');
20
+ if (paths)
21
+ return this.get(paths[paths.length - 1]);
22
+ throw new Error("Coundn't find package");
23
+ }
24
+ static getThis() {
25
+ const paths = FileOperation_1.FileOperation.findUp('package.json');
26
+ if (paths)
27
+ return this.get(paths[0]);
28
+ throw new Error("Coundn't find package");
29
+ }
30
+ constructor(path, json) {
31
+ this.json = json;
32
+ this.path = path;
33
+ }
34
+ getPath() {
35
+ return this.path;
36
+ }
37
+ getName() {
38
+ return this.json.name;
39
+ }
40
+ getTitle() {
41
+ return this.json.title;
42
+ }
43
+ getDescription() {
44
+ return this.json.description;
45
+ }
46
+ getIcon() {
47
+ return this.json.icon;
48
+ }
49
+ getLogo() {
50
+ return this.json.logo;
51
+ }
52
+ getVersion() {
53
+ return this.json.version;
54
+ }
55
+ }
56
+ exports.PackageService = PackageService;
57
+ //# sourceMappingURL=PackageService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PackageService.js","sourceRoot":"","sources":["../src/PackageService.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,mDAAgD;AAEhD,MAAa,cAAc;IAEvB,MAAM,CAAC,GAAG,CAAC,IAAY;QAEnB,IAAI,IAAI,EACR;YACI,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,YAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;YACvD,IAAI,IAAI;gBACJ,OAAO,IAAI,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;SAC7C;QACD,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAC7C,CAAC;IACD,MAAM,CAAC,OAAO;QAEV,MAAM,KAAK,GAAG,6BAAa,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;QACnD,IAAI,KAAK;YACL,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;QAC7C,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAC7C,CAAC;IACD,MAAM,CAAC,OAAO;QAEV,MAAM,KAAK,GAAG,6BAAa,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;QACnD,IAAI,KAAK;YACL,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAC7C,CAAC;IAGD,YAAY,IAAY,EAAE,IAAS;QAE/B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;IACD,OAAO;QAEH,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IACD,OAAO;QAEH,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;IAC1B,CAAC;IACD,QAAQ;QAEJ,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;IAC3B,CAAC;IACD,cAAc;QAEV,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC;IACjC,CAAC;IACD,OAAO;QAEH,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;IAC1B,CAAC;IACD,OAAO;QAEH,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;IAC1B,CAAC;IACD,UAAU;QAEN,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;IAC7B,CAAC;CACJ;AA7DD,wCA6DC"}
package/dist/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export * from "./ConvertService";
5
5
  export * from "./Country";
6
6
  export * from "./CountryOperation";
7
7
  export * from "./ErrorOperation";
8
+ export * from "./FileOperation";
8
9
  export * from "./GeoOperation";
9
10
  export * from "./HTTPError";
10
11
  export * from "./HTTPMethod";
@@ -12,6 +13,7 @@ export * from "./IStorage";
12
13
  export * from "./IStorageLocal";
13
14
  export * from "./IStorageMemory";
14
15
  export * from "./ObjectService";
16
+ export * from "./PackageService";
15
17
  export * from "./ParsedNameValue";
16
18
  export * from "./PhoneOperation";
17
19
  export * from "./SignOperation";
package/dist/index.js CHANGED
@@ -21,6 +21,7 @@ __exportStar(require("./ConvertService"), exports);
21
21
  __exportStar(require("./Country"), exports);
22
22
  __exportStar(require("./CountryOperation"), exports);
23
23
  __exportStar(require("./ErrorOperation"), exports);
24
+ __exportStar(require("./FileOperation"), exports);
24
25
  __exportStar(require("./GeoOperation"), exports);
25
26
  __exportStar(require("./HTTPError"), exports);
26
27
  __exportStar(require("./HTTPMethod"), exports);
@@ -28,6 +29,7 @@ __exportStar(require("./IStorage"), exports);
28
29
  __exportStar(require("./IStorageLocal"), exports);
29
30
  __exportStar(require("./IStorageMemory"), exports);
30
31
  __exportStar(require("./ObjectService"), exports);
32
+ __exportStar(require("./PackageService"), exports);
31
33
  __exportStar(require("./ParsedNameValue"), exports);
32
34
  __exportStar(require("./PhoneOperation"), exports);
33
35
  __exportStar(require("./SignOperation"), exports);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,+CAA6B;AAC7B,8CAA4B;AAC5B,mDAAiC;AACjC,4CAA0B;AAC1B,qDAAmC;AACnC,mDAAiC;AACjC,iDAA+B;AAC/B,8CAA4B;AAC5B,+CAA6B;AAC7B,6CAA2B;AAC3B,kDAAgC;AAChC,mDAAiC;AACjC,kDAAgC;AAChC,oDAAkC;AAClC,mDAAiC;AACjC,kDAAgC;AAChC,oDAAkC;AAClC,kDAAgC;AAChC,iDAA+B;AAC/B,qDAAmC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,+CAA6B;AAC7B,8CAA4B;AAC5B,mDAAiC;AACjC,4CAA0B;AAC1B,qDAAmC;AACnC,mDAAiC;AACjC,kDAAgC;AAChC,iDAA+B;AAC/B,8CAA4B;AAC5B,+CAA6B;AAC7B,6CAA2B;AAC3B,kDAAgC;AAChC,mDAAiC;AACjC,kDAAgC;AAChC,mDAAiC;AACjC,oDAAkC;AAClC,mDAAiC;AACjC,kDAAgC;AAChC,oDAAkC;AAClC,kDAAgC;AAChC,iDAA+B;AAC/B,qDAAmC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "namirasoft-core",
3
3
  "description": "Namira Software Corporation Core NPM Package",
4
- "version": "1.2.1",
4
+ "version": "1.2.2",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "scripts": {},
@@ -9,9 +9,10 @@
9
9
  "license": "MIT",
10
10
  "dependencies": {
11
11
  "@types/md5": "^2.3.5",
12
+ "@types/node": "^20.10.3",
12
13
  "axios": "^1.6.2",
13
14
  "md5": "^2.3.0",
14
15
  "moment": "^2.29.4",
15
16
  "phone": "^3.1.41"
16
17
  }
17
- }
18
+ }
@@ -0,0 +1,46 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ export class FileOperation
4
+ {
5
+ static findUp(fileName: string): string[]
6
+ {
7
+ let currentDir: string = __dirname;
8
+ const rootDir: string = process.cwd();
9
+ const foundFilePaths: string[] = [];
10
+ function searchRecursively(dir: string)
11
+ {
12
+ const files: string[] = fs.readdirSync(dir);
13
+ if (files.includes(fileName))
14
+ foundFilePaths.push(path.join(dir, fileName));
15
+ if (rootDir === dir)
16
+ return;
17
+ searchRecursively(path.dirname(dir));
18
+ }
19
+ searchRecursively(currentDir);
20
+ return foundFilePaths;
21
+ }
22
+ static async foreachFolder(base: string, handler: (base: string, sub: string, full: string) => Promise<void>, folders: boolean = true, files: boolean = true)
23
+ {
24
+ async function recursive(base: string, sub: string)
25
+ {
26
+ let files_folders = fs.readdirSync(path.join(base, sub));
27
+ for (let folder of files_folders)
28
+ {
29
+ let s = path.join(sub, folder)
30
+ let p = path.join(base, s);
31
+ if (fs.statSync(p).isDirectory())
32
+ {
33
+ if (folders)
34
+ await handler(base, sub, folder);
35
+ await recursive(base, s);
36
+ }
37
+ else
38
+ {
39
+ if (files)
40
+ await handler(base, sub, folder);
41
+ }
42
+ }
43
+ }
44
+ await recursive(base, "");
45
+ }
46
+ }
@@ -0,0 +1,65 @@
1
+ import fs from "fs";
2
+ import { FileOperation } from "./FileOperation";
3
+
4
+ export class PackageService
5
+ {
6
+ static get(path: string): PackageService
7
+ {
8
+ if (path)
9
+ {
10
+ const json = JSON.parse(fs.readFileSync(path, 'utf8'));
11
+ if (json)
12
+ return new PackageService(path, json);
13
+ }
14
+ throw new Error("Coundn't find package");
15
+ }
16
+ static getMain(): PackageService
17
+ {
18
+ const paths = FileOperation.findUp('package.json');
19
+ if (paths)
20
+ return this.get(paths[paths.length - 1]);
21
+ throw new Error("Coundn't find package");
22
+ }
23
+ static getThis(): PackageService
24
+ {
25
+ const paths = FileOperation.findUp('package.json');
26
+ if (paths)
27
+ return this.get(paths[0]);
28
+ throw new Error("Coundn't find package");
29
+ }
30
+ private path: string;
31
+ private json: any;
32
+ constructor(path: string, json: any)
33
+ {
34
+ this.json = json;
35
+ this.path = path;
36
+ }
37
+ getPath(): string
38
+ {
39
+ return this.path;
40
+ }
41
+ getName(): string
42
+ {
43
+ return this.json.name;
44
+ }
45
+ getTitle(): string
46
+ {
47
+ return this.json.title;
48
+ }
49
+ getDescription(): string
50
+ {
51
+ return this.json.description;
52
+ }
53
+ getIcon(): string
54
+ {
55
+ return this.json.icon;
56
+ }
57
+ getLogo(): string
58
+ {
59
+ return this.json.logo;
60
+ }
61
+ getVersion(): string
62
+ {
63
+ return this.json.version;
64
+ }
65
+ }
package/src/index.ts CHANGED
@@ -5,6 +5,7 @@ export * from "./ConvertService";
5
5
  export * from "./Country";
6
6
  export * from "./CountryOperation";
7
7
  export * from "./ErrorOperation";
8
+ export * from "./FileOperation";
8
9
  export * from "./GeoOperation";
9
10
  export * from "./HTTPError";
10
11
  export * from "./HTTPMethod";
@@ -12,6 +13,7 @@ export * from "./IStorage";
12
13
  export * from "./IStorageLocal";
13
14
  export * from "./IStorageMemory";
14
15
  export * from "./ObjectService";
16
+ export * from "./PackageService";
15
17
  export * from "./ParsedNameValue";
16
18
  export * from "./PhoneOperation";
17
19
  export * from "./SignOperation";