@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.
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Create an object with omitted or picked entries.
3
+ *
4
+ * @template Omitting
5
+ * Type representation of `omitting` parameter for return type determination.
6
+ *
7
+ * @template T
8
+ * Object type.
9
+ *
10
+ * @template K
11
+ * Object key type.
12
+ *
13
+ * @param omitting
14
+ * True if omitting.
15
+ *
16
+ * @param o
17
+ * Object.
18
+ *
19
+ * @param keys
20
+ * Keys to omit or pick.
21
+ *
22
+ * @returns
23
+ * Edited object.
24
+ */
25
+ function omitOrPick(omitting, o, ...keys) {
26
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Key and value types are known.
27
+ return Object.fromEntries(Object.entries(o).filter(([key]) => keys.includes(key) !== omitting));
28
+ }
29
+ /**
30
+ * Create an object with omitted entries.
31
+ *
32
+ * @template T
33
+ * Object type.
34
+ *
35
+ * @template K
36
+ * Object key type.
37
+ *
38
+ * @param o
39
+ * Object.
40
+ *
41
+ * @param keys
42
+ * Keys to omit.
43
+ *
44
+ * @returns
45
+ * Edited object.
46
+ */
47
+ export function omit(o, ...keys) {
48
+ return omitOrPick(true, o, ...keys);
49
+ }
50
+ /**
51
+ * Create an object with picked entries.
52
+ *
53
+ * @template T
54
+ * Object type.
55
+ *
56
+ * @template K
57
+ * Object key type.
58
+ *
59
+ * @param o
60
+ * Object.
61
+ *
62
+ * @param keys
63
+ * Keys to pick.
64
+ *
65
+ * @returns
66
+ * Edited object.
67
+ */
68
+ export function pick(o, ...keys) {
69
+ return omitOrPick(false, o, ...keys);
70
+ }
71
+ /**
72
+ * Cast a property as a more narrow type.
73
+ *
74
+ * @template T
75
+ * Object type.
76
+ *
77
+ * @template K
78
+ * Object key type.
79
+ *
80
+ * @template TAsType
81
+ * Desired type.
82
+ *
83
+ * @param o
84
+ * Object.
85
+ *
86
+ * @param key
87
+ * Key of property to cast.
88
+ *
89
+ * @returns
90
+ * Single-key object with property cast as desired type.
91
+ */
92
+ export function propertyAs(o, key) {
93
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Type is determined by condition.
94
+ return (key in o ?
95
+ {
96
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Force cast.
97
+ [key]: o[key]
98
+ } :
99
+ {});
100
+ }
101
+ /**
102
+ * Determine if argument is nullish. Application extension may pass `null` or `undefined` to missing parameters.
103
+ *
104
+ * @param argument
105
+ * Argument.
106
+ *
107
+ * @returns
108
+ * True if argument is undefined or null.
109
+ */
110
+ export function isNullish(argument) {
111
+ return argument === null || argument === undefined;
112
+ }
113
+ //# sourceMappingURL=type-helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-helper.js","sourceRoot":"","sources":["../src/type-helper.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,SAAS,UAAU,CAAgE,QAAkB,EAAE,CAAI,EAAE,GAAG,IAAS;IACrH,yGAAyG;IACzG,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAQ,CAAC,KAAK,QAAQ,CAAC,CAAkD,CAAC;AAC1J,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,IAAI,CAAsC,CAAI,EAAE,GAAG,IAAS;IACxE,OAAO,UAAU,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;AACxC,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,IAAI,CAAsC,CAAI,EAAE,GAAG,IAAS;IACxE,OAAO,UAAU,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;AACzC,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,UAAU,CAA4D,CAAI,EAAE,GAAM;IAC9F,2GAA2G;IAC3G,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;QACd;YACI,sFAAsF;YACtF,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,CAAY;SAC3B,CAAC,CAAC;QACH,EAAE,CAC2C,CAAC;AACtD,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,SAAS,CAAC,QAAiB;IACvC,OAAO,QAAQ,KAAK,IAAI,IAAI,QAAQ,KAAK,SAAS,CAAC;AACvD,CAAC"}
package/dist/type.d.ts ADDED
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Typed function, applicable to any function, stricter than {@linkcode Function}.
3
+ *
4
+ * @template TFunction
5
+ * Function type.
6
+ */
7
+ export type TypedFunction<TFunction extends (...args: Parameters<TFunction>) => ReturnType<TFunction>> = (...args: Parameters<TFunction>) => ReturnType<TFunction>;
8
+ /**
9
+ * Typed synchronous function, applicable to any function that doesn't return a {@linkcode Promise}.
10
+ *
11
+ * @template TFunction
12
+ * Function type.
13
+ */
14
+ export type TypedSyncFunction<TFunction extends TypedFunction<TFunction>> = [ReturnType<TFunction>] extends [PromiseLike<unknown>] ? never : TypedFunction<TFunction>;
15
+ /**
16
+ * Determine the fundamental promised type. This is stricter than `Awaited<Type>` in that it requires a {@linkcode
17
+ * Promise}.
18
+ *
19
+ * @template T
20
+ * Promised type.
21
+ */
22
+ export type PromisedType<T> = [T] extends [PromiseLike<infer TPromised>] ? TPromised : never;
23
+ /**
24
+ * Typed asynchronous function, applicable to any function that returns a {@linkcode Promise}.
25
+ *
26
+ * @template TFunction
27
+ * Function type.
28
+ */
29
+ export type TypedAsyncFunction<TMethod extends (...args: Parameters<TMethod>) => PromiseLike<PromisedType<ReturnType<TMethod>>>> = (...args: Parameters<TMethod>) => Promise<PromisedType<ReturnType<TMethod>>>;
30
+ /**
31
+ * Nullishable type. Extends a type by allowing `null` and `undefined`.
32
+ *
33
+ * @template T
34
+ * Type.
35
+ */
36
+ export type Nullishable<T> = T | null | undefined;
37
+ /**
38
+ * Non-nullishable type. If T is an object type, it is spread and attributes within it are made non-nullishable.
39
+ * Equivalent to a deep `Required<T>` for an object and `NonNullable<T>` for any other type.
40
+ *
41
+ * @template T
42
+ * Type.
43
+ */
44
+ export type NonNullishable<T> = T extends object ? {
45
+ [P in keyof T]-?: NonNullishable<T[P]>;
46
+ } : NonNullable<T>;
47
+ /**
48
+ * Make some keys within a type optional.
49
+ *
50
+ * @template T
51
+ * Object type.
52
+ *
53
+ * @template K
54
+ * Object key type.
55
+ */
56
+ export type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
57
+ /**
58
+ * Type to restrict property keys to those that are strings and that support a specified type.
59
+ *
60
+ * @template T
61
+ * Object type.
62
+ *
63
+ * @template P
64
+ * Object property type.
65
+ */
66
+ export type PropertyKeys<T, P> = {
67
+ [K in keyof T]: K extends string ? T[K] extends P ? K : never : never;
68
+ }[keyof T];
69
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,aAAa,CAAC,SAAS,SAAS,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,SAAS,CAAC,KAAK,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,SAAS,CAAC,KAAK,UAAU,CAAC,SAAS,CAAC,CAAC;AAEnK;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,CAAC,SAAS,SAAS,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,GAAG,KAAK,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;AAEtK;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,WAAW,CAAC,MAAM,SAAS,CAAC,CAAC,GAAG,SAAS,GAAG,KAAK,CAAC;AAE7F;;;;;GAKG;AACH,MAAM,MAAM,kBAAkB,CAAC,OAAO,SAAS,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,KAAK,WAAW,CAAC,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,KAAK,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAEhN;;;;;GAKG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GAAG;KAC9C,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACzC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;AAEnB;;;;;;;;GAQG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAE9E;;;;;;;;GAQG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,CAAC,IAAI;KAC5B,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,SAAS,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,KAAK,GAAG,KAAK;CACxE,CAAC,MAAM,CAAC,CAAC,CAAC"}
package/dist/type.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "@aidc-toolkit/core",
3
- "version": "1.0.24-beta",
3
+ "version": "1.0.26-beta",
4
4
  "description": "Core functionality for AIDC Toolkit",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "homepage": "https://aidc-toolkit.com/",
