jopi-toolkit 3.0.5
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/README.md +6 -0
- package/dist/jk_app/common.d.ts +40 -0
- package/dist/jk_app/common.js +313 -0
- package/dist/jk_app/common.js.map +1 -0
- package/dist/jk_app/index.d.ts +1 -0
- package/dist/jk_app/index.js +4 -0
- package/dist/jk_app/index.js.map +1 -0
- package/dist/jk_app/jBundler_ifBrowser.d.ts +1 -0
- package/dist/jk_app/jBundler_ifBrowser.js +3 -0
- package/dist/jk_app/jBundler_ifBrowser.js.map +1 -0
- package/dist/jk_app/jBundler_ifServer.d.ts +1 -0
- package/dist/jk_app/jBundler_ifServer.js +9 -0
- package/dist/jk_app/jBundler_ifServer.js.map +1 -0
- package/dist/jk_appResolver/common.d.ts +40 -0
- package/dist/jk_appResolver/common.js +306 -0
- package/dist/jk_appResolver/common.js.map +1 -0
- package/dist/jk_appResolver/index.d.ts +30 -0
- package/dist/jk_appResolver/index.js +276 -0
- package/dist/jk_appResolver/index.js.map +1 -0
- package/dist/jk_appResolver/jBundler_ifBrowser.d.ts +1 -0
- package/dist/jk_appResolver/jBundler_ifBrowser.js +3 -0
- package/dist/jk_appResolver/jBundler_ifBrowser.js.map +1 -0
- package/dist/jk_appResolver/jBundler_ifServer.d.ts +1 -0
- package/dist/jk_appResolver/jBundler_ifServer.js +9 -0
- package/dist/jk_appResolver/jBundler_ifServer.js.map +1 -0
- package/dist/jk_compress/index.d.ts +1 -0
- package/dist/jk_compress/index.js +2 -0
- package/dist/jk_compress/index.js.map +1 -0
- package/dist/jk_compress/jBundler_ifBrowser.d.ts +2 -0
- package/dist/jk_compress/jBundler_ifBrowser.js +3 -0
- package/dist/jk_compress/jBundler_ifBrowser.js.map +1 -0
- package/dist/jk_compress/jBundler_ifServer.d.ts +5 -0
- package/dist/jk_compress/jBundler_ifServer.js +11 -0
- package/dist/jk_compress/jBundler_ifServer.js.map +1 -0
- package/dist/jk_crypto/index.d.ts +1 -0
- package/dist/jk_crypto/index.js +2 -0
- package/dist/jk_crypto/index.js.map +1 -0
- package/dist/jk_crypto/jBundler_ifBrowser.d.ts +2 -0
- package/dist/jk_crypto/jBundler_ifBrowser.js +3 -0
- package/dist/jk_crypto/jBundler_ifBrowser.js.map +1 -0
- package/dist/jk_crypto/jBundler_ifServer.d.ts +5 -0
- package/dist/jk_crypto/jBundler_ifServer.js +17 -0
- package/dist/jk_crypto/jBundler_ifServer.js.map +1 -0
- package/dist/jk_events/index.d.ts +35 -0
- package/dist/jk_events/index.js +134 -0
- package/dist/jk_events/index.js.map +1 -0
- package/dist/jk_fs/common.d.ts +16 -0
- package/dist/jk_fs/common.js +2 -0
- package/dist/jk_fs/common.js.map +1 -0
- package/dist/jk_fs/index.d.ts +2 -0
- package/dist/jk_fs/index.js +3 -0
- package/dist/jk_fs/index.js.map +1 -0
- package/dist/jk_fs/jBundler_ifBrowser.d.ts +41 -0
- package/dist/jk_fs/jBundler_ifBrowser.js +88 -0
- package/dist/jk_fs/jBundler_ifBrowser.js.map +1 -0
- package/dist/jk_fs/jBundler_ifServer.d.ts +48 -0
- package/dist/jk_fs/jBundler_ifServer.js +286 -0
- package/dist/jk_fs/jBundler_ifServer.js.map +1 -0
- package/dist/jk_linker/TypeComposite.d.ts +12 -0
- package/dist/jk_linker/TypeComposite.js +112 -0
- package/dist/jk_linker/TypeComposite.js.map +1 -0
- package/dist/jk_linker/arobaseType_List.d.ts +44 -0
- package/dist/jk_linker/arobaseType_List.js +183 -0
- package/dist/jk_linker/arobaseType_List.js.map +1 -0
- package/dist/jk_linker/arobaseTypes.d.ts +45 -0
- package/dist/jk_linker/arobaseTypes.js +181 -0
- package/dist/jk_linker/arobaseTypes.js.map +1 -0
- package/dist/jk_linker/binding.d.ts +1 -0
- package/dist/jk_linker/binding.js +13 -0
- package/dist/jk_linker/binding.js.map +1 -0
- package/dist/jk_linker/engine.d.ts +119 -0
- package/dist/jk_linker/engine.js +553 -0
- package/dist/jk_linker/engine.js.map +1 -0
- package/dist/jk_linker/index.d.ts +1 -0
- package/dist/jk_linker/index.js +2 -0
- package/dist/jk_linker/index.js.map +1 -0
- package/dist/jk_linker/install.d.ts +4 -0
- package/dist/jk_linker/install.js +44 -0
- package/dist/jk_linker/install.js.map +1 -0
- package/dist/jk_linker/jBundler_ifServer.d.ts +3 -0
- package/dist/jk_linker/jBundler_ifServer.js +4 -0
- package/dist/jk_linker/jBundler_ifServer.js.map +1 -0
- package/dist/jk_linker/modulesInitProcessor.d.ts +7 -0
- package/dist/jk_linker/modulesInitProcessor.js +36 -0
- package/dist/jk_linker/modulesInitProcessor.js.map +1 -0
- package/dist/jk_linker/typeChunks.d.ts +15 -0
- package/dist/jk_linker/typeChunks.js +42 -0
- package/dist/jk_linker/typeChunks.js.map +1 -0
- package/dist/jk_linker/typeComposites.d.ts +13 -0
- package/dist/jk_linker/typeComposites.js +121 -0
- package/dist/jk_linker/typeComposites.js.map +1 -0
- package/dist/jk_linker/typeEvents.d.ts +5 -0
- package/dist/jk_linker/typeEvents.js +29 -0
- package/dist/jk_linker/typeEvents.js.map +1 -0
- package/dist/jk_linker/typeList.d.ts +30 -0
- package/dist/jk_linker/typeList.js +144 -0
- package/dist/jk_linker/typeList.js.map +1 -0
- package/dist/jk_linker/typeListeners.d.ts +21 -0
- package/dist/jk_linker/typeListeners.js +188 -0
- package/dist/jk_linker/typeListeners.js.map +1 -0
- package/dist/jk_linker/typeReplaces.d.ts +8 -0
- package/dist/jk_linker/typeReplaces.js +41 -0
- package/dist/jk_linker/typeReplaces.js.map +1 -0
- package/dist/jk_os/index.d.ts +1 -0
- package/dist/jk_os/index.js +2 -0
- package/dist/jk_os/index.js.map +1 -0
- package/dist/jk_os/jBundler_ifBrowser.d.ts +3 -0
- package/dist/jk_os/jBundler_ifBrowser.js +10 -0
- package/dist/jk_os/jBundler_ifBrowser.js.map +1 -0
- package/dist/jk_os/jBundler_ifServer.d.ts +2 -0
- package/dist/jk_os/jBundler_ifServer.js +64 -0
- package/dist/jk_os/jBundler_ifServer.js.map +1 -0
- package/dist/jk_process/index.d.ts +1 -0
- package/dist/jk_process/index.js +2 -0
- package/dist/jk_process/index.js.map +1 -0
- package/dist/jk_process/jBundler_ifBrowser.d.ts +4 -0
- package/dist/jk_process/jBundler_ifBrowser.js +21 -0
- package/dist/jk_process/jBundler_ifBrowser.js.map +1 -0
- package/dist/jk_process/jBundler_ifServer.d.ts +4 -0
- package/dist/jk_process/jBundler_ifServer.js +5 -0
- package/dist/jk_process/jBundler_ifServer.js.map +1 -0
- package/dist/jk_registry/index.d.ts +11 -0
- package/dist/jk_registry/index.js +36 -0
- package/dist/jk_registry/index.js.map +1 -0
- package/dist/jk_schemas/index.d.ts +118 -0
- package/dist/jk_schemas/index.js +220 -0
- package/dist/jk_schemas/index.js.map +1 -0
- package/dist/jk_streams/index.d.ts +1 -0
- package/dist/jk_streams/index.js +6 -0
- package/dist/jk_streams/index.js.map +1 -0
- package/dist/jk_term/index.d.ts +51 -0
- package/dist/jk_term/index.js +102 -0
- package/dist/jk_term/index.js.map +1 -0
- package/dist/jk_thread/common.d.ts +3 -0
- package/dist/jk_thread/common.js +8 -0
- package/dist/jk_thread/common.js.map +1 -0
- package/dist/jk_thread/index.d.ts +2 -0
- package/dist/jk_thread/index.js +3 -0
- package/dist/jk_thread/index.js.map +1 -0
- package/dist/jk_thread/jBundler_ifBrowser.d.ts +6 -0
- package/dist/jk_thread/jBundler_ifBrowser.js +15 -0
- package/dist/jk_thread/jBundler_ifBrowser.js.map +1 -0
- package/dist/jk_thread/jBundler_ifServer.d.ts +6 -0
- package/dist/jk_thread/jBundler_ifServer.js +22 -0
- package/dist/jk_thread/jBundler_ifServer.js.map +1 -0
- package/dist/jk_timer/index.d.ts +26 -0
- package/dist/jk_timer/index.js +100 -0
- package/dist/jk_timer/index.js.map +1 -0
- package/dist/jk_tools/index.d.ts +20 -0
- package/dist/jk_tools/index.js +72 -0
- package/dist/jk_tools/index.js.map +1 -0
- package/dist/jk_translate/index.d.ts +21 -0
- package/dist/jk_translate/index.js +56 -0
- package/dist/jk_translate/index.js.map +1 -0
- package/dist/jk_webSocket/common.d.ts +2 -0
- package/dist/jk_webSocket/common.js +7 -0
- package/dist/jk_webSocket/common.js.map +1 -0
- package/dist/jk_webSocket/index.d.ts +2 -0
- package/dist/jk_webSocket/index.js +3 -0
- package/dist/jk_webSocket/index.js.map +1 -0
- package/dist/jk_webSocket/jBundler_ifBrowser.ts.d.ts +3 -0
- package/dist/jk_webSocket/jBundler_ifBrowser.ts.js +14 -0
- package/dist/jk_webSocket/jBundler_ifBrowser.ts.js.map +1 -0
- package/dist/jk_webSocket/jBundler_ifServer.d.ts +7 -0
- package/dist/jk_webSocket/jBundler_ifServer.js +41 -0
- package/dist/jk_webSocket/jBundler_ifServer.js.map +1 -0
- package/dist/jk_what/index.d.ts +1 -0
- package/dist/jk_what/index.js +2 -0
- package/dist/jk_what/index.js.map +1 -0
- package/dist/jk_what/jBundler_ifBrowser.d.ts +5 -0
- package/dist/jk_what/jBundler_ifBrowser.js +6 -0
- package/dist/jk_what/jBundler_ifBrowser.js.map +1 -0
- package/dist/jk_what/jBundler_ifServer.d.ts +5 -0
- package/dist/jk_what/jBundler_ifServer.js +6 -0
- package/dist/jk_what/jBundler_ifServer.js.map +1 -0
- package/package.json +100 -0
- package/src/jk_app/common.js +442 -0
- package/src/jk_app/common.ts +389 -0
- package/src/jk_app/index.js +3 -0
- package/src/jk_app/index.ts +4 -0
- package/src/jk_app/jBundler_ifBrowser.ts +2 -0
- package/src/jk_app/jBundler_ifServer.js +8 -0
- package/src/jk_app/jBundler_ifServer.ts +11 -0
- package/src/jk_compress/index.js +1 -0
- package/src/jk_compress/index.ts +1 -0
- package/src/jk_compress/jBundler_ifBrowser.ts +2 -0
- package/src/jk_compress/jBundler_ifServer.js +10 -0
- package/src/jk_compress/jBundler_ifServer.ts +16 -0
- package/src/jk_crypto/index.js +1 -0
- package/src/jk_crypto/index.ts +1 -0
- package/src/jk_crypto/jBundler_ifBrowser.ts +2 -0
- package/src/jk_crypto/jBundler_ifServer.ts +21 -0
- package/src/jk_events/index.js +203 -0
- package/src/jk_events/index.ts +168 -0
- package/src/jk_fs/common.js +1 -0
- package/src/jk_fs/common.ts +20 -0
- package/src/jk_fs/index.js +2 -0
- package/src/jk_fs/index.ts +2 -0
- package/src/jk_fs/jBundler_ifBrowser.ts +116 -0
- package/src/jk_fs/jBundler_ifServer.ts +308 -0
- package/src/jk_os/index.js +1 -0
- package/src/jk_os/index.ts +1 -0
- package/src/jk_os/jBundler_ifBrowser.ts +11 -0
- package/src/jk_os/jBundler_ifServer.js +132 -0
- package/src/jk_os/jBundler_ifServer.ts +63 -0
- package/src/jk_process/index.ts +1 -0
- package/src/jk_process/jBundler_ifBrowser.ts +20 -0
- package/src/jk_process/jBundler_ifServer.ts +4 -0
- package/src/jk_schemas/TODO.txt +7 -0
- package/src/jk_schemas/index.js +248 -0
- package/src/jk_schemas/index.ts +416 -0
- package/src/jk_streams/index.ts +6 -0
- package/src/jk_term/index.js +146 -0
- package/src/jk_term/index.ts +131 -0
- package/src/jk_thread/common.ts +9 -0
- package/src/jk_thread/index.js +2 -0
- package/src/jk_thread/index.ts +2 -0
- package/src/jk_thread/jBundler_ifBrowser.ts +18 -0
- package/src/jk_thread/jBundler_ifServer.js +21 -0
- package/src/jk_thread/jBundler_ifServer.ts +28 -0
- package/src/jk_timer/index.js +155 -0
- package/src/jk_timer/index.ts +150 -0
- package/src/jk_tools/index.js +82 -0
- package/src/jk_tools/index.ts +82 -0
- package/src/jk_translate/index.js +56 -0
- package/src/jk_translate/index.ts +85 -0
- package/src/jk_webSocket/common.js +6 -0
- package/src/jk_webSocket/common.ts +7 -0
- package/src/jk_webSocket/index.js +2 -0
- package/src/jk_webSocket/index.ts +2 -0
- package/src/jk_webSocket/jBundler_ifBrowser.ts.ts +16 -0
- package/src/jk_webSocket/jBundler_ifServer.js +40 -0
- package/src/jk_webSocket/jBundler_ifServer.ts +57 -0
- package/src/jk_what/index.js +1 -0
- package/src/jk_what/index.ts +1 -0
- package/src/jk_what/jBundler_ifBrowser.ts +5 -0
- package/src/jk_what/jBundler_ifServer.ts +5 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
export function generateUUIDv4() {
|
|
13
|
+
if (typeof crypto !== 'undefined' && crypto.randomUUID) {
|
|
14
|
+
return crypto.randomUUID();
|
|
15
|
+
}
|
|
16
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
17
|
+
var r = Math.random() * 16 | 0;
|
|
18
|
+
var v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
19
|
+
return v.toString(16);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export function isUUIDv4(text) {
|
|
23
|
+
return /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(text);
|
|
24
|
+
}
|
|
25
|
+
export function getErrorMessage(e) {
|
|
26
|
+
if (e instanceof Error)
|
|
27
|
+
return e.message;
|
|
28
|
+
return "" + e;
|
|
29
|
+
}
|
|
30
|
+
export function applyDefaults(source, defaults) {
|
|
31
|
+
if (!source)
|
|
32
|
+
source = {};
|
|
33
|
+
return __assign(__assign({}, defaults), source);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Allow knowing the file path of the function calling us.
|
|
37
|
+
*/
|
|
38
|
+
export function getCallerFilePath() {
|
|
39
|
+
try {
|
|
40
|
+
throw new Error("");
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
var error = e;
|
|
44
|
+
if (!error.stack)
|
|
45
|
+
return undefined;
|
|
46
|
+
var stackLines = error.stack.split('\n');
|
|
47
|
+
if (stackLines.length < 4)
|
|
48
|
+
return undefined;
|
|
49
|
+
// Here we have something like:
|
|
50
|
+
// at file:///Users/johan/Projets/jopi-rewrite-workspace/__tests/jopi-ui-sample/dist/mod_sample/routes/tests/test3.page.js:4:1
|
|
51
|
+
//
|
|
52
|
+
var fileUrl = stackLines[3].trim();
|
|
53
|
+
var idx = fileUrl.indexOf("file://");
|
|
54
|
+
fileUrl = fileUrl.substring(idx);
|
|
55
|
+
idx = fileUrl.lastIndexOf(":");
|
|
56
|
+
fileUrl = fileUrl.substring(0, idx);
|
|
57
|
+
idx = fileUrl.lastIndexOf(":");
|
|
58
|
+
if (idx !== -1)
|
|
59
|
+
fileUrl = fileUrl.substring(0, idx);
|
|
60
|
+
return fileUrl;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export var PriorityLevel;
|
|
64
|
+
(function (PriorityLevel) {
|
|
65
|
+
PriorityLevel[PriorityLevel["veryLow"] = -200] = "veryLow";
|
|
66
|
+
PriorityLevel[PriorityLevel["low"] = -100] = "low";
|
|
67
|
+
PriorityLevel[PriorityLevel["default"] = 0] = "default";
|
|
68
|
+
PriorityLevel[PriorityLevel["high"] = 100] = "high";
|
|
69
|
+
PriorityLevel[PriorityLevel["veryHigh"] = 200] = "veryHigh";
|
|
70
|
+
})(PriorityLevel || (PriorityLevel = {}));
|
|
71
|
+
export function sortByPriority(values) {
|
|
72
|
+
if (values === undefined)
|
|
73
|
+
return undefined;
|
|
74
|
+
values.sort(function (a, b) {
|
|
75
|
+
if (a.priority < b.priority)
|
|
76
|
+
return -1;
|
|
77
|
+
if (a.priority > b.priority)
|
|
78
|
+
return 1;
|
|
79
|
+
return 0;
|
|
80
|
+
});
|
|
81
|
+
return values.map(function (v) { return v.value; });
|
|
82
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export function generateUUIDv4(): string {
|
|
2
|
+
if (typeof crypto !== 'undefined' && crypto.randomUUID) {
|
|
3
|
+
return crypto.randomUUID();
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
|
7
|
+
const r = Math.random() * 16 | 0;
|
|
8
|
+
const v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
9
|
+
return v.toString(16);
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function isUUIDv4(text: string): boolean {
|
|
14
|
+
return /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(text);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function getErrorMessage(e: unknown): string {
|
|
18
|
+
if (e instanceof Error) return e.message;
|
|
19
|
+
return "" + e;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function applyDefaults<T>(source: T|undefined, defaults: T): T {
|
|
23
|
+
if (!source) source = {} as T;
|
|
24
|
+
return {...defaults, ...source};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Allow knowing the file path of the function calling us.
|
|
29
|
+
*/
|
|
30
|
+
export function getCallerFilePath(): string|undefined {
|
|
31
|
+
try {
|
|
32
|
+
throw new Error("");
|
|
33
|
+
} catch (e: any) {
|
|
34
|
+
let error: Error = e;
|
|
35
|
+
|
|
36
|
+
if (!error.stack) return undefined;
|
|
37
|
+
|
|
38
|
+
const stackLines = error.stack.split('\n');
|
|
39
|
+
if (stackLines.length < 4) return undefined;
|
|
40
|
+
|
|
41
|
+
// Here we have something like:
|
|
42
|
+
// at file:///Users/johan/Projets/jopi-rewrite-workspace/__tests/jopi-ui-sample/dist/mod_sample/routes/tests/test3.page.js:4:1
|
|
43
|
+
//
|
|
44
|
+
let fileUrl = stackLines[3].trim();
|
|
45
|
+
|
|
46
|
+
let idx = fileUrl.indexOf("file://");
|
|
47
|
+
fileUrl = fileUrl.substring(idx);
|
|
48
|
+
|
|
49
|
+
idx = fileUrl.lastIndexOf(":");
|
|
50
|
+
fileUrl = fileUrl.substring(0, idx);
|
|
51
|
+
|
|
52
|
+
idx = fileUrl.lastIndexOf(":");
|
|
53
|
+
if (idx!==-1) fileUrl = fileUrl.substring(0, idx);
|
|
54
|
+
|
|
55
|
+
return fileUrl;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export enum PriorityLevel {
|
|
60
|
+
veryLow = -200,
|
|
61
|
+
low = -100,
|
|
62
|
+
default = 0,
|
|
63
|
+
high = 100,
|
|
64
|
+
veryHigh = 200,
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface ValueWithPriority<T> {
|
|
68
|
+
value: T;
|
|
69
|
+
priority: PriorityLevel;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function sortByPriority<T>(values: undefined|ValueWithPriority<T>[]): undefined|(T[]) {
|
|
73
|
+
if (values === undefined) return undefined;
|
|
74
|
+
|
|
75
|
+
values.sort((a, b) => {
|
|
76
|
+
if (a.priority < b.priority) return -1;
|
|
77
|
+
if (a.priority > b.priority) return 1;
|
|
78
|
+
return 0;
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
return values.map(v => v.value);
|
|
82
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
var gCurrentLanguage = 'en';
|
|
2
|
+
var gTranslations = {};
|
|
3
|
+
export function setLanguage(languageName) {
|
|
4
|
+
gCurrentLanguage = languageName;
|
|
5
|
+
}
|
|
6
|
+
export function translate(key, p) {
|
|
7
|
+
return translateTo(gCurrentLanguage, key, p);
|
|
8
|
+
}
|
|
9
|
+
export function translateTo(language, key, p) {
|
|
10
|
+
// Does it exist?
|
|
11
|
+
if (!gTranslations[language]) {
|
|
12
|
+
gTranslations[language] = {};
|
|
13
|
+
}
|
|
14
|
+
var translation;
|
|
15
|
+
// Must use plural?
|
|
16
|
+
//
|
|
17
|
+
var translationKey = key;
|
|
18
|
+
//
|
|
19
|
+
if ((p.count !== undefined) && (p.count > 1)) {
|
|
20
|
+
var pluralKey = "".concat(key, "_plural");
|
|
21
|
+
translation = gTranslations[language][pluralKey];
|
|
22
|
+
}
|
|
23
|
+
// Get the translation.
|
|
24
|
+
if (!translation) {
|
|
25
|
+
translation = gTranslations[language][translationKey];
|
|
26
|
+
}
|
|
27
|
+
// Not found?
|
|
28
|
+
if (!translation) {
|
|
29
|
+
if (p.default) {
|
|
30
|
+
gTranslations[language][translationKey] = p.default;
|
|
31
|
+
return p.default;
|
|
32
|
+
}
|
|
33
|
+
translation = "[trNotFound:".concat(key, "]");
|
|
34
|
+
}
|
|
35
|
+
// Replace the parameters in the translation.
|
|
36
|
+
if (p.params && translation.includes("$")) {
|
|
37
|
+
for (var _i = 0, _a = Object.entries(p.params); _i < _a.length; _i++) {
|
|
38
|
+
var _b = _a[_i], paramKey = _b[0], paramValue = _b[1];
|
|
39
|
+
var placeholder = "$" + paramKey;
|
|
40
|
+
translation = translation.replace(placeholder, String(paramValue));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return translation;
|
|
44
|
+
}
|
|
45
|
+
export function addTranslation(language, key, value) {
|
|
46
|
+
if (!gTranslations[language]) {
|
|
47
|
+
gTranslations[language] = {};
|
|
48
|
+
}
|
|
49
|
+
gTranslations[language][key] = value;
|
|
50
|
+
}
|
|
51
|
+
export function addTranslations(language, newTranslations) {
|
|
52
|
+
if (!gTranslations[language]) {
|
|
53
|
+
gTranslations[language] = {};
|
|
54
|
+
}
|
|
55
|
+
Object.assign(gTranslations[language], newTranslations);
|
|
56
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
let gCurrentLanguage = 'en';
|
|
2
|
+
const gTranslations: { [language: string]: { [key: string]: string } } = {};
|
|
3
|
+
|
|
4
|
+
export interface TranslationRequest {
|
|
5
|
+
/**
|
|
6
|
+
* The default value for the translation.
|
|
7
|
+
*/
|
|
8
|
+
default?: string;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The parameters to use for values with parameters
|
|
12
|
+
*/
|
|
13
|
+
params?: any;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* If 'count' is more than one, then use plural form.
|
|
17
|
+
*/
|
|
18
|
+
count?: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function setLanguage(languageName: string): void {
|
|
22
|
+
gCurrentLanguage = languageName;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function translate(key: string, p: TranslationRequest): string {
|
|
26
|
+
return translateTo(gCurrentLanguage, key, p);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function translateTo(language: string, key: string, p: TranslationRequest): string {
|
|
30
|
+
// Does it exist?
|
|
31
|
+
if (!gTranslations[language]) {
|
|
32
|
+
gTranslations[language] = {};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let translation: string | undefined;
|
|
36
|
+
|
|
37
|
+
// Must use plural?
|
|
38
|
+
//
|
|
39
|
+
let translationKey = key;
|
|
40
|
+
//
|
|
41
|
+
if ((p.count !== undefined) && (p.count > 1)) {
|
|
42
|
+
const pluralKey = `${key}_plural`;
|
|
43
|
+
translation = gTranslations[language][pluralKey]
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Get the translation.
|
|
47
|
+
if (!translation) {
|
|
48
|
+
translation = gTranslations[language][translationKey];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Not found?
|
|
52
|
+
if (!translation) {
|
|
53
|
+
if (p.default) {
|
|
54
|
+
gTranslations[language][translationKey] = p.default;
|
|
55
|
+
return p.default;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
translation = `[trNotFound:${key}]`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Replace the parameters in the translation.
|
|
62
|
+
if (p.params && translation.includes("$")) {
|
|
63
|
+
for (const [paramKey, paramValue] of Object.entries(p.params)) {
|
|
64
|
+
const placeholder = "$" + paramKey;
|
|
65
|
+
translation = translation.replace(placeholder, String(paramValue));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return translation;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function addTranslation(language: string, key: string, value: string): void {
|
|
73
|
+
if (!gTranslations[language]) {
|
|
74
|
+
gTranslations[language] = {};
|
|
75
|
+
}
|
|
76
|
+
gTranslations[language][key] = value;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function addTranslations(language: string, newTranslations: { [key: string]: string }): void {
|
|
80
|
+
if (!gTranslations[language]) {
|
|
81
|
+
gTranslations[language] = {};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
Object.assign(gTranslations[language], newTranslations);
|
|
85
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function openConnection(wsUrl: string, protocol?: string|string[]): Promise<WebSocket> {
|
|
2
|
+
return new Promise<WebSocket>((resolve, reject) => {
|
|
3
|
+
const ws = new WebSocket(wsUrl, protocol);
|
|
4
|
+
|
|
5
|
+
ws.onopen = () => { resolve(ws) };
|
|
6
|
+
ws.onerror = () => { reject(); };
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function onClosed(socket: WebSocket, listener: () => void): void {
|
|
11
|
+
socket.addEventListener('close', () => { listener() });
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function onMessage(socket: WebSocket, listener: ((msg: string|Buffer) => void)): void {
|
|
15
|
+
socket.addEventListener('message', (event) => { listener(event.data) });
|
|
16
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { WebSocket as WsWebSocket } from "ws";
|
|
2
|
+
import { isNodeJS } from "jopi-toolkit/jk_what";
|
|
3
|
+
//region openConnection
|
|
4
|
+
function node_openConnection(wsUrl, protocol) {
|
|
5
|
+
return new Promise(function (resolve, reject) {
|
|
6
|
+
var ws = new WsWebSocket(wsUrl, protocol);
|
|
7
|
+
var ws2 = ws;
|
|
8
|
+
ws.onopen = function () { resolve(ws2); };
|
|
9
|
+
ws.onerror = function () { reject(); };
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
function bun_openConnection(wsUrl, protocol) {
|
|
13
|
+
return new Promise(function (resolve, reject) {
|
|
14
|
+
var ws = new WebSocket(wsUrl, protocol);
|
|
15
|
+
ws.onopen = function () { resolve(ws); };
|
|
16
|
+
ws.onerror = function () { reject(); };
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export var openConnection = isNodeJS ? node_openConnection : bun_openConnection;
|
|
20
|
+
//endregion
|
|
21
|
+
//region onClose
|
|
22
|
+
function node_onClosed(socket, listener) {
|
|
23
|
+
socket.addEventListener('close', function () { listener(); });
|
|
24
|
+
}
|
|
25
|
+
function bun_onClosed(socket, listener) {
|
|
26
|
+
var data = (socket.data);
|
|
27
|
+
data.onClosed = listener;
|
|
28
|
+
}
|
|
29
|
+
export var onClosed = isNodeJS ? node_onClosed : bun_onClosed;
|
|
30
|
+
//endregion
|
|
31
|
+
//region onMessage
|
|
32
|
+
function node_onMessage(socket, listener) {
|
|
33
|
+
socket.addEventListener('message', function (event) { listener(event.data); });
|
|
34
|
+
}
|
|
35
|
+
function bun_onMessage(socket, listener) {
|
|
36
|
+
var data = (socket.data);
|
|
37
|
+
data.onMessage = listener;
|
|
38
|
+
}
|
|
39
|
+
export var onMessage = isNodeJS ? node_onMessage : bun_onMessage;
|
|
40
|
+
//endregion
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {WebSocket as WsWebSocket} from "ws";
|
|
2
|
+
import {isNodeJS} from "jopi-toolkit/jk_what";
|
|
3
|
+
|
|
4
|
+
//region openConnection
|
|
5
|
+
|
|
6
|
+
function node_openConnection(wsUrl: string, protocol?: string|string[]): Promise<WebSocket> {
|
|
7
|
+
return new Promise<WebSocket>((resolve, reject) => {
|
|
8
|
+
const ws = new WsWebSocket(wsUrl, protocol);
|
|
9
|
+
const ws2 = ws as unknown as WebSocket;
|
|
10
|
+
|
|
11
|
+
ws.onopen = () => { resolve(ws2) };
|
|
12
|
+
ws.onerror = () => { reject(); };
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function bun_openConnection(wsUrl: string, protocol?: string|string[]): Promise<WebSocket> {
|
|
17
|
+
return new Promise<WebSocket>((resolve, reject) => {
|
|
18
|
+
const ws = new WebSocket(wsUrl, protocol);
|
|
19
|
+
|
|
20
|
+
ws.onopen = () => { resolve(ws) };
|
|
21
|
+
ws.onerror = () => { reject(); };
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const openConnection = isNodeJS ? node_openConnection : bun_openConnection;
|
|
26
|
+
|
|
27
|
+
//endregion
|
|
28
|
+
|
|
29
|
+
//region onClose
|
|
30
|
+
|
|
31
|
+
function node_onClosed(socket: WebSocket, listener: () => void): void {
|
|
32
|
+
socket.addEventListener('close', () => { listener() });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function bun_onClosed(socket: WebSocket, listener: () => void): void {
|
|
36
|
+
const data = ((socket as any).data) as any;
|
|
37
|
+
data.onClosed = listener;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const onClosed = isNodeJS ? node_onClosed : bun_onClosed;
|
|
41
|
+
|
|
42
|
+
//endregion
|
|
43
|
+
|
|
44
|
+
//region onMessage
|
|
45
|
+
|
|
46
|
+
function node_onMessage(socket: WebSocket, listener: ((msg: string|Buffer) => void)): void {
|
|
47
|
+
socket.addEventListener('message', (event) => { listener(event.data) });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function bun_onMessage(socket: WebSocket, listener: ((msg: string|Buffer) => void)): void {
|
|
51
|
+
const data = ((socket as any).data) as any;
|
|
52
|
+
data.onMessage = listener;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const onMessage = isNodeJS ? node_onMessage : bun_onMessage;
|
|
56
|
+
|
|
57
|
+
//endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./jBundler_ifServer.ts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./jBundler_ifServer.ts";
|