namirasoft-core 1.4.12 → 1.4.13
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/dist/EncryptionOperation.js +17 -7
- package/dist/EncryptionOperation.js.map +1 -1
- package/dist/HashOperation.js +17 -7
- package/dist/HashOperation.js.map +1 -1
- package/dist/PhoneOperation.js +17 -7
- package/dist/PhoneOperation.js.map +1 -1
- package/dist/SortItem.d.ts +24 -0
- package/dist/SortItem.js +75 -0
- package/dist/SortItem.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/BaseDatabaseRow.ts +6 -6
- package/src/BaseMetaColumn.ts +13 -13
- package/src/BaseMetaTable.ts +24 -24
- package/src/BaseServer.ts +107 -107
- package/src/CacheService.ts +57 -57
- package/src/ConsoleOperation.ts +68 -68
- package/src/ConvertService.ts +100 -100
- 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/EncodingOperation.ts +12 -12
- package/src/EncryptionOperation.ts +40 -40
- package/src/EnvService.ts +22 -22
- package/src/ErrorOperation.ts +13 -13
- package/src/FileOperation.ts +57 -57
- package/src/FilterItem.ts +128 -128
- package/src/FilterItemColumnType.ts +6 -6
- package/src/FilterItemOperator.ts +51 -51
- package/src/GeoOperation.ts +18 -18
- package/src/HTTPError.ts +8 -8
- package/src/HTTPMethod.ts +6 -6
- package/src/HashOperation.ts +24 -24
- 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/IStorageMemory.ts +17 -17
- package/src/NamingConvention.ts +107 -107
- package/src/ObjectService.ts +27 -27
- package/src/PackageService.ts +76 -76
- package/src/PhoneOperation.ts +8 -8
- package/src/PriceOperation.ts +18 -18
- package/src/RegexTemplate.ts +7 -7
- package/src/SearchOperation.ts +29 -29
- package/src/SortItem.ts +89 -0
- package/src/StringOperation.ts +18 -18
- package/src/TimeOperation.ts +262 -262
- package/src/URLOperation.ts +54 -54
- package/src/VersionOperation.ts +46 -46
- package/src/index.ts +40 -39
package/src/RegexTemplate.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export class RegexTemplate
|
|
2
|
-
{
|
|
3
|
-
static Date: RegExp = /^(?!0000)[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12][0-9]|3[01])$/gm;
|
|
4
|
-
static Time: RegExp = /^([01]\d|2[0-3]):([0-5]\d)$/gm;
|
|
5
|
-
static Duration: RegExp = /^(\d+d\s)?([01]\d|2[0-3]):([0-5]\d)$/gm;
|
|
6
|
-
static Email: RegExp = /^[\w\._-]+@([\w]+\.)+\w{2,}$/gm;
|
|
7
|
-
static IP: RegExp = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/gm;
|
|
1
|
+
export class RegexTemplate
|
|
2
|
+
{
|
|
3
|
+
static Date: RegExp = /^(?!0000)[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12][0-9]|3[01])$/gm;
|
|
4
|
+
static Time: RegExp = /^([01]\d|2[0-3]):([0-5]\d)$/gm;
|
|
5
|
+
static Duration: RegExp = /^(\d+d\s)?([01]\d|2[0-3]):([0-5]\d)$/gm;
|
|
6
|
+
static Email: RegExp = /^[\w\._-]+@([\w]+\.)+\w{2,}$/gm;
|
|
7
|
+
static IP: RegExp = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/gm;
|
|
8
8
|
}
|
package/src/SearchOperation.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
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, search: string, tokens: string[] = []): boolean
|
|
8
|
-
{
|
|
9
|
-
if (search)
|
|
10
|
-
{
|
|
11
|
-
if (tokens.length == 0)
|
|
12
|
-
tokens = search.split(' ').filter(x => x.trim()).map(x => x.toLowerCase());
|
|
13
|
-
let name = value.toLowerCase();
|
|
14
|
-
for (let i = 0; i < tokens.length; i++)
|
|
15
|
-
if (!name.toLowerCase().includes(tokens[i]))
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
static filter<T>(array: T[], getValue: (item: T) => string, search: string): T[]
|
|
21
|
-
{
|
|
22
|
-
let ans = array;
|
|
23
|
-
if (search)
|
|
24
|
-
{
|
|
25
|
-
let tokens = this.getTokens(search);
|
|
26
|
-
ans = ans.filter((item) => SearchOperation.match(getValue(item), search, tokens));
|
|
27
|
-
}
|
|
28
|
-
return ans;
|
|
29
|
-
}
|
|
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, search: string, tokens: string[] = []): boolean
|
|
8
|
+
{
|
|
9
|
+
if (search)
|
|
10
|
+
{
|
|
11
|
+
if (tokens.length == 0)
|
|
12
|
+
tokens = search.split(' ').filter(x => x.trim()).map(x => x.toLowerCase());
|
|
13
|
+
let name = value.toLowerCase();
|
|
14
|
+
for (let i = 0; i < tokens.length; i++)
|
|
15
|
+
if (!name.toLowerCase().includes(tokens[i]))
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
static filter<T>(array: T[], getValue: (item: T) => string, search: string): T[]
|
|
21
|
+
{
|
|
22
|
+
let ans = array;
|
|
23
|
+
if (search)
|
|
24
|
+
{
|
|
25
|
+
let tokens = this.getTokens(search);
|
|
26
|
+
ans = ans.filter((item) => SearchOperation.match(getValue(item), search, tokens));
|
|
27
|
+
}
|
|
28
|
+
return ans;
|
|
29
|
+
}
|
|
30
30
|
}
|
package/src/SortItem.ts
ADDED
|
@@ -0,0 +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: { name: string; text: string; };
|
|
9
|
+
public column: { name: string; text: string; };
|
|
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(value_table, value_table);
|
|
48
|
+
|
|
49
|
+
let value_column = next("Column");
|
|
50
|
+
let column = new BaseMetaColumn(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: { name: string; text: string; }, column: { name: string; text: string; }, 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
|
+
}
|
package/src/StringOperation.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
export class StringOperation
|
|
2
|
-
{
|
|
3
|
-
static format(string: string, ...args: string[]): string
|
|
4
|
-
{
|
|
5
|
-
return string.replace(/{(\d+)}/g, (match, index) =>
|
|
6
|
-
{
|
|
7
|
-
const arg = args[index];
|
|
8
|
-
return typeof arg !== 'undefined' ? arg : match;
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
static repair(value: string): string
|
|
12
|
-
{
|
|
13
|
-
if (value == null)
|
|
14
|
-
value = '';
|
|
15
|
-
value = value.replace(/\s\s+/gm, ' ');
|
|
16
|
-
value = value.trim();
|
|
17
|
-
return value;
|
|
18
|
-
}
|
|
1
|
+
export class StringOperation
|
|
2
|
+
{
|
|
3
|
+
static format(string: string, ...args: string[]): string
|
|
4
|
+
{
|
|
5
|
+
return string.replace(/{(\d+)}/g, (match, index) =>
|
|
6
|
+
{
|
|
7
|
+
const arg = args[index];
|
|
8
|
+
return typeof arg !== 'undefined' ? arg : match;
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
static repair(value: string): string
|
|
12
|
+
{
|
|
13
|
+
if (value == null)
|
|
14
|
+
value = '';
|
|
15
|
+
value = value.replace(/\s\s+/gm, ' ');
|
|
16
|
+
value = value.trim();
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
19
|
}
|