namirasoft-core 1.5.2 → 1.5.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.
Files changed (57) hide show
  1. package/SKILL.md +223 -223
  2. package/dist/TimeOperation.d.ts +1 -0
  3. package/dist/TimeOperation.js +4 -0
  4. package/dist/TimeOperation.js.map +1 -1
  5. package/package.json +26 -26
  6. package/src/BaseDatabaseRow.ts +6 -6
  7. package/src/BaseLogger.ts +24 -24
  8. package/src/BaseMetaColumn.ts +17 -17
  9. package/src/BaseMetaDatabase.ts +30 -30
  10. package/src/BaseMetaTable.ts +40 -40
  11. package/src/BaseServer.ts +150 -150
  12. package/src/BaseUUID.ts +76 -76
  13. package/src/ByteOperation.ts +57 -57
  14. package/src/CacheService.ts +76 -76
  15. package/src/ColorOperation.ts +153 -153
  16. package/src/ConsoleOperation.ts +68 -68
  17. package/src/ConvertService.ts +123 -123
  18. package/src/CookieService.ts +33 -33
  19. package/src/Countries.ts +486 -486
  20. package/src/Country.ts +21 -21
  21. package/src/CountryOperation.ts +98 -98
  22. package/src/CronOperation.ts +121 -121
  23. package/src/EncodingOperation.ts +46 -46
  24. package/src/EnvService.ts +28 -28
  25. package/src/ErrorOperation.ts +13 -13
  26. package/src/FileOperation.ts +60 -60
  27. package/src/FilterItem.ts +117 -117
  28. package/src/FilterItemColumnType.ts +9 -9
  29. package/src/FilterItemOperator.ts +52 -52
  30. package/src/GeoOperation.ts +18 -18
  31. package/src/HTTPError.ts +8 -8
  32. package/src/HTTPMethod.ts +7 -7
  33. package/src/HashOperation.ts +24 -24
  34. package/src/ILogger.ts +17 -17
  35. package/src/IStorage.ts +5 -5
  36. package/src/IStorageCookie.ts +52 -52
  37. package/src/IStorageJsonFile.ts +45 -45
  38. package/src/IStorageLocal.ts +16 -16
  39. package/src/IStorageMemoryDedicated.ts +17 -17
  40. package/src/IStorageMemoryShared.ts +21 -21
  41. package/src/IStorageSession.ts +16 -16
  42. package/src/LogLevel.ts +11 -11
  43. package/src/NamingConvention.ts +199 -199
  44. package/src/ObjectService.ts +27 -27
  45. package/src/PackageService.ts +76 -76
  46. package/src/PasswordOperation.ts +12 -12
  47. package/src/PhoneOperation.ts +8 -8
  48. package/src/PriceOperation.ts +20 -20
  49. package/src/SearchOperation.ts +31 -31
  50. package/src/SetTimeouService.ts +32 -32
  51. package/src/SortItem.ts +88 -88
  52. package/src/StringOperation.ts +22 -22
  53. package/src/TimeOperation.ts +303 -299
  54. package/src/TimeUnitOperation.ts +82 -82
  55. package/src/URLOperation.ts +66 -66
  56. package/src/VersionOperation.ts +46 -46
  57. package/src/index.ts +52 -52
