@aidc-toolkit/core 1.0.24-beta → 1.0.26-beta
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/index.d.ts +21 -170
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -128
- package/dist/index.js.map +1 -1
- package/dist/locale/i18n.d.ts +56 -0
- package/dist/locale/i18n.d.ts.map +1 -0
- package/dist/locale/i18n.js +97 -0
- package/dist/locale/i18n.js.map +1 -0
- package/dist/logger.d.ts +32 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +41 -0
- package/dist/logger.js.map +1 -0
- package/dist/type-helper.d.ts +71 -0
- package/dist/type-helper.d.ts.map +1 -0
- package/dist/type-helper.js +113 -0
- package/dist/type-helper.js.map +1 -0
- package/dist/type.d.ts +69 -0
- package/dist/type.d.ts.map +1 -0
- package/dist/type.js +2 -0
- package/dist/type.js.map +1 -0
- package/package.json +10 -6
- package/src/index.ts +4 -4
- package/src/locale/i18n.ts +6 -1
- package/src/logger.ts +8 -3
- package/src/type-helper.ts +33 -3
- package/src/type.ts +41 -10
- package/tsconfig-config.json +4 -0
- package/tsconfig-src.json +8 -0
- package/tsconfig.json +9 -1
- package/tsup.config.ts +3 -2
- package/dist/index.cjs +0 -173
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -170
package/dist/index.d.ts
CHANGED
|
@@ -1,170 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*/
|
|
23
|
-
type Nullishable<T> = T | null | undefined;
|
|
24
|
-
/**
|
|
25
|
-
* Non-nullishable type. If T is an object type, it is spread and attributes within it are made non-nullishable.
|
|
26
|
-
* Equivalent to a deep `Required\<T\>` for an object and `NonNullable\<T\>` for any other type.
|
|
27
|
-
*/
|
|
28
|
-
type NonNullishable<T> = T extends object ? {
|
|
29
|
-
[P in keyof T]-?: NonNullishable<T[P]>;
|
|
30
|
-
} : NonNullable<T>;
|
|
31
|
-
/**
|
|
32
|
-
* Make some keys within a type optional.
|
|
33
|
-
*/
|
|
34
|
-
type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
35
|
-
/**
|
|
36
|
-
* Type to restrict property keys to those that are strings and that support a specified type.
|
|
37
|
-
*/
|
|
38
|
-
type PropertyKeys<T, TProperty> = {
|
|
39
|
-
[K in keyof T]: K extends string ? T[K] extends TProperty ? K : never : never;
|
|
40
|
-
}[keyof T];
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Create an object with omitted entries.
|
|
44
|
-
*
|
|
45
|
-
* @param o
|
|
46
|
-
* Object.
|
|
47
|
-
*
|
|
48
|
-
* @param keys
|
|
49
|
-
* Keys to omit.
|
|
50
|
-
*
|
|
51
|
-
* @returns
|
|
52
|
-
* Edited object.
|
|
53
|
-
*/
|
|
54
|
-
declare function omit<T extends object, K extends keyof T>(o: T, ...keys: K[]): Omit<T, K>;
|
|
55
|
-
/**
|
|
56
|
-
* Create an object with picked entries.
|
|
57
|
-
*
|
|
58
|
-
* @param o
|
|
59
|
-
* Object.
|
|
60
|
-
*
|
|
61
|
-
* @param keys
|
|
62
|
-
* Keys to pick.
|
|
63
|
-
*
|
|
64
|
-
* @returns
|
|
65
|
-
* Edited object.
|
|
66
|
-
*/
|
|
67
|
-
declare function pick<T extends object, K extends keyof T>(o: T, ...keys: K[]): Pick<T, K>;
|
|
68
|
-
/**
|
|
69
|
-
* Cast a property as a more narrow type.
|
|
70
|
-
*
|
|
71
|
-
* @param o
|
|
72
|
-
* Object.
|
|
73
|
-
*
|
|
74
|
-
* @param key
|
|
75
|
-
* Key of property to cast.
|
|
76
|
-
*
|
|
77
|
-
* @returns
|
|
78
|
-
* Single-key object with property cast as desired type.
|
|
79
|
-
*/
|
|
80
|
-
declare function propertyAs<TAsType extends T[K], T extends object, K extends keyof T>(o: T, key: K): Readonly<Omit<T, K> extends T ? Partial<Record<K, TAsType>> : Record<K, TAsType>>;
|
|
81
|
-
/**
|
|
82
|
-
* Determine if argument is nullish. Application extension may pass `null` or `undefined` to missing parameters.
|
|
83
|
-
*
|
|
84
|
-
* @param argument
|
|
85
|
-
* Argument.
|
|
86
|
-
*
|
|
87
|
-
* @returns
|
|
88
|
-
* True if argument is undefined or null.
|
|
89
|
-
*/
|
|
90
|
-
declare function isNullish<T>(argument: T | null | undefined): argument is null | undefined;
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Log levels.
|
|
94
|
-
*/
|
|
95
|
-
declare const LogLevels: {
|
|
96
|
-
readonly Silly: 0;
|
|
97
|
-
readonly Trace: 1;
|
|
98
|
-
readonly Debug: 2;
|
|
99
|
-
readonly Info: 3;
|
|
100
|
-
readonly Warn: 4;
|
|
101
|
-
readonly Error: 5;
|
|
102
|
-
readonly Fatal: 6;
|
|
103
|
-
};
|
|
104
|
-
/**
|
|
105
|
-
* Log level.
|
|
106
|
-
*/
|
|
107
|
-
type LogLevel = typeof LogLevels[keyof typeof LogLevels];
|
|
108
|
-
/**
|
|
109
|
-
* Get a simple logger with an optional log level.
|
|
110
|
-
*
|
|
111
|
-
* @param logLevel
|
|
112
|
-
* Log level as enumeration value or string if any.
|
|
113
|
-
*
|
|
114
|
-
* @returns
|
|
115
|
-
* Logger.
|
|
116
|
-
*/
|
|
117
|
-
declare function getLogger(logLevel?: string | number): Logger<unknown>;
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Locale strings type for generic manipulation.
|
|
121
|
-
*/
|
|
122
|
-
interface LocaleResources {
|
|
123
|
-
[key: string]: LocaleResources | string;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Internationalization operating environments.
|
|
127
|
-
*/
|
|
128
|
-
declare const I18nEnvironments: {
|
|
129
|
-
/**
|
|
130
|
-
* Command-line interface (e.g., unit tests).
|
|
131
|
-
*/
|
|
132
|
-
readonly CLI: 0;
|
|
133
|
-
/**
|
|
134
|
-
* Web server.
|
|
135
|
-
*/
|
|
136
|
-
readonly Server: 1;
|
|
137
|
-
/**
|
|
138
|
-
* Web browser.
|
|
139
|
-
*/
|
|
140
|
-
readonly Browser: 2;
|
|
141
|
-
};
|
|
142
|
-
/**
|
|
143
|
-
* Internationalization operating environment.
|
|
144
|
-
*/
|
|
145
|
-
type I18nEnvironment = typeof I18nEnvironments[keyof typeof I18nEnvironments];
|
|
146
|
-
/**
|
|
147
|
-
* Initialize internationalization.
|
|
148
|
-
*
|
|
149
|
-
* @param i18next
|
|
150
|
-
* Internationalization object. As multiple objects exists, this parameter represents the one for the module for which
|
|
151
|
-
* internationalization is being initialized.
|
|
152
|
-
*
|
|
153
|
-
* @param environment
|
|
154
|
-
* Environment in which the application is running.
|
|
155
|
-
*
|
|
156
|
-
* @param debug
|
|
157
|
-
* Debug setting.
|
|
158
|
-
*
|
|
159
|
-
* @param defaultNS
|
|
160
|
-
* Default namespace.
|
|
161
|
-
*
|
|
162
|
-
* @param resources
|
|
163
|
-
* Resources.
|
|
164
|
-
*
|
|
165
|
-
* @returns
|
|
166
|
-
* Void promise.
|
|
167
|
-
*/
|
|
168
|
-
declare function i18nCoreInit(i18next: i18n, environment: I18nEnvironment, debug: boolean, defaultNS: string, ...resources: Resource[]): Promise<void>;
|
|
169
|
-
|
|
170
|
-
export { type I18nEnvironment, I18nEnvironments, type LocaleResources, type LogLevel, LogLevels, type NonNullishable, type Nullishable, type Optional, type PropertyKeys, type TypedAsyncFunction, type TypedFunction, type TypedSyncFunction, getLogger, i18nCoreInit, isNullish, omit, pick, propertyAs };
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright © 2024-2025 Dolphin Data Development Ltd. and AIDC Toolkit
|
|
3
|
+
* contributors
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
export type * from "./type.js";
|
|
18
|
+
export * from "./type-helper.js";
|
|
19
|
+
export * from "./logger.js";
|
|
20
|
+
export * from "./locale/i18n.js";
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,mBAAmB,WAAW,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,129 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
function omit(o, ...keys) {
|
|
6
|
-
return omitOrPick(true, o, ...keys);
|
|
7
|
-
}
|
|
8
|
-
function pick(o, ...keys) {
|
|
9
|
-
return omitOrPick(false, o, ...keys);
|
|
10
|
-
}
|
|
11
|
-
function propertyAs(o, key) {
|
|
12
|
-
return key in o ? {
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Force cast.
|
|
14
|
-
[key]: o[key]
|
|
15
|
-
} : {};
|
|
16
|
-
}
|
|
17
|
-
function isNullish(argument) {
|
|
18
|
-
return argument === null || argument === void 0;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// src/logger.ts
|
|
22
|
-
import { Logger } from "tslog";
|
|
23
|
-
var LogLevels = {
|
|
24
|
-
Silly: 0,
|
|
25
|
-
Trace: 1,
|
|
26
|
-
Debug: 2,
|
|
27
|
-
Info: 3,
|
|
28
|
-
Warn: 4,
|
|
29
|
-
Error: 5,
|
|
30
|
-
Fatal: 6
|
|
31
|
-
};
|
|
32
|
-
function getLogger(logLevel) {
|
|
33
|
-
let minLevel;
|
|
34
|
-
if (typeof logLevel === "string") {
|
|
35
|
-
if (logLevel in LogLevels) {
|
|
36
|
-
minLevel = LogLevels[logLevel];
|
|
37
|
-
} else {
|
|
38
|
-
throw new Error(`Unknown log level ${logLevel}`);
|
|
39
|
-
}
|
|
40
|
-
} else {
|
|
41
|
-
minLevel = logLevel ?? LogLevels.Info;
|
|
42
|
-
}
|
|
43
|
-
return new Logger({
|
|
44
|
-
minLevel
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// src/locale/i18n.ts
|
|
49
|
-
import I18nextBrowserLanguageDetector from "i18next-browser-languagedetector";
|
|
50
|
-
import I18nextCLILanguageDetector from "i18next-cli-language-detector";
|
|
51
|
-
var I18nEnvironments = {
|
|
52
|
-
/**
|
|
53
|
-
* Command-line interface (e.g., unit tests).
|
|
54
|
-
*/
|
|
55
|
-
CLI: 0,
|
|
56
|
-
/**
|
|
57
|
-
* Web server.
|
|
58
|
-
*/
|
|
59
|
-
Server: 1,
|
|
60
|
-
/**
|
|
61
|
-
* Web browser.
|
|
62
|
-
*/
|
|
63
|
-
Browser: 2
|
|
64
|
-
};
|
|
65
|
-
function toLowerCase(s) {
|
|
66
|
-
return s.split(" ").map((word) => /[a-z]/.test(word) ? word.toLowerCase() : word).join(" ");
|
|
67
|
-
}
|
|
68
|
-
async function i18nCoreInit(i18next, environment, debug, defaultNS, ...resources) {
|
|
69
|
-
if (!i18next.isInitialized) {
|
|
70
|
-
const mergedResource = {};
|
|
71
|
-
for (const resource of resources) {
|
|
72
|
-
for (const [language, resourceLanguage] of Object.entries(resource)) {
|
|
73
|
-
if (!(language in mergedResource)) {
|
|
74
|
-
mergedResource[language] = {};
|
|
75
|
-
}
|
|
76
|
-
const mergedResourceLanguage = mergedResource[language];
|
|
77
|
-
for (const [namespace, resourceKey] of Object.entries(resourceLanguage)) {
|
|
78
|
-
mergedResourceLanguage[namespace] = resourceKey;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
let module;
|
|
83
|
-
switch (environment) {
|
|
84
|
-
case I18nEnvironments.CLI:
|
|
85
|
-
module = I18nextCLILanguageDetector;
|
|
86
|
-
break;
|
|
87
|
-
case I18nEnvironments.Browser:
|
|
88
|
-
module = I18nextBrowserLanguageDetector;
|
|
89
|
-
break;
|
|
90
|
-
default:
|
|
91
|
-
throw new Error("Not supported");
|
|
92
|
-
}
|
|
93
|
-
await i18next.use(module).init({
|
|
94
|
-
debug,
|
|
95
|
-
resources: mergedResource,
|
|
96
|
-
fallbackLng: "en",
|
|
97
|
-
defaultNS
|
|
98
|
-
}).then(() => {
|
|
99
|
-
i18next.services.formatter?.add("toLowerCase", (value) => typeof value === "string" ? toLowerCase(value) : String(value));
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
export {
|
|
104
|
-
I18nEnvironments,
|
|
105
|
-
LogLevels,
|
|
106
|
-
getLogger,
|
|
107
|
-
i18nCoreInit,
|
|
108
|
-
isNullish,
|
|
109
|
-
omit,
|
|
110
|
-
pick,
|
|
111
|
-
propertyAs
|
|
112
|
-
};
|
|
113
|
-
/*!
|
|
114
|
-
* Copyright © 2024-2025 Dolphin Data Development Ltd. and AIDC Toolkit
|
|
115
|
-
* contributors
|
|
116
|
-
*
|
|
117
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
118
|
-
* you may not use this file except in compliance with the License.
|
|
119
|
-
* You may obtain a copy of the License at
|
|
120
|
-
*
|
|
121
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
122
|
-
*
|
|
123
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
124
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
125
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
126
|
-
* See the License for the specific language governing permissions and
|
|
127
|
-
* limitations under the License.
|
|
128
|
-
*/
|
|
1
|
+
export * from "./type-helper.js";
|
|
2
|
+
export * from "./logger.js";
|
|
3
|
+
export * from "./locale/i18n.js";
|
|
129
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAiBA,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { i18n, Resource } from "i18next";
|
|
2
|
+
/**
|
|
3
|
+
* Locale strings type for generic manipulation.
|
|
4
|
+
*/
|
|
5
|
+
export interface LocaleResources {
|
|
6
|
+
[key: string]: LocaleResources | string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Internationalization operating environments.
|
|
10
|
+
*/
|
|
11
|
+
export declare const I18nEnvironments: {
|
|
12
|
+
/**
|
|
13
|
+
* Command-line interface (e.g., unit tests).
|
|
14
|
+
*/
|
|
15
|
+
readonly CLI: 0;
|
|
16
|
+
/**
|
|
17
|
+
* Web server.
|
|
18
|
+
*/
|
|
19
|
+
readonly Server: 1;
|
|
20
|
+
/**
|
|
21
|
+
* Web browser.
|
|
22
|
+
*/
|
|
23
|
+
readonly Browser: 2;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Internationalization operating environment key.
|
|
27
|
+
*/
|
|
28
|
+
export type I18nEnvironmentKey = keyof typeof I18nEnvironments;
|
|
29
|
+
/**
|
|
30
|
+
* Internationalization operating environment.
|
|
31
|
+
*/
|
|
32
|
+
export type I18nEnvironment = typeof I18nEnvironments[I18nEnvironmentKey];
|
|
33
|
+
/**
|
|
34
|
+
* Initialize internationalization.
|
|
35
|
+
*
|
|
36
|
+
* @param i18next
|
|
37
|
+
* Internationalization object. As multiple objects exists, this parameter represents the one for the module for which
|
|
38
|
+
* internationalization is being initialized.
|
|
39
|
+
*
|
|
40
|
+
* @param environment
|
|
41
|
+
* Environment in which the application is running.
|
|
42
|
+
*
|
|
43
|
+
* @param debug
|
|
44
|
+
* Debug setting.
|
|
45
|
+
*
|
|
46
|
+
* @param defaultNS
|
|
47
|
+
* Default namespace.
|
|
48
|
+
*
|
|
49
|
+
* @param resources
|
|
50
|
+
* Resources.
|
|
51
|
+
*
|
|
52
|
+
* @returns
|
|
53
|
+
* Void promise.
|
|
54
|
+
*/
|
|
55
|
+
export declare function i18nCoreInit(i18next: i18n, environment: I18nEnvironment, debug: boolean, defaultNS: string, ...resources: Resource[]): Promise<void>;
|
|
56
|
+
//# sourceMappingURL=i18n.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../../src/locale/i18n.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAA0B,QAAQ,EAAE,MAAM,SAAS,CAAC;AAItE;;GAEG;AACH,MAAM,WAAW,eAAe;IAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,GAAG,MAAM,CAAC;CAC3C;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB;IACzB;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;CAEG,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,OAAO,gBAAgB,CAAC;AAE/D;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,OAAO,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;AAgB1E;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,eAAe,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,SAAS,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAiD1J"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import I18nextBrowserLanguageDetector from "i18next-browser-languagedetector";
|
|
2
|
+
import I18nextCLILanguageDetector from "i18next-cli-language-detector";
|
|
3
|
+
/**
|
|
4
|
+
* Internationalization operating environments.
|
|
5
|
+
*/
|
|
6
|
+
export const I18nEnvironments = {
|
|
7
|
+
/**
|
|
8
|
+
* Command-line interface (e.g., unit tests).
|
|
9
|
+
*/
|
|
10
|
+
CLI: 0,
|
|
11
|
+
/**
|
|
12
|
+
* Web server.
|
|
13
|
+
*/
|
|
14
|
+
Server: 1,
|
|
15
|
+
/**
|
|
16
|
+
* Web browser.
|
|
17
|
+
*/
|
|
18
|
+
Browser: 2
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Convert a string to lower case, skipping words that are all upper case.
|
|
22
|
+
*
|
|
23
|
+
* @param s
|
|
24
|
+
* String.
|
|
25
|
+
*
|
|
26
|
+
* @returns
|
|
27
|
+
* Lower case string.
|
|
28
|
+
*/
|
|
29
|
+
function toLowerCase(s) {
|
|
30
|
+
// Words with no lower case letters are preserved as they are likely mnemonics.
|
|
31
|
+
return s.split(" ").map(word => /[a-z]/.test(word) ? word.toLowerCase() : word).join(" ");
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Initialize internationalization.
|
|
35
|
+
*
|
|
36
|
+
* @param i18next
|
|
37
|
+
* Internationalization object. As multiple objects exists, this parameter represents the one for the module for which
|
|
38
|
+
* internationalization is being initialized.
|
|
39
|
+
*
|
|
40
|
+
* @param environment
|
|
41
|
+
* Environment in which the application is running.
|
|
42
|
+
*
|
|
43
|
+
* @param debug
|
|
44
|
+
* Debug setting.
|
|
45
|
+
*
|
|
46
|
+
* @param defaultNS
|
|
47
|
+
* Default namespace.
|
|
48
|
+
*
|
|
49
|
+
* @param resources
|
|
50
|
+
* Resources.
|
|
51
|
+
*
|
|
52
|
+
* @returns
|
|
53
|
+
* Void promise.
|
|
54
|
+
*/
|
|
55
|
+
export async function i18nCoreInit(i18next, environment, debug, defaultNS, ...resources) {
|
|
56
|
+
// Initialization may be called more than once.
|
|
57
|
+
if (!i18next.isInitialized) {
|
|
58
|
+
const mergedResource = {};
|
|
59
|
+
// Merge resources.
|
|
60
|
+
for (const resource of resources) {
|
|
61
|
+
// Merge languages.
|
|
62
|
+
for (const [language, resourceLanguage] of Object.entries(resource)) {
|
|
63
|
+
if (!(language in mergedResource)) {
|
|
64
|
+
mergedResource[language] = {};
|
|
65
|
+
}
|
|
66
|
+
const mergedResourceLanguage = mergedResource[language];
|
|
67
|
+
// Merge namespaces.
|
|
68
|
+
for (const [namespace, resourceKey] of Object.entries(resourceLanguage)) {
|
|
69
|
+
mergedResourceLanguage[namespace] = resourceKey;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
let module;
|
|
74
|
+
switch (environment) {
|
|
75
|
+
case I18nEnvironments.CLI:
|
|
76
|
+
// TODO Refactor when https://github.com/neet/i18next-cli-language-detector/issues/281 resolved.
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Per above.
|
|
78
|
+
module = I18nextCLILanguageDetector;
|
|
79
|
+
break;
|
|
80
|
+
case I18nEnvironments.Browser:
|
|
81
|
+
module = I18nextBrowserLanguageDetector;
|
|
82
|
+
break;
|
|
83
|
+
default:
|
|
84
|
+
throw new Error("Not supported");
|
|
85
|
+
}
|
|
86
|
+
await i18next.use(module).init({
|
|
87
|
+
debug,
|
|
88
|
+
resources: mergedResource,
|
|
89
|
+
fallbackLng: "en",
|
|
90
|
+
defaultNS
|
|
91
|
+
}).then(() => {
|
|
92
|
+
// Add toLowerCase function.
|
|
93
|
+
i18next.services.formatter?.add("toLowerCase", value => typeof value === "string" ? toLowerCase(value) : String(value));
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=i18n.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.js","sourceRoot":"","sources":["../../src/locale/i18n.ts"],"names":[],"mappings":"AACA,OAAO,8BAA8B,MAAM,kCAAkC,CAAC;AAC9E,OAAO,0BAA0B,MAAM,+BAA+B,CAAC;AASvE;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC5B;;OAEG;IACH,GAAG,EAAE,CAAC;IAEN;;OAEG;IACH,MAAM,EAAE,CAAC;IAET;;OAEG;IACH,OAAO,EAAE,CAAC;CACJ,CAAC;AAYX;;;;;;;;GAQG;AACH,SAAS,WAAW,CAAC,CAAS;IAC1B,+EAA+E;IAC/E,OAAO,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC9F,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,OAAa,EAAE,WAA4B,EAAE,KAAc,EAAE,SAAiB,EAAE,GAAG,SAAqB;IACvI,+CAA+C;IAC/C,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;QACzB,MAAM,cAAc,GAAa,EAAE,CAAC;QAEpC,mBAAmB;QACnB,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;YAC/B,mBAAmB;YACnB,KAAK,MAAM,CAAC,QAAQ,EAAE,gBAAgB,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAClE,IAAI,CAAC,CAAC,QAAQ,IAAI,cAAc,CAAC,EAAE,CAAC;oBAChC,cAAc,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;gBAClC,CAAC;gBAED,MAAM,sBAAsB,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;gBAExD,oBAAoB;gBACpB,KAAK,MAAM,CAAC,SAAS,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE,CAAC;oBACtE,sBAAsB,CAAC,SAAS,CAAC,GAAG,WAAW,CAAC;gBACpD,CAAC;YACL,CAAC;QACL,CAAC;QAED,IAAI,MAAyC,CAAC;QAE9C,QAAQ,WAAW,EAAE,CAAC;YAClB,KAAK,gBAAgB,CAAC,GAAG;gBACrB,gGAAgG;gBAChG,qFAAqF;gBACrF,MAAM,GAAG,0BAA+D,CAAC;gBACzE,MAAM;YAEV,KAAK,gBAAgB,CAAC,OAAO;gBACzB,MAAM,GAAG,8BAA8B,CAAC;gBACxC,MAAM;YAEV;gBACI,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;QACzC,CAAC;QAED,MAAM,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC;YAC3B,KAAK;YACL,SAAS,EAAE,cAAc;YACzB,WAAW,EAAE,IAAI;YACjB,SAAS;SACZ,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;YACT,4BAA4B;YAC5B,OAAO,CAAC,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAC5H,CAAC,CAAC,CAAC;IACP,CAAC;AACL,CAAC"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Logger } from "tslog";
|
|
2
|
+
/**
|
|
3
|
+
* Log levels.
|
|
4
|
+
*/
|
|
5
|
+
export declare const LogLevels: {
|
|
6
|
+
readonly Silly: 0;
|
|
7
|
+
readonly Trace: 1;
|
|
8
|
+
readonly Debug: 2;
|
|
9
|
+
readonly Info: 3;
|
|
10
|
+
readonly Warn: 4;
|
|
11
|
+
readonly Error: 5;
|
|
12
|
+
readonly Fatal: 6;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Log level key.
|
|
16
|
+
*/
|
|
17
|
+
export type LogLevelKey = keyof typeof LogLevels;
|
|
18
|
+
/**
|
|
19
|
+
* Log level.
|
|
20
|
+
*/
|
|
21
|
+
export type LogLevel = typeof LogLevels[LogLevelKey];
|
|
22
|
+
/**
|
|
23
|
+
* Get a simple logger with an optional log level.
|
|
24
|
+
*
|
|
25
|
+
* @param logLevel
|
|
26
|
+
* Log level as enumeration value or string.
|
|
27
|
+
*
|
|
28
|
+
* @returns
|
|
29
|
+
* Logger.
|
|
30
|
+
*/
|
|
31
|
+
export declare function getLogger(logLevel?: string | number): Logger<unknown>;
|
|
32
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE/B;;GAEG;AACH,eAAO,MAAM,SAAS;;;;;;;;CAQZ,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,OAAO,SAAS,CAAC;AAEjD;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,SAAS,CAAC,WAAW,CAAC,CAAC;AAErD;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,CAiBrE"}
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Logger } from "tslog";
|
|
2
|
+
/**
|
|
3
|
+
* Log levels.
|
|
4
|
+
*/
|
|
5
|
+
export const LogLevels = {
|
|
6
|
+
Silly: 0,
|
|
7
|
+
Trace: 1,
|
|
8
|
+
Debug: 2,
|
|
9
|
+
Info: 3,
|
|
10
|
+
Warn: 4,
|
|
11
|
+
Error: 5,
|
|
12
|
+
Fatal: 6
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Get a simple logger with an optional log level.
|
|
16
|
+
*
|
|
17
|
+
* @param logLevel
|
|
18
|
+
* Log level as enumeration value or string.
|
|
19
|
+
*
|
|
20
|
+
* @returns
|
|
21
|
+
* Logger.
|
|
22
|
+
*/
|
|
23
|
+
export function getLogger(logLevel) {
|
|
24
|
+
let minLevel;
|
|
25
|
+
if (typeof logLevel === "string") {
|
|
26
|
+
if (logLevel in LogLevels) {
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- String exists as a key.
|
|
28
|
+
minLevel = LogLevels[logLevel];
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
throw new Error(`Unknown log level ${logLevel}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
minLevel = logLevel ?? LogLevels.Info;
|
|
36
|
+
}
|
|
37
|
+
return new Logger({
|
|
38
|
+
minLevel
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE/B;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;IACrB,KAAK,EAAE,CAAC;IACR,KAAK,EAAE,CAAC;IACR,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;IACR,KAAK,EAAE,CAAC;CACF,CAAC;AAYX;;;;;;;;GAQG;AACH,MAAM,UAAU,SAAS,CAAC,QAA0B;IAChD,IAAI,QAAgB,CAAC;IAErB,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC/B,IAAI,QAAQ,IAAI,SAAS,EAAE,CAAC;YACxB,kGAAkG;YAClG,QAAQ,GAAG,SAAS,CAAC,QAAuB,CAAC,CAAC;QAClD,CAAC;aAAM,CAAC;YACJ,MAAM,IAAI,KAAK,CAAC,qBAAqB,QAAQ,EAAE,CAAC,CAAC;QACrD,CAAC;IACL,CAAC;SAAM,CAAC;QACJ,QAAQ,GAAG,QAAQ,IAAI,SAAS,CAAC,IAAI,CAAC;IAC1C,CAAC;IAED,OAAO,IAAI,MAAM,CAAC;QACd,QAAQ;KACX,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create an object with omitted entries.
|
|
3
|
+
*
|
|
4
|
+
* @template T
|
|
5
|
+
* Object type.
|
|
6
|
+
*
|
|
7
|
+
* @template K
|
|
8
|
+
* Object key type.
|
|
9
|
+
*
|
|
10
|
+
* @param o
|
|
11
|
+
* Object.
|
|
12
|
+
*
|
|
13
|
+
* @param keys
|
|
14
|
+
* Keys to omit.
|
|
15
|
+
*
|
|
16
|
+
* @returns
|
|
17
|
+
* Edited object.
|
|
18
|
+
*/
|
|
19
|
+
export declare function omit<T extends object, K extends keyof T>(o: T, ...keys: K[]): Omit<T, K>;
|
|
20
|
+
/**
|
|
21
|
+
* Create an object with picked entries.
|
|
22
|
+
*
|
|
23
|
+
* @template T
|
|
24
|
+
* Object type.
|
|
25
|
+
*
|
|
26
|
+
* @template K
|
|
27
|
+
* Object key type.
|
|
28
|
+
*
|
|
29
|
+
* @param o
|
|
30
|
+
* Object.
|
|
31
|
+
*
|
|
32
|
+
* @param keys
|
|
33
|
+
* Keys to pick.
|
|
34
|
+
*
|
|
35
|
+
* @returns
|
|
36
|
+
* Edited object.
|
|
37
|
+
*/
|
|
38
|
+
export declare function pick<T extends object, K extends keyof T>(o: T, ...keys: K[]): Pick<T, K>;
|
|
39
|
+
/**
|
|
40
|
+
* Cast a property as a more narrow type.
|
|
41
|
+
*
|
|
42
|
+
* @template T
|
|
43
|
+
* Object type.
|
|
44
|
+
*
|
|
45
|
+
* @template K
|
|
46
|
+
* Object key type.
|
|
47
|
+
*
|
|
48
|
+
* @template TAsType
|
|
49
|
+
* Desired type.
|
|
50
|
+
*
|
|
51
|
+
* @param o
|
|
52
|
+
* Object.
|
|
53
|
+
*
|
|
54
|
+
* @param key
|
|
55
|
+
* Key of property to cast.
|
|
56
|
+
*
|
|
57
|
+
* @returns
|
|
58
|
+
* Single-key object with property cast as desired type.
|
|
59
|
+
*/
|
|
60
|
+
export declare function propertyAs<T extends object, K extends keyof T, TAsType extends T[K]>(o: T, key: K): Readonly<Omit<T, K> extends T ? Partial<Record<K, TAsType>> : Record<K, TAsType>>;
|
|
61
|
+
/**
|
|
62
|
+
* Determine if argument is nullish. Application extension may pass `null` or `undefined` to missing parameters.
|
|
63
|
+
*
|
|
64
|
+
* @param argument
|
|
65
|
+
* Argument.
|
|
66
|
+
*
|
|
67
|
+
* @returns
|
|
68
|
+
* True if argument is undefined or null.
|
|
69
|
+
*/
|
|
70
|
+
export declare function isNullish(argument: unknown): argument is null | undefined;
|
|
71
|
+
//# sourceMappingURL=type-helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-helper.d.ts","sourceRoot":"","sources":["../src/type-helper.ts"],"names":[],"mappings":"AA6BA;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAExF;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAExF;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CASrL;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,IAAI,IAAI,GAAG,SAAS,CAEzE"}
|