namirasoft-core 1.2.1 → 1.2.3

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,81 @@
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
+ let fs;
37
+ if (typeof window === 'undefined')
38
+ fs = require('fs');
39
+ const path = __importStar(require("path"));
40
+ class FileOperation {
41
+ static findUp(fileName) {
42
+ let currentDir = __dirname;
43
+ const rootDir = process.cwd();
44
+ const foundFilePaths = [];
45
+ function searchRecursively(dir) {
46
+ const files = fs.readdirSync(dir);
47
+ if (files.includes(fileName))
48
+ foundFilePaths.push(path.join(dir, fileName));
49
+ if (rootDir === dir)
50
+ return;
51
+ searchRecursively(path.dirname(dir));
52
+ }
53
+ searchRecursively(currentDir);
54
+ return foundFilePaths;
55
+ }
56
+ static foreachFolder(base, handler, folders = true, files = true) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ function recursive(base, sub) {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ let files_folders = fs.readdirSync(path.join(base, sub));
61
+ for (let folder of files_folders) {
62
+ let s = path.join(sub, folder);
63
+ let p = path.join(base, s);
64
+ if (fs.statSync(p).isDirectory()) {
65
+ if (folders)
66
+ yield handler(base, sub, folder);
67
+ yield recursive(base, s);
68
+ }
69
+ else {
70
+ if (files)
71
+ yield handler(base, sub, folder);
72
+ }
73
+ }
74
+ });
75
+ }
76
+ yield recursive(base, "");
77
+ });
78
+ }
79
+ }
80
+ exports.FileOperation = FileOperation;
81
+ //# sourceMappingURL=FileOperation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FileOperation.js","sourceRoot":"","sources":["../src/FileOperation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAI,EAAO,CAAC;AACZ,IAAI,OAAO,MAAM,KAAK,WAAW;IAC7B,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AACvB,2CAA6B;AAC7B,MAAa,aAAa;IAEtB,MAAM,CAAC,MAAM,CAAC,QAAgB;QAE1B,IAAI,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ACI,IAAI,KAAK;gCACL,MAAM,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;yBACxC;qBACJ;gBACL,CAAC;aAAA;YACD,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,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PackageService = void 0;
4
+ let fs;
5
+ if (typeof window === 'undefined')
6
+ fs = require('fs');
7
+ const FileOperation_1 = require("./FileOperation");
8
+ class PackageService {
9
+ static get(path) {
10
+ if (path) {
11
+ const json = JSON.parse(fs.readFileSync(path, 'utf8'));
12
+ if (json)
13
+ return new PackageService(path, json);
14
+ }
15
+ throw new Error("Coundn't find package");
16
+ }
17
+ static getMain() {
18
+ const paths = FileOperation_1.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() {
24
+ const paths = FileOperation_1.FileOperation.findUp('package.json');
25
+ if (paths)
26
+ return this.get(paths[0]);
27
+ throw new Error("Coundn't find package");
28
+ }
29
+ constructor(path, json) {
30
+ this.json = json;
31
+ this.path = path;
32
+ }
33
+ getPath() {
34
+ return this.path;
35
+ }
36
+ getName() {
37
+ return this.json.name;
38
+ }
39
+ getTitle() {
40
+ return this.json.title;
41
+ }
42
+ getDescription() {
43
+ return this.json.description;
44
+ }
45
+ getIcon() {
46
+ return this.json.icon;
47
+ }
48
+ getLogo() {
49
+ return this.json.logo;
50
+ }
51
+ getVersion() {
52
+ return this.json.version;
53
+ }
54
+ }
55
+ exports.PackageService = PackageService;
56
+ //# sourceMappingURL=PackageService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PackageService.js","sourceRoot":"","sources":["../src/PackageService.ts"],"names":[],"mappings":";;;AAAA,IAAI,EAAO,CAAC;AACZ,IAAI,OAAO,MAAM,KAAK,WAAW;IAC7B,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AACvB,mDAAgD;AAEhD,MAAa,cAAc;IAEvB,MAAM,CAAC,GAAG,CAAC,IAAY;QAEnB,IAAI,IAAI,EACR;YACI,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,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.3",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "scripts": {},
@@ -9,6 +9,7 @@
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",
@@ -0,0 +1,48 @@
1
+ let fs: any;
2
+ if (typeof window === 'undefined')
3
+ fs = require('fs');
4
+ import * as path from 'path';
5
+ export class FileOperation
6
+ {
7
+ static findUp(fileName: string): string[]
8
+ {
9
+ let currentDir: string = __dirname;
10
+ const rootDir: string = process.cwd();
11
+ const foundFilePaths: string[] = [];
12
+ function searchRecursively(dir: string)
13
+ {
14
+ const files: string[] = fs.readdirSync(dir);
15
+ if (files.includes(fileName))
16
+ foundFilePaths.push(path.join(dir, fileName));
17
+ if (rootDir === dir)
18
+ return;
19
+ searchRecursively(path.dirname(dir));
20
+ }
21
+ searchRecursively(currentDir);
22
+ return foundFilePaths;
23
+ }
24
+ static async foreachFolder(base: string, handler: (base: string, sub: string, full: string) => Promise<void>, folders: boolean = true, files: boolean = true)
25
+ {
26
+ async function recursive(base: string, sub: string)
27
+ {
28
+ let files_folders = fs.readdirSync(path.join(base, sub));
29
+ for (let folder of files_folders)
30
+ {
31
+ let s = path.join(sub, folder)
32
+ let p = path.join(base, s);
33
+ if (fs.statSync(p).isDirectory())
34
+ {
35
+ if (folders)
36
+ await handler(base, sub, folder);
37
+ await recursive(base, s);
38
+ }
39
+ else
40
+ {
41
+ if (files)
42
+ await handler(base, sub, folder);
43
+ }
44
+ }
45
+ }
46
+ await recursive(base, "");
47
+ }
48
+ }
@@ -0,0 +1,67 @@
1
+ let fs: any;
2
+ if (typeof window === 'undefined')
3
+ fs = require('fs');
4
+ import { FileOperation } from "./FileOperation";
5
+
6
+ export class PackageService
7
+ {
8
+ static get(path: string): PackageService
9
+ {
10
+ if (path)
11
+ {
12
+ const json = JSON.parse(fs.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(): PackageService
19
+ {
20
+ const paths = FileOperation.findUp('package.json');
21
+ if (paths)
22
+ return this.get(paths[paths.length - 1]);
23
+ throw new Error("Coundn't find package");
24
+ }
25
+ static getThis(): PackageService
26
+ {
27
+ const paths = FileOperation.findUp('package.json');
28
+ if (paths)
29
+ return this.get(paths[0]);
30
+ throw new Error("Coundn't find package");
31
+ }
32
+ private path: string;
33
+ private json: any;
34
+ constructor(path: string, json: any)
35
+ {
36
+ this.json = json;
37
+ this.path = path;
38
+ }
39
+ getPath(): string
40
+ {
41
+ return this.path;
42
+ }
43
+ getName(): string
44
+ {
45
+ return this.json.name;
46
+ }
47
+ getTitle(): string
48
+ {
49
+ return this.json.title;
50
+ }
51
+ getDescription(): string
52
+ {
53
+ return this.json.description;
54
+ }
55
+ getIcon(): string
56
+ {
57
+ return this.json.icon;
58
+ }
59
+ getLogo(): string
60
+ {
61
+ return this.json.logo;
62
+ }
63
+ getVersion(): string
64
+ {
65
+ return this.json.version;
66
+ }
67
+ }
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";