8
- "repository": "aidc-toolkit/core",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/aidc-toolkit/core.git"
11
+ },
9
12
  "bugs": {
10
13
  "url": "https://github.com/aidc-toolkit/core/issues"
11
14
  },
@@ -17,15 +20,16 @@
17
20
  },
18
21
  "scripts": {
19
22
  "lint": "eslint",
20
- "build:dev": "tsup --define.mode=dev",
21
- "build:release": "tsup",
23
+ "tsc:core": "tsc --project tsconfig-src.json",
24
+ "build:dev": "rimraf dist && npm run tsc:core -- --declarationMap --sourceMap",
25
+ "build:release": "npm run tsc:core -- --noEmit && tsup",
22
26
  "build:doc": "npm run build:dev"
23
27
  },
24
28
  "devDependencies": {
25
- "@aidc-toolkit/dev": "beta"
29
+ "@aidc-toolkit/dev": "1.0.26-beta"
26
30
  },
27
31
  "dependencies": {
28
- "i18next": "^25.7.0",
32
+ "i18next": "^25.7.1",
29
33
  "i18next-browser-languagedetector": "^8.2.0",
30
34
  "i18next-cli-language-detector": "^1.1.8",
31
35
  "tslog": "^4.10.2"
package/src/index.ts CHANGED
@@ -14,7 +14,7 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- export type * from "./type";
18
- export * from "./type-helper";
19
- export * from "./logger";
20
- export * from "./locale/i18n";
17
+ export type * from "./type.js";
18
+ export * from "./type-helper.js";
19
+ export * from "./logger.js";
20
+ export * from "./locale/i18n.js";
@@ -29,10 +29,15 @@ export const I18nEnvironments = {
29
29
  Browser: 2
30
30
  } as const;
31
31
 
32
+ /**
33
+ * Internationalization operating environment key.
34
+ */
35
+ export type I18nEnvironmentKey = keyof typeof I18nEnvironments;
36
+
32
37
  /**
33
38
  * Internationalization operating environment.
34
39
  */
35
- export type I18nEnvironment = typeof I18nEnvironments[keyof typeof I18nEnvironments];
40
+ export type I18nEnvironment = typeof I18nEnvironments[I18nEnvironmentKey];
36
41
 
37
42
  /**
38
43
  * Convert a string to lower case, skipping words that are all upper case.
package/src/logger.ts CHANGED
@@ -13,16 +13,21 @@ export const LogLevels = {
13
13
  Fatal: 6
14
14
  } as const;
15
15
 
16
+ /**
17
+ * Log level key.
18
+ */
19
+ export type LogLevelKey = keyof typeof LogLevels;
20
+
16
21
  /**
17
22
  * Log level.
18
23
  */
19
- export type LogLevel = typeof LogLevels[keyof typeof LogLevels];
24
+ export type LogLevel = typeof LogLevels[LogLevelKey];
20
25
 
21
26
  /**
22
27
  * Get a simple logger with an optional log level.
23
28
  *
24
29
  * @param logLevel
25
- * Log level as enumeration value or string if any.
30
+ * Log level as enumeration value or string.
26
31
  *
27
32
  * @returns
28
33
  * Logger.
@@ -33,7 +38,7 @@ export function getLogger(logLevel?: string | number): Logger<unknown> {
33
38
  if (typeof logLevel === "string") {
34
39
  if (logLevel in LogLevels) {
35
40
  // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- String exists as a key.
36
- minLevel = LogLevels[logLevel as keyof typeof LogLevels];
41
+ minLevel = LogLevels[logLevel as LogLevelKey];
37
42
  } else {
38
43
  throw new Error(`Unknown log level ${logLevel}`);
39
44
  }
@@ -1,6 +1,15 @@
1
1
  /**
2
2
  * Create an object with omitted or picked entries.
3
3
  *
4
+ * @template Omitting
5
+ * Type representation of `omitting` parameter for return type determination.
6
+ *
7
+ * @template T
8
+ * Object type.
9
+ *
10
+ * @template K
11
+ * Object key type.
12
+ *
4
13
  * @param omitting
5
14
  * True if omitting.
6
15
  *
@@ -21,6 +30,12 @@ function omitOrPick<Omitting extends boolean, T extends object, K extends keyof
21
30
  /**
22
31
  * Create an object with omitted entries.
23
32
  *
33
+ * @template T
34
+ * Object type.
35
+ *
36
+ * @template K
37
+ * Object key type.
38
+ *
24
39
  * @param o
25
40
  * Object.
26
41
  *
@@ -37,6 +52,12 @@ export function omit<T extends object, K extends keyof T>(o: T, ...keys: K[]): O
37
52
  /**
38
53
  * Create an object with picked entries.
39
54
  *
55
+ * @template T
56
+ * Object type.
57
+ *
58
+ * @template K
59
+ * Object key type.
60
+ *
40
61
  * @param o
41
62
  * Object.
42
63
  *
@@ -53,6 +74,15 @@ export function pick<T extends object, K extends keyof T>(o: T, ...keys: K[]): P
53
74
  /**
54
75
  * Cast a property as a more narrow type.
55
76
  *
77
+ * @template T
78
+ * Object type.
79
+ *
80
+ * @template K
81
+ * Object key type.
82
+ *
83
+ * @template TAsType
84
+ * Desired type.
85
+ *
56
86
  * @param o
57
87
  * Object.
58
88
  *
@@ -62,7 +92,7 @@ export function pick<T extends object, K extends keyof T>(o: T, ...keys: K[]): P
62
92
  * @returns
63
93
  * Single-key object with property cast as desired type.
64
94
  */
65
- export 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>> {
95
+ export 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>> {
66
96
  // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Type is determined by condition.
67
97
  return (key in o ?
68
98
  {
@@ -70,7 +100,7 @@ export function propertyAs<TAsType extends T[K], T extends object, K extends key
70
100
  [key]: o[key] as TAsType
71
101
  } :
72
102
  {}
73
- ) as ReturnType<typeof propertyAs<TAsType, T, K>>;
103
+ ) as ReturnType<typeof propertyAs<T, K, TAsType>>;
74
104
  }
75
105
 
76
106
  /**
@@ -82,6 +112,6 @@ export function propertyAs<TAsType extends T[K], T extends object, K extends key
82
112
  * @returns
83
113
  * True if argument is undefined or null.
84
114
  */
85
- export function isNullish<T>(argument: T | null | undefined): argument is null | undefined {
115
+ export function isNullish(argument: unknown): argument is null | undefined {
86
116
  return argument === null || argument === undefined;
87
117
  }
package/src/type.ts CHANGED
@@ -1,31 +1,50 @@
1
1
  /**
2
- * Typed function, applicable to any function, stricter than {@link Function}.
2
+ * Typed function, applicable to any function, stricter than {@linkcode Function}.
3
+ *
4
+ * @template TFunction
5
+ * Function type.
3
6
  */
4
- export type TypedFunction<TMethod extends (...args: Parameters<TMethod>) => ReturnType<TMethod>> = (...args: Parameters<TMethod>) => ReturnType<TMethod>;
7
+ export type TypedFunction<TFunction extends (...args: Parameters<TFunction>) => ReturnType<TFunction>> = (...args: Parameters<TFunction>) => ReturnType<TFunction>;
5
8
 
6
9
  /**
7
- * Typed synchronous function, applicable to any function that doesn't return a Promise.
10
+ * Typed synchronous function, applicable to any function that doesn't return a {@linkcode Promise}.
11
+ *
12
+ * @template TFunction
13
+ * Function type.
8
14
  */
9
- export type TypedSyncFunction<TMethod extends TypedFunction<TMethod>> = [ReturnType<TMethod>] extends [PromiseLike<unknown>] ? never : TypedFunction<TMethod>;
15
+ export type TypedSyncFunction<TFunction extends TypedFunction<TFunction>> = [ReturnType<TFunction>] extends [PromiseLike<unknown>] ? never : TypedFunction<TFunction>;
10
16
 
11
17
  /**
12
- * Determine the fundamental promised type. This is stricter than `Awaited\<Type\>` in that it requires a Promise.
18
+ * Determine the fundamental promised type. This is stricter than `Awaited<Type>` in that it requires a {@linkcode
19
+ * Promise}.
20
+ *
21
+ * @template T
22
+ * Promised type.
13
23
  */
14
- type PromisedType<T> = [T] extends [PromiseLike<infer TPromised>] ? TPromised : never;
24
+ export type PromisedType<T> = [T] extends [PromiseLike<infer TPromised>] ? TPromised : never;
15
25
 
16
26
  /**
17
- * Typed asynchronous function, applicable to any function that returns a Promise.
27
+ * Typed asynchronous function, applicable to any function that returns a {@linkcode Promise}.
28
+ *
29
+ * @template TFunction
30
+ * Function type.
18
31
  */
19
32
  export type TypedAsyncFunction<TMethod extends (...args: Parameters<TMethod>) => PromiseLike<PromisedType<ReturnType<TMethod>>>> = (...args: Parameters<TMethod>) => Promise<PromisedType<ReturnType<TMethod>>>;
20
33
 
21
34
  /**
22
35
  * Nullishable type. Extends a type by allowing `null` and `undefined`.
36
+ *
37
+ * @template T
38
+ * Type.
23
39
  */
24
40
  export type Nullishable<T> = T | null | undefined;
25
41
 
26
42
  /**
27
43
  * Non-nullishable type. If T is an object type, it is spread and attributes within it are made non-nullishable.
28
- * Equivalent to a deep `Required\<T\>` for an object and `NonNullable\<T\>` for any other type.
44
+ * Equivalent to a deep `Required<T>` for an object and `NonNullable<T>` for any other type.
45
+ *
46
+ * @template T
47
+ * Type.
29
48
  */
30
49
  export type NonNullishable<T> = T extends object ? {
31
50
  [P in keyof T]-?: NonNullishable<T[P]>
@@ -33,12 +52,24 @@ export type NonNullishable<T> = T extends object ? {
33
52
 
34
53
  /**
35
54
  * Make some keys within a type optional.
55
+ *
56
+ * @template T
57
+ * Object type.
58
+ *
59
+ * @template K
60
+ * Object key type.
36
61
  */
37
62
  export type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
38
63
 
39
64
  /**
40
65
  * Type to restrict property keys to those that are strings and that support a specified type.
66
+ *
67
+ * @template T
68
+ * Object type.
69
+ *
70
+ * @template P
71
+ * Object property type.
41
72
  */
42
- export type PropertyKeys<T, TProperty> = {
43
- [K in keyof T]: K extends string ? T[K] extends TProperty ? K : never : never;
73
+ export type PropertyKeys<T, P> = {
74
+ [K in keyof T]: K extends string ? T[K] extends P ? K : never : never;
44
75
  }[keyof T];
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "@aidc-toolkit/dev/tsconfig-template.json",
3
+ "files": ["./eslint.config.ts", "./tsup.config.ts"]
4
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "@aidc-toolkit/dev/tsconfig-template.json",
3
+ "include": ["./src/**/*"],
4
+ "compilerOptions": {
5
+ // Emit.
6
+ "outDir": "dist"
7
+ }
8
+ }
package/tsconfig.json CHANGED
@@ -1,3 +1,11 @@
1
1
  {
2
- "extends": "@aidc-toolkit/dev/tsconfig.json"
2
+ "include": [],
3
+ "references": [
4
+ {
5
+ "path": "./tsconfig-src.json"
6
+ },
7
+ {
8
+ "path": "./tsconfig-config.json"
9
+ }
10
+ ]
3
11
  }
package/tsup.config.ts CHANGED
@@ -1,3 +1,4 @@
1
- import { tsupConfigAIDCToolkit } from "@aidc-toolkit/dev";
1
+ import { tsupConfig } from "@aidc-toolkit/dev";
2
+ import { defineConfig } from "tsup";
2
3
 
3
- export default tsupConfigAIDCToolkit;
4
+ export default defineConfig(tsupConfig);
package/dist/index.cjs DELETED
@@ -1,173 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
33
- I18nEnvironments: () => I18nEnvironments,
34
- LogLevels: () => LogLevels,
35
- getLogger: () => getLogger,
36
- i18nCoreInit: () => i18nCoreInit,
37
- isNullish: () => isNullish,
38
- omit: () => omit,
39
- pick: () => pick,
40
- propertyAs: () => propertyAs
41
- });
42
- module.exports = __toCommonJS(index_exports);
43
-
44
- // src/type-helper.ts
45
- function omitOrPick(omitting, o, ...keys) {
46
- return Object.fromEntries(Object.entries(o).filter(([key]) => keys.includes(key) !== omitting));
47
- }
48
- function omit(o, ...keys) {
49
- return omitOrPick(true, o, ...keys);
50
- }
51
- function pick(o, ...keys) {
52
- return omitOrPick(false, o, ...keys);
53
- }
54
- function propertyAs(o, key) {
55
- return key in o ? {
56
- // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Force cast.
57
- [key]: o[key]
58
- } : {};
59
- }
60
- function isNullish(argument) {
61
- return argument === null || argument === void 0;
62
- }
63
-
64
- // src/logger.ts
65
- var import_tslog = require("tslog");
66
- var LogLevels = {
67
- Silly: 0,
68
- Trace: 1,
69
- Debug: 2,
70
- Info: 3,
71
- Warn: 4,
72
- Error: 5,
73
- Fatal: 6
74
- };
75
- function getLogger(logLevel) {
76
- let minLevel;
77
- if (typeof logLevel === "string") {
78
- if (logLevel in LogLevels) {
79
- minLevel = LogLevels[logLevel];
80
- } else {
81
- throw new Error(`Unknown log level ${logLevel}`);
82
- }
83
- } else {
84
- minLevel = logLevel ?? LogLevels.Info;
85
- }
86
- return new import_tslog.Logger({
87
- minLevel
88
- });
89
- }
90
-
91
- // src/locale/i18n.ts
92
- var import_i18next_browser_languagedetector = __toESM(require("i18next-browser-languagedetector"), 1);
93
- var import_i18next_cli_language_detector = __toESM(require("i18next-cli-language-detector"), 1);
94
- var I18nEnvironments = {
95
- /**
96
- * Command-line interface (e.g., unit tests).
97
- */
98
- CLI: 0,
99
- /**
100
- * Web server.
101
- */
102
- Server: 1,
103
- /**
104
- * Web browser.
105
- */
106
- Browser: 2
107
- };
108
- function toLowerCase(s) {
109
- return s.split(" ").map((word) => /[a-z]/.test(word) ? word.toLowerCase() : word).join(" ");
110
- }
111
- async function i18nCoreInit(i18next, environment, debug, defaultNS, ...resources) {
112
- if (!i18next.isInitialized) {
113
- const mergedResource = {};
114
- for (const resource of resources) {
115
- for (const [language, resourceLanguage] of Object.entries(resource)) {
116
- if (!(language in mergedResource)) {
117
- mergedResource[language] = {};
118
- }
119
- const mergedResourceLanguage = mergedResource[language];
120
- for (const [namespace, resourceKey] of Object.entries(resourceLanguage)) {
121
- mergedResourceLanguage[namespace] = resourceKey;
122
- }
123
- }
124
- }
125
- let module2;
126
- switch (environment) {
127
- case I18nEnvironments.CLI:
128
- module2 = import_i18next_cli_language_detector.default;
129
- break;
130
- case I18nEnvironments.Browser:
131
- module2 = import_i18next_browser_languagedetector.default;
132
- break;
133
- default:
134
- throw new Error("Not supported");
135
- }
136
- await i18next.use(module2).init({
137
- debug,
138
- resources: mergedResource,
139
- fallbackLng: "en",
140
- defaultNS
141
- }).then(() => {
142
- i18next.services.formatter?.add("toLowerCase", (value) => typeof value === "string" ? toLowerCase(value) : String(value));
143
- });
144
- }
145
- }
146
- // Annotate the CommonJS export names for ESM import in node:
147
- 0 && (module.exports = {
148
- I18nEnvironments,
149
- LogLevels,
150
- getLogger,
151
- i18nCoreInit,
152
- isNullish,
153
- omit,
154
- pick,
155
- propertyAs
156
- });
157
- /*!
158
- * Copyright © 2024-2025 Dolphin Data Development Ltd. and AIDC Toolkit
159
- * contributors
160
- *
161
- * Licensed under the Apache License, Version 2.0 (the "License");
162
- * you may not use this file except in compliance with the License.
163
- * You may obtain a copy of the License at
164
- *
165
- * https://www.apache.org/licenses/LICENSE-2.0
166
- *
167
- * Unless required by applicable law or agreed to in writing, software
168
- * distributed under the License is distributed on an "AS IS" BASIS,
169
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
170
- * See the License for the specific language governing permissions and
171
- * limitations under the License.
172
- */
173
- //# sourceMappingURL=index.cjs.map