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.
- package/SKILL.md +223 -223
- package/dist/TimeOperation.d.ts +1 -0
- package/dist/TimeOperation.js +4 -0
- package/dist/TimeOperation.js.map +1 -1
- package/package.json +26 -26
- package/src/BaseDatabaseRow.ts +6 -6
- package/src/BaseLogger.ts +24 -24
- package/src/BaseMetaColumn.ts +17 -17
- package/src/BaseMetaDatabase.ts +30 -30
- package/src/BaseMetaTable.ts +40 -40
- package/src/BaseServer.ts +150 -150
- package/src/BaseUUID.ts +76 -76
- package/src/ByteOperation.ts +57 -57
- package/src/CacheService.ts +76 -76
- package/src/ColorOperation.ts +153 -153
- package/src/ConsoleOperation.ts +68 -68
- package/src/ConvertService.ts +123 -123
- package/src/CookieService.ts +33 -33
- package/src/Countries.ts +486 -486
- package/src/Country.ts +21 -21
- package/src/CountryOperation.ts +98 -98
- package/src/CronOperation.ts +121 -121
- package/src/EncodingOperation.ts +46 -46
- package/src/EnvService.ts +28 -28
- package/src/ErrorOperation.ts +13 -13
- package/src/FileOperation.ts +60 -60
- package/src/FilterItem.ts +117 -117
- package/src/FilterItemColumnType.ts +9 -9
- package/src/FilterItemOperator.ts +52 -52
- package/src/GeoOperation.ts +18 -18
- package/src/HTTPError.ts +8 -8
- package/src/HTTPMethod.ts +7 -7
- package/src/HashOperation.ts +24 -24
- package/src/ILogger.ts +17 -17
- package/src/IStorage.ts +5 -5
- package/src/IStorageCookie.ts +52 -52
- package/src/IStorageJsonFile.ts +45 -45
- package/src/IStorageLocal.ts +16 -16
- package/src/IStorageMemoryDedicated.ts +17 -17
- package/src/IStorageMemoryShared.ts +21 -21
- package/src/IStorageSession.ts +16 -16
- package/src/LogLevel.ts +11 -11
- package/src/NamingConvention.ts +199 -199
- package/src/ObjectService.ts +27 -27
- package/src/PackageService.ts +76 -76
- package/src/PasswordOperation.ts +12 -12
- package/src/PhoneOperation.ts +8 -8
- package/src/PriceOperation.ts +20 -20
- package/src/SearchOperation.ts +31 -31
- package/src/SetTimeouService.ts +32 -32
- package/src/SortItem.ts +88 -88
- package/src/StringOperation.ts +22 -22
- package/src/TimeOperation.ts +303 -299
- package/src/TimeUnitOperation.ts +82 -82
- package/src/URLOperation.ts +66 -66
- package/src/VersionOperation.ts +46 -46
- package/src/index.ts +52 -52
package/src/PhoneOperation.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import * as Phone from 'phone';
|
|
2
|
-
|
|
3
|
-
export class PhoneOperation
|
|
4
|
-
{
|
|
5
|
-
static isValid(number: string): boolean
|
|
6
|
-
{
|
|
7
|
-
return Phone.phone(number).isValid;
|
|
8
|
-
}
|
|
1
|
+
import * as Phone from 'phone';
|
|
2
|
+
|
|
3
|
+
export class PhoneOperation
|
|
4
|
+
{
|
|
5
|
+
static isValid(number: string): boolean
|
|
6
|
+
{
|
|
7
|
+
return Phone.phone(number).isValid;
|
|
8
|
+
}
|
|
9
9
|
}
|
package/src/PriceOperation.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
export class PriceOperation
|
|
2
|
-
{
|
|
3
|
-
static millicent_to_cent(millicent: number): number
|
|
4
|
-
{
|
|
5
|
-
return Math.round(millicent / 1000);
|
|
6
|
-
}
|
|
7
|
-
static millicent_to_fiat(millicent: number, decimal: number = 2): number
|
|
8
|
-
{
|
|
9
|
-
let thousand = Math.max(5 - decimal, 0);
|
|
10
|
-
let hundred = 5 - thousand;
|
|
11
|
-
return Math.round(millicent / Math.pow(10, thousand)) / Math.pow(10, hundred);
|
|
12
|
-
}
|
|
13
|
-
static cent_to_millicent(cent: number): number
|
|
14
|
-
{
|
|
15
|
-
return Math.floor(cent * 1000);
|
|
16
|
-
}
|
|
17
|
-
static fiat_to_millicent(fiat: number): number
|
|
18
|
-
{
|
|
19
|
-
return Math.floor(fiat * 100 * 1000);
|
|
20
|
-
}
|
|
1
|
+
export class PriceOperation
|
|
2
|
+
{
|
|
3
|
+
static millicent_to_cent(millicent: number): number
|
|
4
|
+
{
|
|
5
|
+
return Math.round(millicent / 1000);
|
|
6
|
+
}
|
|
7
|
+
static millicent_to_fiat(millicent: number, decimal: number = 2): number
|
|
8
|
+
{
|
|
9
|
+
let thousand = Math.max(5 - decimal, 0);
|
|
10
|
+
let hundred = 5 - thousand;
|
|
11
|
+
return Math.round(millicent / Math.pow(10, thousand)) / Math.pow(10, hundred);
|
|
12
|
+
}
|
|
13
|
+
static cent_to_millicent(cent: number): number
|
|
14
|
+
{
|
|
15
|
+
return Math.floor(cent * 1000);
|
|
16
|
+
}
|
|
17
|
+
static fiat_to_millicent(fiat: number): number
|
|
18
|
+
{
|
|
19
|
+
return Math.floor(fiat * 100 * 1000);
|
|
20
|
+
}
|
|
21
21
|
}
|
package/src/SearchOperation.ts
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
export class SearchOperation
|
|
2
|
-
{
|
|
3
|
-
static getTokens(search: string): string[]
|
|
4
|
-
{
|
|
5
|
-
return search.split(' ').filter(x => x.trim()).map(x => x.toLowerCase());
|
|
6
|
-
}
|
|
7
|
-
static match(value: string | null, search: string, tokens: string[] = []): boolean
|
|
8
|
-
{
|
|
9
|
-
if (search)
|
|
10
|
-
{
|
|
11
|
-
if (!value)
|
|
12
|
-
return false;
|
|
13
|
-
if (tokens.length == 0)
|
|
14
|
-
tokens = search.split(' ').filter(x => x.trim()).map(x => x.toLowerCase());
|
|
15
|
-
let name = value.toLowerCase();
|
|
16
|
-
for (let i = 0; i < tokens.length; i++)
|
|
17
|
-
if (!name.toLowerCase().includes(tokens[i]))
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
static filter<T>(array: T[], getValue: (item: T) => string, search: string): T[]
|
|
23
|
-
{
|
|
24
|
-
let ans = array;
|
|
25
|
-
if (search)
|
|
26
|
-
{
|
|
27
|
-
let tokens = this.getTokens(search);
|
|
28
|
-
ans = ans.filter((item) => SearchOperation.match(getValue(item), search, tokens));
|
|
29
|
-
}
|
|
30
|
-
return ans;
|
|
31
|
-
}
|
|
1
|
+
export class SearchOperation
|
|
2
|
+
{
|
|
3
|
+
static getTokens(search: string): string[]
|
|
4
|
+
{
|
|
5
|
+
return search.split(' ').filter(x => x.trim()).map(x => x.toLowerCase());
|
|
6
|
+
}
|
|
7
|
+
static match(value: string | null, search: string, tokens: string[] = []): boolean
|
|
8
|
+
{
|
|
9
|
+
if (search)
|
|
10
|
+
{
|
|
11
|
+
if (!value)
|
|
12
|
+
return false;
|
|
13
|
+
if (tokens.length == 0)
|
|
14
|
+
tokens = search.split(' ').filter(x => x.trim()).map(x => x.toLowerCase());
|
|
15
|
+
let name = value.toLowerCase();
|
|
16
|
+
for (let i = 0; i < tokens.length; i++)
|
|
17
|
+
if (!name.toLowerCase().includes(tokens[i]))
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
static filter<T>(array: T[], getValue: (item: T) => string, search: string): T[]
|
|
23
|
+
{
|
|
24
|
+
let ans = array;
|
|
25
|
+
if (search)
|
|
26
|
+
{
|
|
27
|
+
let tokens = this.getTokens(search);
|
|
28
|
+
ans = ans.filter((item) => SearchOperation.match(getValue(item), search, tokens));
|
|
29
|
+
}
|
|
30
|
+
return ans;
|
|
31
|
+
}
|
|
32
32
|
}
|
package/src/SetTimeouService.ts
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { TimeOperation } from "./TimeOperation";
|
|
2
|
-
|
|
3
|
-
export class SetTimeouService
|
|
4
|
-
{
|
|
5
|
-
private last_date: Date = new Date();
|
|
6
|
-
private last_index: number = 0;
|
|
7
|
-
private onCalled(milliseconds: number)
|
|
8
|
-
{
|
|
9
|
-
this.last_index++;
|
|
10
|
-
let l = TimeOperation.millisecondsLater(milliseconds - 1, new Date());
|
|
11
|
-
if (this.last_date < l)
|
|
12
|
-
this.last_date = l;
|
|
13
|
-
return this.last_index;
|
|
14
|
-
}
|
|
15
|
-
setTimeoutIfNotCalledAgain(callback: () => void, milliseconds: number)
|
|
16
|
-
{
|
|
17
|
-
let index = this.onCalled(milliseconds);
|
|
18
|
-
setTimeout(() =>
|
|
19
|
-
{
|
|
20
|
-
if (index === this.last_index)
|
|
21
|
-
callback();
|
|
22
|
-
}, milliseconds);
|
|
23
|
-
}
|
|
24
|
-
setTimeoutIfFarArrival(callback: () => void, milliseconds: number)
|
|
25
|
-
{
|
|
26
|
-
this.onCalled(milliseconds);
|
|
27
|
-
setTimeout(() =>
|
|
28
|
-
{
|
|
29
|
-
if (this.last_date < new Date())
|
|
30
|
-
callback();
|
|
31
|
-
}, milliseconds);
|
|
32
|
-
}
|
|
1
|
+
import { TimeOperation } from "./TimeOperation";
|
|
2
|
+
|
|
3
|
+
export class SetTimeouService
|
|
4
|
+
{
|
|
5
|
+
private last_date: Date = new Date();
|
|
6
|
+
private last_index: number = 0;
|
|
7
|
+
private onCalled(milliseconds: number)
|
|
8
|
+
{
|
|
9
|
+
this.last_index++;
|
|
10
|
+
let l = TimeOperation.millisecondsLater(milliseconds - 1, new Date());
|
|
11
|
+
if (this.last_date < l)
|
|
12
|
+
this.last_date = l;
|
|
13
|
+
return this.last_index;
|
|
14
|
+
}
|
|
15
|
+
setTimeoutIfNotCalledAgain(callback: () => void, milliseconds: number)
|
|
16
|
+
{
|
|
17
|
+
let index = this.onCalled(milliseconds);
|
|
18
|
+
setTimeout(() =>
|
|
19
|
+
{
|
|
20
|
+
if (index === this.last_index)
|
|
21
|
+
callback();
|
|
22
|
+
}, milliseconds);
|
|
23
|
+
}
|
|
24
|
+
setTimeoutIfFarArrival(callback: () => void, milliseconds: number)
|
|
25
|
+
{
|
|
26
|
+
this.onCalled(milliseconds);
|
|
27
|
+
setTimeout(() =>
|
|
28
|
+
{
|
|
29
|
+
if (this.last_date < new Date())
|
|
30
|
+
callback();
|
|
31
|
+
}, milliseconds);
|
|
32
|
+
}
|
|
33
33
|
}
|
package/src/SortItem.ts
CHANGED
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
import { BaseMetaColumn } from "./BaseMetaColumn";
|
|
2
|
-
import { BaseMetaTable } from "./BaseMetaTable";
|
|
3
|
-
import { EncodingOperation } from "./EncodingOperation";
|
|
4
|
-
import { ErrorOperation } from "./ErrorOperation";
|
|
5
|
-
|
|
6
|
-
export class SortItem
|
|
7
|
-
{
|
|
8
|
-
public table: BaseMetaTable;
|
|
9
|
-
public column: BaseMetaColumn;
|
|
10
|
-
public ascending: boolean;
|
|
11
|
-
public static encode(sorts: SortItem[] | null): string
|
|
12
|
-
{
|
|
13
|
-
let value = this.stringify(sorts);
|
|
14
|
-
return EncodingOperation.Base64Encode(value);
|
|
15
|
-
}
|
|
16
|
-
public static decode(value: string): SortItem[] | null
|
|
17
|
-
{
|
|
18
|
-
let encoded = EncodingOperation.Base64Decode(value);
|
|
19
|
-
return this.parse(encoded);
|
|
20
|
-
}
|
|
21
|
-
public static stringify(sorts: SortItem[] | null): string
|
|
22
|
-
{
|
|
23
|
-
if (sorts)
|
|
24
|
-
return sorts.map(x => x.getCommand()).join(";");
|
|
25
|
-
return "";
|
|
26
|
-
}
|
|
27
|
-
public static parse(item: string | null): SortItem[]
|
|
28
|
-
{
|
|
29
|
-
let ans: SortItem[] = [];
|
|
30
|
-
if (item)
|
|
31
|
-
{
|
|
32
|
-
let index = 0;
|
|
33
|
-
let items = item.split(/(?<!\\);/);
|
|
34
|
-
let thereIsMore = (): boolean =>
|
|
35
|
-
{
|
|
36
|
-
return index < items.length;
|
|
37
|
-
};
|
|
38
|
-
let next = (name: string): string =>
|
|
39
|
-
{
|
|
40
|
-
if (thereIsMore())
|
|
41
|
-
return items[index++];
|
|
42
|
-
throw ErrorOperation.getHTTP(400, `Next value is required for '${name}'. Must be separated by ;`);
|
|
43
|
-
};
|
|
44
|
-
while (thereIsMore())
|
|
45
|
-
{
|
|
46
|
-
let value_table = next("Table");
|
|
47
|
-
let table = new BaseMetaTable(null, value_table, value_table);
|
|
48
|
-
|
|
49
|
-
let value_column = next("Column");
|
|
50
|
-
let column = new BaseMetaColumn(table, value_column, value_column, "", false)
|
|
51
|
-
|
|
52
|
-
let value_asc = next("Asending").toLowerCase();
|
|
53
|
-
let asc = value_asc === "asc"
|
|
54
|
-
if (value_asc != "asc" && value_asc != "desc")
|
|
55
|
-
ErrorOperation.throwHTTP(400, `Invalid value '${value_asc}' for SortItem.Asending, Only 'Asc' and 'Desc' are allowed.`);
|
|
56
|
-
|
|
57
|
-
ans.push(new SortItem(table, column, asc));
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return ans;
|
|
61
|
-
}
|
|
62
|
-
constructor(table: BaseMetaTable, column: BaseMetaColumn, ascending: boolean)
|
|
63
|
-
{
|
|
64
|
-
this.table = table;
|
|
65
|
-
this.column = column;
|
|
66
|
-
this.ascending = ascending;
|
|
67
|
-
}
|
|
68
|
-
getCommand()
|
|
69
|
-
{
|
|
70
|
-
return [this.table.name, this.column.name, this.ascending ? "asc" : "desc"].join(";");
|
|
71
|
-
}
|
|
72
|
-
toString()
|
|
73
|
-
{
|
|
74
|
-
let ans = [];
|
|
75
|
-
if (this.table.text)
|
|
76
|
-
ans.push(this.table.text);
|
|
77
|
-
else
|
|
78
|
-
ans.push(this.table.name);
|
|
79
|
-
if (this.column.text)
|
|
80
|
-
ans.push(this.column.text);
|
|
81
|
-
else
|
|
82
|
-
ans.push(this.column.name);
|
|
83
|
-
if (this.ascending)
|
|
84
|
-
ans.push("Ascending");
|
|
85
|
-
else
|
|
86
|
-
ans.push("Descending");
|
|
87
|
-
return ans.filter(x => x).join(" ");
|
|
88
|
-
}
|
|
1
|
+
import { BaseMetaColumn } from "./BaseMetaColumn";
|
|
2
|
+
import { BaseMetaTable } from "./BaseMetaTable";
|
|
3
|
+
import { EncodingOperation } from "./EncodingOperation";
|
|
4
|
+
import { ErrorOperation } from "./ErrorOperation";
|
|
5
|
+
|
|
6
|
+
export class SortItem
|
|
7
|
+
{
|
|
8
|
+
public table: BaseMetaTable;
|
|
9
|
+
public column: BaseMetaColumn;
|
|
10
|
+
public ascending: boolean;
|
|
11
|
+
public static encode(sorts: SortItem[] | null): string
|
|
12
|
+
{
|
|
13
|
+
let value = this.stringify(sorts);
|
|
14
|
+
return EncodingOperation.Base64Encode(value);
|
|
15
|
+
}
|
|
16
|
+
public static decode(value: string): SortItem[] | null
|
|
17
|
+
{
|
|
18
|
+
let encoded = EncodingOperation.Base64Decode(value);
|
|
19
|
+
return this.parse(encoded);
|
|
20
|
+
}
|
|
21
|
+
public static stringify(sorts: SortItem[] | null): string
|
|
22
|
+
{
|
|
23
|
+
if (sorts)
|
|
24
|
+
return sorts.map(x => x.getCommand()).join(";");
|
|
25
|
+
return "";
|
|
26
|
+
}
|
|
27
|
+
public static parse(item: string | null): SortItem[]
|
|
28
|
+
{
|
|
29
|
+
let ans: SortItem[] = [];
|
|
30
|
+
if (item)
|
|
31
|
+
{
|
|
32
|
+
let index = 0;
|
|
33
|
+
let items = item.split(/(?<!\\);/);
|
|
34
|
+
let thereIsMore = (): boolean =>
|
|
35
|
+
{
|
|
36
|
+
return index < items.length;
|
|
37
|
+
};
|
|
38
|
+
let next = (name: string): string =>
|
|
39
|
+
{
|
|
40
|
+
if (thereIsMore())
|
|
41
|
+
return items[index++];
|
|
42
|
+
throw ErrorOperation.getHTTP(400, `Next value is required for '${name}'. Must be separated by ;`);
|
|
43
|
+
};
|
|
44
|
+
while (thereIsMore())
|
|
45
|
+
{
|
|
46
|
+
let value_table = next("Table");
|
|
47
|
+
let table = new BaseMetaTable(null, value_table, value_table);
|
|
48
|
+
|
|
49
|
+
let value_column = next("Column");
|
|
50
|
+
let column = new BaseMetaColumn(table, value_column, value_column, "", false)
|
|
51
|
+
|
|
52
|
+
let value_asc = next("Asending").toLowerCase();
|
|
53
|
+
let asc = value_asc === "asc"
|
|
54
|
+
if (value_asc != "asc" && value_asc != "desc")
|
|
55
|
+
ErrorOperation.throwHTTP(400, `Invalid value '${value_asc}' for SortItem.Asending, Only 'Asc' and 'Desc' are allowed.`);
|
|
56
|
+
|
|
57
|
+
ans.push(new SortItem(table, column, asc));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return ans;
|
|
61
|
+
}
|
|
62
|
+
constructor(table: BaseMetaTable, column: BaseMetaColumn, ascending: boolean)
|
|
63
|
+
{
|
|
64
|
+
this.table = table;
|
|
65
|
+
this.column = column;
|
|
66
|
+
this.ascending = ascending;
|
|
67
|
+
}
|
|
68
|
+
getCommand()
|
|
69
|
+
{
|
|
70
|
+
return [this.table.name, this.column.name, this.ascending ? "asc" : "desc"].join(";");
|
|
71
|
+
}
|
|
72
|
+
toString()
|
|
73
|
+
{
|
|
74
|
+
let ans = [];
|
|
75
|
+
if (this.table.text)
|
|
76
|
+
ans.push(this.table.text);
|
|
77
|
+
else
|
|
78
|
+
ans.push(this.table.name);
|
|
79
|
+
if (this.column.text)
|
|
80
|
+
ans.push(this.column.text);
|
|
81
|
+
else
|
|
82
|
+
ans.push(this.column.name);
|
|
83
|
+
if (this.ascending)
|
|
84
|
+
ans.push("Ascending");
|
|
85
|
+
else
|
|
86
|
+
ans.push("Descending");
|
|
87
|
+
return ans.filter(x => x).join(" ");
|
|
88
|
+
}
|
|
89
89
|
}
|
package/src/StringOperation.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
export class StringOperation
|
|
2
|
-
{
|
|
3
|
-
static split(text: string): string[]
|
|
4
|
-
{
|
|
5
|
-
return text.split(/[\s;,|]+/).filter(x => x);
|
|
6
|
-
}
|
|
7
|
-
static format(string: string, ...args: string[]): string
|
|
8
|
-
{
|
|
9
|
-
return string.replace(/{(\d+)}/g, (match, index) =>
|
|
10
|
-
{
|
|
11
|
-
const arg = args[index];
|
|
12
|
-
return typeof arg !== 'undefined' ? arg : match;
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
static repair(value: string): string
|
|
16
|
-
{
|
|
17
|
-
if (value == null)
|
|
18
|
-
value = '';
|
|
19
|
-
value = value.replace(/\s\s+/gm, ' ');
|
|
20
|
-
value = value.trim();
|
|
21
|
-
return value;
|
|
22
|
-
}
|
|
1
|
+
export class StringOperation
|
|
2
|
+
{
|
|
3
|
+
static split(text: string): string[]
|
|
4
|
+
{
|
|
5
|
+
return text.split(/[\s;,|]+/).filter(x => x);
|
|
6
|
+
}
|
|
7
|
+
static format(string: string, ...args: string[]): string
|
|
8
|
+
{
|
|
9
|
+
return string.replace(/{(\d+)}/g, (match, index) =>
|
|
10
|
+
{
|
|
11
|
+
const arg = args[index];
|
|
12
|
+
return typeof arg !== 'undefined' ? arg : match;
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
static repair(value: string): string
|
|
16
|
+
{
|
|
17
|
+
if (value == null)
|
|
18
|
+
value = '';
|
|
19
|
+
value = value.replace(/\s\s+/gm, ' ');
|
|
20
|
+
value = value.trim();
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
23
|
}
|