@@ -1,61 +1,61 @@
1
- let fs: any;
2
- let path: any;
3
- if (typeof window === 'undefined')
4
- {
5
- fs = require('fs');
6
- path = require('path');
7
- }
8
- export class FileOperation
9
- {
10
- static findUp(fileName: string): string[]
11
- {
12
- let currentDir: string = __dirname;
13
- const rootDir: string = process.cwd();
14
- const foundFilePaths: string[] = [];
15
- function searchRecursively(dir: string)
16
- {
17
- const files: string[] = fs.readdirSync(dir);
18
- if (files.includes(fileName))
19
- foundFilePaths.push(path.join(dir, fileName));
20
- if (rootDir === dir)
21
- return;
22
- let new_dir = path.dirname(dir);
23
- if (new_dir == dir)
24
- return;
25
- searchRecursively(new_dir);
26
- }
27
- searchRecursively(currentDir);
28
- return foundFilePaths;
29
- }
30
- static async foreach(base: string, handler: (base: string, sub: string, name: string, full: string, isFolder: boolean) => Promise<boolean>, folders: boolean = true, files: boolean = true, level: number | null = null)
31
- {
32
- async function recursive(base: string, sub: string, number: number)
33
- {
34
- if (level)
35
- if (number > level)
36
- return;
37
- let names = fs.readdirSync(path.join(base, sub));
38
- for (let name of names)
39
- {
40
- let newSub = path.join(sub, name)
41
- let full = path.join(base, newSub);
42
- if (fs.statSync(full).isDirectory())
43
- {
44
- if (folders)
45
- {
46
- let moveon = await handler(base, sub, name, full, true);
47
- if (!moveon)
48
- continue;
49
- }
50
- await recursive(base, newSub, number + 1);
51
- }
52
- else
53
- {
54
- if (files)
55
- await handler(base, sub, name, full, false);
56
- }
57
- }
58
- }
59
- await recursive(base, "", 1);
60
- }
1
+ let fs: any;
2
+ let path: any;
3
+ if (typeof window === 'undefined')
4
+ {
5
+ fs = require('fs');
6
+ path = require('path');
7
+ }
8
+ export class FileOperation
9
+ {
10
+ static findUp(fileName: string): string[]
11
+ {
12
+ let currentDir: string = __dirname;
13
+ const rootDir: string = process.cwd();
14
+ const foundFilePaths: string[] = [];
15
+ function searchRecursively(dir: string)
16
+ {
17
+ const files: string[] = fs.readdirSync(dir);
18
+ if (files.includes(fileName))
19
+ foundFilePaths.push(path.join(dir, fileName));
20
+ if (rootDir === dir)
21
+ return;
22
+ let new_dir = path.dirname(dir);
23
+ if (new_dir == dir)
24
+ return;
25
+ searchRecursively(new_dir);
26
+ }
27
+ searchRecursively(currentDir);
28
+ return foundFilePaths;
29
+ }
30
+ static async foreach(base: string, handler: (base: string, sub: string, name: string, full: string, isFolder: boolean) => Promise<boolean>, folders: boolean = true, files: boolean = true, level: number | null = null)
31
+ {
32
+ async function recursive(base: string, sub: string, number: number)
33
+ {
34
+ if (level)
35
+ if (number > level)
36
+ return;
37
+ let names = fs.readdirSync(path.join(base, sub));
38
+ for (let name of names)
39
+ {
40
+ let newSub = path.join(sub, name)
41
+ let full = path.join(base, newSub);
42
+ if (fs.statSync(full).isDirectory())
43
+ {
44
+ if (folders)
45
+ {
46
+ let moveon = await handler(base, sub, name, full, true);
47
+ if (!moveon)
48
+ continue;
49
+ }
50
+ await recursive(base, newSub, number + 1);
51
+ }
52
+ else
53
+ {
54
+ if (files)
55
+ await handler(base, sub, name, full, false);
56
+ }
57
+ }
58
+ }
59
+ await recursive(base, "", 1);
60
+ }
61
61
  }
package/src/FilterItem.ts CHANGED
@@ -1,118 +1,118 @@
1
- import { BaseMetaColumn } from "./BaseMetaColumn";
2
- import { BaseMetaTable } from "./BaseMetaTable";
3
- import { EncodingOperation } from "./EncodingOperation";
4
- import { ErrorOperation } from "./ErrorOperation";
5
- import { FilterItemOperator } from "./FilterItemOperator";
6
-
7
- export class FilterItem
8
- {
9
- public table: BaseMetaTable;
10
- public column: BaseMetaColumn;
11
- public not: boolean;
12
- public operator: FilterItemOperator;
13
- public values: string[];
14
- public static encode(filters: FilterItem[] | null): string
15
- {
16
- let value = this.stringify(filters);
17
- return EncodingOperation.Base64Encode(value);
18
- }
19
- public static decode(value: string): FilterItem[] | null
20
- {
21
- let encoded = EncodingOperation.Base64Decode(value);
22
- return this.parse(encoded);
23
- }
24
- public static stringify(filters: FilterItem[] | null): string
25
- {
26
- if (filters)
27
- return filters.map(x => x.getCommand()).join(";");
28
- return "";
29
- }
30
- public static parse(item: string | null): FilterItem[]
31
- {
32
- let ans: FilterItem[] = [];
33
- if (item)
34
- {
35
- let index = 0;
36
- let items = item.split(/(?<!\\);/);
37
- let thereIsMore = (): boolean =>
38
- {
39
- return index < items.length;
40
- };
41
- let next = (name: string): string =>
42
- {
43
- if (thereIsMore())
44
- return items[index++];
45
- throw ErrorOperation.getHTTP(400, `Next value is required for '${name}'. Must be separated by ;`);
46
- };
47
- while (thereIsMore())
48
- {
49
- let value_table = next("Table");
50
- let table = new BaseMetaTable(null, value_table, value_table);
51
-
52
- let value_column = next("Column");
53
- let column = new BaseMetaColumn(table, value_column, value_column, "", false)
54
-
55
- let value_not = next("Not");
56
- let not = value_not != "0"
57
- if (value_not != "0" && value_not != "1")
58
- ErrorOperation.throwHTTP(400, `Invalid value '${value_not}' for FilterItem.not, Only 0 and 1 are allowed.`);
59
-
60
- let value_operator = next("Operator");
61
- let operator = FilterItemOperator.getByName(value_operator);
62
-
63
- let values: string[] = [];
64
- for (let j = 0; j < operator.count; j++)
65
- {
66
- let value_value = next("Value Number " + (j + 1));
67
- let value = value_value.replace(/\\;/gm, ";");
68
- values.push(value);
69
- }
70
-
71
- ans.push(new FilterItem(table, column, not, operator, ...values));
72
- }
73
- }
74
- return ans;
75
- }
76
- constructor(table: BaseMetaTable, column: BaseMetaColumn, not: boolean, operator: FilterItemOperator, ...values: string[])
77
- {
78
- this.table = table;
79
- this.column = column;
80
- this.not = not;
81
- this.operator = operator;
82
- this.values = values;
83
- if (this.values.length != operator.count)
84
- throw ErrorOperation.getHTTP(400, `Invalid count of values: ${this.values.length} is provided but ${operator.count} is required.`);
85
- }
86
- getCommand()
87
- {
88
- return [this.table.name, this.column.name, this.not ? "1" : "0", this.operator.name, ...this.values.map(x => (x ?? "").toString().replace(/;/gm, "\\;"))].join(";");
89
- }
90
- isAllColumns()
91
- {
92
- return this.column.name === "*";
93
- }
94
- toString()
95
- {
96
- let ans = [];
97
- if (!this.isAllColumns())
98
- {
99
- let table;
100
- let column;
101
- if (this.table.text)
102
- table = this.table.text;
103
- else
104
- table = this.table.name;
105
- if (this.column.text)
106
- column = this.column.text;
107
- else
108
- column = this.column.name;
109
- ans.push([table, column].filter(x => x).join("."));
110
- }
111
- if (this.not)
112
- ans.push("Not");
113
- if (!this.isAllColumns() || this.operator != FilterItemOperator.all.equals || this.not)
114
- ans.push(this.operator.name);
115
- ans.push(this.values.join(", "));
116
- return ans.filter(x => x).join(" ");
117
- }
1
+ import { BaseMetaColumn } from "./BaseMetaColumn";
2
+ import { BaseMetaTable } from "./BaseMetaTable";
3
+ import { EncodingOperation } from "./EncodingOperation";
4
+ import { ErrorOperation } from "./ErrorOperation";
5
+ import { FilterItemOperator } from "./FilterItemOperator";
6
+
7
+ export class FilterItem
8
+ {
9
+ public table: BaseMetaTable;
10
+ public column: BaseMetaColumn;
11
+ public not: boolean;
12
+ public operator: FilterItemOperator;
13
+ public values: string[];
14
+ public static encode(filters: FilterItem[] | null): string
15
+ {
16
+ let value = this.stringify(filters);
17
+ return EncodingOperation.Base64Encode(value);
18
+ }
19
+ public static decode(value: string): FilterItem[] | null
20
+ {
21
+ let encoded = EncodingOperation.Base64Decode(value);
22
+ return this.parse(encoded);
23
+ }
24
+ public static stringify(filters: FilterItem[] | null): string
25
+ {
26
+ if (filters)
27
+ return filters.map(x => x.getCommand()).join(";");
28
+ return "";
29
+ }
30
+ public static parse(item: string | null): FilterItem[]
31
+ {
32
+ let ans: FilterItem[] = [];
33
+ if (item)
34
+ {
35
+ let index = 0;
36
+ let items = item.split(/(?<!\\);/);
37
+ let thereIsMore = (): boolean =>
38
+ {
39
+ return index < items.length;
40
+ };
41
+ let next = (name: string): string =>
42
+ {
43
+ if (thereIsMore())
44
+ return items[index++];
45
+ throw ErrorOperation.getHTTP(400, `Next value is required for '${name}'. Must be separated by ;`);
46
+ };
47
+ while (thereIsMore())
48
+ {
49
+ let value_table = next("Table");
50
+ let table = new BaseMetaTable(null, value_table, value_table);
51
+
52
+ let value_column = next("Column");
53
+ let column = new BaseMetaColumn(table, value_column, value_column, "", false)
54
+
55
+ let value_not = next("Not");
56
+ let not = value_not != "0"
57
+ if (value_not != "0" && value_not != "1")
58
+ ErrorOperation.throwHTTP(400, `Invalid value '${value_not}' for FilterItem.not, Only 0 and 1 are allowed.`);
59
+
60
+ let value_operator = next("Operator");
61
+ let operator = FilterItemOperator.getByName(value_operator);
62
+
63
+ let values: string[] = [];
64
+ for (let j = 0; j < operator.count; j++)
65
+ {
66
+ let value_value = next("Value Number " + (j + 1));
67
+ let value = value_value.replace(/\\;/gm, ";");
68
+ values.push(value);
69
+ }
70
+
71
+ ans.push(new FilterItem(table, column, not, operator, ...values));
72
+ }
73
+ }
74
+ return ans;
75
+ }
76
+ constructor(table: BaseMetaTable, column: BaseMetaColumn, not: boolean, operator: FilterItemOperator, ...values: string[])
77
+ {
78
+ this.table = table;
79
+ this.column = column;
80
+ this.not = not;
81
+ this.operator = operator;
82
+ this.values = values;
83
+ if (this.values.length != operator.count)
84
+ throw ErrorOperation.getHTTP(400, `Invalid count of values: ${this.values.length} is provided but ${operator.count} is required.`);
85
+ }
86
+ getCommand()
87
+ {
88
+ return [this.table.name, this.column.name, this.not ? "1" : "0", this.operator.name, ...this.values.map(x => (x ?? "").toString().replace(/;/gm, "\\;"))].join(";");
89
+ }
90
+ isAllColumns()
91
+ {
92
+ return this.column.name === "*";
93
+ }
94
+ toString()
95
+ {
96
+ let ans = [];
97
+ if (!this.isAllColumns())
98
+ {
99
+ let table;
100
+ let column;
101
+ if (this.table.text)
102
+ table = this.table.text;
103
+ else
104
+ table = this.table.name;
105
+ if (this.column.text)
106
+ column = this.column.text;
107
+ else
108
+ column = this.column.name;
109
+ ans.push([table, column].filter(x => x).join("."));
110
+ }
111
+ if (this.not)
112
+ ans.push("Not");
113
+ if (!this.isAllColumns() || this.operator != FilterItemOperator.all.equals || this.not)
114
+ ans.push(this.operator.name);
115
+ ans.push(this.values.join(", "));
116
+ return ans.filter(x => x).join(" ");
117
+ }
118
118
  }
@@ -1,10 +1,10 @@
1
- export enum FilterItemColumnType
2
- {
3
- Unknown = "Unknown",
4
- Boolean = "Boolean",
5
- Number = "Number",
6
- String = "String",
7
- Date = "Date",
8
- Time = "Time",
9
- DateTime = "DateTime",
1
+ export enum FilterItemColumnType
2
+ {
3
+ Unknown = "Unknown",
4
+ Boolean = "Boolean",
5
+ Number = "Number",
6
+ String = "String",
7
+ Date = "Date",
8
+ Time = "Time",
9
+ DateTime = "DateTime",
10
10
  };
@@ -1,53 +1,53 @@
1
- import { ErrorOperation } from "./ErrorOperation";
2
- import { FilterItemColumnType } from "./FilterItemColumnType";
3
-
4
- export class FilterItemOperator
5
- {
6
- static all = {
7
- equals: new FilterItemOperator("Equals", "=", 1, (type: FilterItemColumnType) => { return type != FilterItemColumnType.Unknown; }),
8
- contains: new FilterItemOperator("Contains", ":", 1, (type: FilterItemColumnType) => { return type != FilterItemColumnType.Unknown && type != FilterItemColumnType.Boolean; }),
9
- regex: new FilterItemOperator("Regex", "*", 1, (type: FilterItemColumnType) => { return type != FilterItemColumnType.Unknown && type != FilterItemColumnType.Boolean; }),
10
- empty: new FilterItemOperator("Empty", "?", 0, (type: FilterItemColumnType) => { return type != FilterItemColumnType.Unknown; }),
11
- exists: new FilterItemOperator("Exists", "??", 0, (_: FilterItemColumnType, required: boolean) => { return !required; }),
12
- includes: new FilterItemOperator("Includes", "()", 1, (_: FilterItemColumnType, required: boolean) => { return !required; }),
13
- startswith: new FilterItemOperator("Starts With", "(", 1, (type: FilterItemColumnType) => { return type == FilterItemColumnType.String; }),
14
- endswith: new FilterItemOperator("Ends With", ")", 1, (type: FilterItemColumnType) => { return type == FilterItemColumnType.String; }),
15
- lessthan: new FilterItemOperator("Less Than", "<", 1, (type: FilterItemColumnType) => { return [FilterItemColumnType.Number, FilterItemColumnType.DateTime, FilterItemColumnType.Date, FilterItemColumnType.Time].includes(type); }),
16
- lessthanequal: new FilterItemOperator("Less Than Equal", "<=", 1, (type: FilterItemColumnType) => { return [FilterItemColumnType.Number, FilterItemColumnType.DateTime, FilterItemColumnType.Date, FilterItemColumnType.Time].includes(type); }),
17
- morethan: new FilterItemOperator("More Than", ">", 1, (type: FilterItemColumnType) => { return [FilterItemColumnType.Number, FilterItemColumnType.DateTime, FilterItemColumnType.Date, FilterItemColumnType.Time].includes(type); }),
18
- morethanequal: new FilterItemOperator("More Than Equal", ">=", 1, (type: FilterItemColumnType) => { return [FilterItemColumnType.Number, FilterItemColumnType.DateTime, FilterItemColumnType.Date, FilterItemColumnType.Time].includes(type); }),
19
- };
20
- static getAll(): FilterItemOperator[]
21
- {
22
- return Object.keys(FilterItemOperator.all).map(name => (FilterItemOperator.all as any)[name]);
23
- }
24
- static getAllByType(type: FilterItemColumnType, required: boolean): FilterItemOperator[]
25
- {
26
- return FilterItemOperator.getAll().filter(f => f.accepts(type, required));
27
- }
28
- static getByName(name: string): FilterItemOperator
29
- {
30
- let found = (FilterItemOperator.all as any)[name.toLowerCase()];
31
- if (!found)
32
- ErrorOperation.throwHTTP(400, `Could not find operator by name: '${name}'. Valid values are ${this.getAll().map(x => x.name).join(",")}`);
33
- return found;
34
- }
35
- static getBySign(sign: string): FilterItemOperator
36
- {
37
- let found = FilterItemOperator.getAll().filter(x => x.sign == sign);
38
- if (found.length == 0)
39
- ErrorOperation.throwHTTP(400, `Could not find operator by sign: '${sign}'. Valid values are ${this.getAll().map(x => x.sign).join(",")}`);
40
- return found[0];
41
- }
42
- name: string;
43
- sign: string;
44
- count: number;
45
- accepts: (type: FilterItemColumnType, required: boolean) => boolean;
46
- constructor(name: string, sign: string, count: number, accepts: (type: FilterItemColumnType, required: boolean) => boolean)
47
- {
48
- this.name = name;
49
- this.sign = sign;
50
- this.count = count;
51
- this.accepts = accepts;
52
- }
1
+ import { ErrorOperation } from "./ErrorOperation";
2
+ import { FilterItemColumnType } from "./FilterItemColumnType";
3
+
4
+ export class FilterItemOperator
5
+ {
6
+ static all = {
7
+ equals: new FilterItemOperator("Equals", "=", 1, (type: FilterItemColumnType) => { return type != FilterItemColumnType.Unknown; }),
8
+ contains: new FilterItemOperator("Contains", ":", 1, (type: FilterItemColumnType) => { return type != FilterItemColumnType.Unknown && type != FilterItemColumnType.Boolean; }),
9
+ regex: new FilterItemOperator("Regex", "*", 1, (type: FilterItemColumnType) => { return type != FilterItemColumnType.Unknown && type != FilterItemColumnType.Boolean; }),
10
+ empty: new FilterItemOperator("Empty", "?", 0, (type: FilterItemColumnType) => { return type != FilterItemColumnType.Unknown; }),
11
+ exists: new FilterItemOperator("Exists", "??", 0, (_: FilterItemColumnType, required: boolean) => { return !required; }),
12
+ includes: new FilterItemOperator("Includes", "()", 1, (_: FilterItemColumnType, required: boolean) => { return !required; }),
13
+ startswith: new FilterItemOperator("Starts With", "(", 1, (type: FilterItemColumnType) => { return type == FilterItemColumnType.String; }),
14
+ endswith: new FilterItemOperator("Ends With", ")", 1, (type: FilterItemColumnType) => { return type == FilterItemColumnType.String; }),
15
+ lessthan: new FilterItemOperator("Less Than", "<", 1, (type: FilterItemColumnType) => { return [FilterItemColumnType.Number, FilterItemColumnType.DateTime, FilterItemColumnType.Date, FilterItemColumnType.Time].includes(type); }),
16
+ lessthanequal: new FilterItemOperator("Less Than Equal", "<=", 1, (type: FilterItemColumnType) => { return [FilterItemColumnType.Number, FilterItemColumnType.DateTime, FilterItemColumnType.Date, FilterItemColumnType.Time].includes(type); }),
17
+ morethan: new FilterItemOperator("More Than", ">", 1, (type: FilterItemColumnType) => { return [FilterItemColumnType.Number, FilterItemColumnType.DateTime, FilterItemColumnType.Date, FilterItemColumnType.Time].includes(type); }),
18
+ morethanequal: new FilterItemOperator("More Than Equal", ">=", 1, (type: FilterItemColumnType) => { return [FilterItemColumnType.Number, FilterItemColumnType.DateTime, FilterItemColumnType.Date, FilterItemColumnType.Time].includes(type); }),
19
+ };
20
+ static getAll(): FilterItemOperator[]
21
+ {
22
+ return Object.keys(FilterItemOperator.all).map(name => (FilterItemOperator.all as any)[name]);
23
+ }
24
+ static getAllByType(type: FilterItemColumnType, required: boolean): FilterItemOperator[]
25
+ {
26
+ return FilterItemOperator.getAll().filter(f => f.accepts(type, required));
27
+ }
28
+ static getByName(name: string): FilterItemOperator
29
+ {
30
+ let found = (FilterItemOperator.all as any)[name.toLowerCase()];
31
+ if (!found)
32
+ ErrorOperation.throwHTTP(400, `Could not find operator by name: '${name}'. Valid values are ${this.getAll().map(x => x.name).join(",")}`);
33
+ return found;
34
+ }
35
+ static getBySign(sign: string): FilterItemOperator
36
+ {
37
+ let found = FilterItemOperator.getAll().filter(x => x.sign == sign);
38
+ if (found.length == 0)
39
+ ErrorOperation.throwHTTP(400, `Could not find operator by sign: '${sign}'. Valid values are ${this.getAll().map(x => x.sign).join(",")}`);
40
+ return found[0];
41
+ }
42
+ name: string;
43
+ sign: string;
44
+ count: number;
45
+ accepts: (type: FilterItemColumnType, required: boolean) => boolean;
46
+ constructor(name: string, sign: string, count: number, accepts: (type: FilterItemColumnType, required: boolean) => boolean)
47
+ {
48
+ this.name = name;
49
+ this.sign = sign;
50
+ this.count = count;
51
+ this.accepts = accepts;
52
+ }
53
53
  }
@@ -1,19 +1,19 @@
1
- export class GeoOperation
2
- {
3
- static distance(lat1: number, lng1: number, lat2: number, lng2: number)
4
- {
5
- function degreeToRadian(degree: number)
6
- {
7
- return degree * Math.PI / 180;
8
- }
9
- let R = 6371; // km
10
- let dLat = degreeToRadian(lat2 - lat1);
11
- let dLng = degreeToRadian(lng2 - lng1);
12
- lat1 = degreeToRadian(lat1);
13
- lat2 = degreeToRadian(lat2);
14
- let a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
15
- Math.sin(dLng / 2) * Math.sin(dLng / 2) * Math.cos(lat1) * Math.cos(lat2);
16
- let c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
17
- return R * c;
18
- }
1
+ export class GeoOperation
2
+ {
3
+ static distance(lat1: number, lng1: number, lat2: number, lng2: number)
4
+ {
5
+ function degreeToRadian(degree: number)
6
+ {
7
+ return degree * Math.PI / 180;
8
+ }
9
+ let R = 6371; // km
10
+ let dLat = degreeToRadian(lat2 - lat1);
11
+ let dLng = degreeToRadian(lng2 - lng1);
12
+ lat1 = degreeToRadian(lat1);
13
+ lat2 = degreeToRadian(lat2);
14
+ let a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
15
+ Math.sin(dLng / 2) * Math.sin(dLng / 2) * Math.cos(lat1) * Math.cos(lat2);
16
+ let c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
17
+ return R * c;
18
+ }
19
19
  }
package/src/HTTPError.ts CHANGED
@@ -1,9 +1,9 @@
1
- export class HTTPError extends Error
2
- {
3
- code: number;
4
- constructor(code: number, message: string)
5
- {
6
- super(message);
7
- this.code = code;
8
- }
1
+ export class HTTPError extends Error
2
+ {
3
+ code: number;
4
+ constructor(code: number, message: string)
5
+ {
6
+ super(message);
7
+ this.code = code;
8
+ }
9
9
  }
package/src/HTTPMethod.ts CHANGED
@@ -1,8 +1,8 @@
1
- export enum HTTPMethod
2
- {
3
- GET = "GET",
4
- POST = "POST",
5
- PUT = "PUT",
6
- PATCH = "PATCH",
7
- DELETE = "DELETE"
1
+ export enum HTTPMethod
2
+ {
3
+ GET = "GET",
4
+ POST = "POST",
5
+ PUT = "PUT",
6
+ PATCH = "PATCH",
7
+ DELETE = "DELETE"
8
8
  }
@@ -1,25 +1,25 @@
1
- import * as crypto from 'node:crypto';
2
-
3
- export class HashOperation
4
- {
5
- static SHA256<T>(message: T): string
6
- {
7
- const hash = crypto.createHash('sha256');
8
- hash.update(JSON.stringify(message));
9
- return hash.digest('hex');
10
- }
11
- static SHA256Secret<T>(secret: string, message: T): string
12
- {
13
- const hash = crypto.createHmac('sha256', secret);
14
- hash.update(JSON.stringify(message));
15
- return hash.digest('hex');
16
- }
17
- static isValidSHA256(values: any, signature: string)
18
- {
19
- return this.SHA256(values).toLowerCase() === signature.toLowerCase();
20
- }
21
- static isValidSHA256Secret(secret: string, values: any, signature: string)
22
- {
23
- return this.SHA256Secret(secret, values).toLowerCase() === signature.toLowerCase();
24
- }
1
+ import * as crypto from 'node:crypto';
2
+
3
+ export class HashOperation
4
+ {
5
+ static SHA256<T>(message: T): string
6
+ {
7
+ const hash = crypto.createHash('sha256');
8
+ hash.update(JSON.stringify(message));
9
+ return hash.digest('hex');
10
+ }
11
+ static SHA256Secret<T>(secret: string, message: T): string
12
+ {
13
+ const hash = crypto.createHmac('sha256', secret);
14
+ hash.update(JSON.stringify(message));
15
+ return hash.digest('hex');
16
+ }
17
+ static isValidSHA256(values: any, signature: string)
18
+ {
19
+ return this.SHA256(values).toLowerCase() === signature.toLowerCase();
20
+ }
21
+ static isValidSHA256Secret(secret: string, values: any, signature: string)
22
+ {
23
+ return this.SHA256Secret(secret, values).toLowerCase() === signature.toLowerCase();
24
+ }
25
25
  }
package/src/ILogger.ts CHANGED
@@ -1,18 +1,18 @@
1
- import { LogLevel } from "./LogLevel";
2
-
3
- export interface ILogger
4
- {
5
- log(level: LogLevel, ...messages: any[]): void;
6
- trace(...messages: any[]): void;
7
- verbose(...messages: any[]): void;
8
- debug(...messages: any[]): void;
9
- info(...messages: any[]): void;
10
- success(...messages: any[]): void;
11
- warning(...messages: any[]): void;
12
- error(...messages: any[]): void;
13
- critical(...messages: any[]): void;
14
- fatal(...messages: any[]): void;
15
- onCatchError(error: Error | unknown): void;
16
- onCatchCritical(error: Error | unknown): void;
17
- onCatchFatal(error: Error | unknown): void;
1
+ import { LogLevel } from "./LogLevel";
2
+
3
+ export interface ILogger
4
+ {
5
+ log(level: LogLevel, ...messages: any[]): void;
6
+ trace(...messages: any[]): void;
7
+ verbose(...messages: any[]): void;
8
+ debug(...messages: any[]): void;
9
+ info(...messages: any[]): void;
10
+ success(...messages: any[]): void;
11
+ warning(...messages: any[]): void;
12
+ error(...messages: any[]): void;
13
+ critical(...messages: any[]): void;
14
+ fatal(...messages: any[]): void;
15
+ onCatchError(error: Error | unknown): void;
16
+ onCatchCritical(error: Error | unknown): void;
17
+ onCatchFatal(error: Error | unknown): void;
18
18
  }