@aidc-toolkit/core 0.9.4 → 0.9.6-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.cjs ADDED
@@ -0,0 +1,128 @@
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 src_exports = {};
32
+ __export(src_exports, {
33
+ I18NEnvironment: () => I18NEnvironment,
34
+ i18nAddResourceBundle: () => i18nAddResourceBundle,
35
+ i18nAssertValidResources: () => i18nAssertValidResources,
36
+ i18nInit: () => i18nInit,
37
+ i18next: () => i18n_default
38
+ });
39
+ module.exports = __toCommonJS(src_exports);
40
+
41
+ // src/locale/i18n.ts
42
+ var import_i18next = __toESM(require("i18next"), 1);
43
+ var import_i18next_browser_languagedetector = __toESM(require("i18next-browser-languagedetector"), 1);
44
+ var import_i18next_cli_language_detector = __toESM(require("i18next-cli-language-detector"), 1);
45
+ var i18n_default = import_i18next.default;
46
+ var pendingResourceBundles = [];
47
+ var I18NEnvironment = /* @__PURE__ */ ((I18NEnvironment2) => {
48
+ I18NEnvironment2[I18NEnvironment2["CLI"] = 0] = "CLI";
49
+ I18NEnvironment2[I18NEnvironment2["Server"] = 1] = "Server";
50
+ I18NEnvironment2[I18NEnvironment2["Browser"] = 2] = "Browser";
51
+ return I18NEnvironment2;
52
+ })(I18NEnvironment || {});
53
+ async function i18nInit(environment, debug = false) {
54
+ let initialized;
55
+ if (pendingResourceBundles !== void 0) {
56
+ initialized = true;
57
+ let module2;
58
+ switch (environment) {
59
+ case 0 /* CLI */:
60
+ module2 = import_i18next_cli_language_detector.default;
61
+ break;
62
+ case 2 /* Browser */:
63
+ module2 = import_i18next_browser_languagedetector.default;
64
+ break;
65
+ default:
66
+ throw new Error("Not supported");
67
+ }
68
+ const initResourceBundles = pendingResourceBundles;
69
+ pendingResourceBundles = void 0;
70
+ await import_i18next.default.use(module2).init({
71
+ fallbackLng: "en",
72
+ debug,
73
+ resources: {}
74
+ }).then(() => {
75
+ import_i18next.default.services.formatter?.add("toLowerCase", (value) => typeof value === "string" ? value.toLowerCase() : String(value));
76
+ for (const initResourceBundle of initResourceBundles) {
77
+ i18nAddResourceBundle(initResourceBundle.lng, initResourceBundle.ns, initResourceBundle.resources);
78
+ }
79
+ });
80
+ } else {
81
+ initialized = false;
82
+ }
83
+ return initialized;
84
+ }
85
+ function i18nAddResourceBundle(lng, ns, resources) {
86
+ if (pendingResourceBundles !== void 0) {
87
+ pendingResourceBundles.push({
88
+ lng,
89
+ ns,
90
+ resources
91
+ });
92
+ } else {
93
+ import_i18next.default.addResourceBundle(lng, ns, resources);
94
+ }
95
+ }
96
+ function i18nAssertValidResources(enResources, lng, lngResources, parent) {
97
+ const enResourcesMap = new Map(Object.entries(enResources));
98
+ const lngResourcesMap = new Map(Object.entries(lngResources));
99
+ const isLocale = lng.includes("-");
100
+ for (const [enKey, enValue] of enResourcesMap) {
101
+ const lngValue = lngResourcesMap.get(enKey);
102
+ if (lngValue !== void 0) {
103
+ const enValueType = typeof enValue;
104
+ const lngValueType = typeof lngValue;
105
+ if (lngValueType !== enValueType) {
106
+ throw new Error(`Invalid value type ${lngValueType} for key ${parent === void 0 ? "" : `${parent}.`}${enKey} in ${lng} resources`);
107
+ }
108
+ if (enValueType === "object") {
109
+ i18nAssertValidResources(enValue, lng, lngValue, `${parent === void 0 ? "" : `${parent}.`}${enKey}`);
110
+ }
111
+ } else if (!isLocale) {
112
+ throw new Error(`Missing key ${parent === void 0 ? "" : `${parent}.`}${enKey} from ${lng} resources`);
113
+ }
114
+ }
115
+ for (const [lngKey] of lngResourcesMap) {
116
+ if (!enResourcesMap.has(lngKey)) {
117
+ throw new Error(`Extraneous key ${parent === void 0 ? "" : `${parent}.`}${lngKey} in ${lng} resources`);
118
+ }
119
+ }
120
+ }
121
+ // Annotate the CommonJS export names for ESM import in node:
122
+ 0 && (module.exports = {
123
+ I18NEnvironment,
124
+ i18nAddResourceBundle,
125
+ i18nAssertValidResources,
126
+ i18nInit,
127
+ i18next
128
+ });
@@ -0,0 +1,64 @@
1
+ import i18next from 'i18next';
2
+ export { default as i18next } from 'i18next';
3
+
4
+ /**
5
+ * Internationalization operating environment.
6
+ */
7
+ declare enum I18NEnvironment {
8
+ /**
9
+ * Command-line interface (e.g., unit tests).
10
+ */
11
+ CLI = 0,
12
+ /**
13
+ * Web server.
14
+ */
15
+ Server = 1,
16
+ /**
17
+ * Web browser.
18
+ */
19
+ Browser = 2
20
+ }
21
+ /**
22
+ * Initialize internationalization.
23
+ *
24
+ * @param environment
25
+ * Environment in which the application is running.
26
+ *
27
+ * @param debug
28
+ * Debug setting.
29
+ *
30
+ * @returns
31
+ * True if initialization was completed, false if skipped (already initialized).
32
+ */
33
+ declare function i18nInit(environment: I18NEnvironment, debug?: boolean): Promise<boolean>;
34
+ /**
35
+ * Add a resource bundle.
36
+ *
37
+ * @param lng
38
+ * Language.
39
+ *
40
+ * @param ns
41
+ * Namespace.
42
+ *
43
+ * @param resources
44
+ * Resources.
45
+ */
46
+ declare function i18nAddResourceBundle(lng: string, ns: string, resources: object): void;
47
+ /**
48
+ * Assert that language resources are a type match for English (default) resources.
49
+ *
50
+ * @param enResources
51
+ * English resources.
52
+ *
53
+ * @param lng
54
+ * Language.
55
+ *
56
+ * @param lngResources
57
+ * Language resources.
58
+ *
59
+ * @param parent
60
+ * Parent key name (set recursively).
61
+ */
62
+ declare function i18nAssertValidResources(enResources: object, lng: string, lngResources: object, parent?: string): void;
63
+
64
+ export { I18NEnvironment, i18nAddResourceBundle, i18nAssertValidResources, i18nInit };
@@ -0,0 +1,64 @@
1
+ import i18next from 'i18next';
2
+ export { default as i18next } from 'i18next';
3
+
4
+ /**
5
+ * Internationalization operating environment.
6
+ */
7
+ declare enum I18NEnvironment {
8
+ /**
9
+ * Command-line interface (e.g., unit tests).
10
+ */
11
+ CLI = 0,
12
+ /**
13
+ * Web server.
14
+ */
15
+ Server = 1,
16
+ /**
17
+ * Web browser.
18
+ */
19
+ Browser = 2
20
+ }
21
+ /**
22
+ * Initialize internationalization.
23
+ *
24
+ * @param environment
25
+ * Environment in which the application is running.
26
+ *
27
+ * @param debug
28
+ * Debug setting.
29
+ *
30
+ * @returns
31
+ * True if initialization was completed, false if skipped (already initialized).
32
+ */
33
+ declare function i18nInit(environment: I18NEnvironment, debug?: boolean): Promise<boolean>;
34
+ /**
35
+ * Add a resource bundle.
36
+ *
37
+ * @param lng
38
+ * Language.
39
+ *
40
+ * @param ns
41
+ * Namespace.
42
+ *
43
+ * @param resources
44
+ * Resources.
45
+ */
46
+ declare function i18nAddResourceBundle(lng: string, ns: string, resources: object): void;
47
+ /**
48
+ * Assert that language resources are a type match for English (default) resources.
49
+ *
50
+ * @param enResources
51
+ * English resources.
52
+ *
53
+ * @param lng
54
+ * Language.
55
+ *
56
+ * @param lngResources
57
+ * Language resources.
58
+ *
59
+ * @param parent
60
+ * Parent key name (set recursively).
61
+ */
62
+ declare function i18nAssertValidResources(enResources: object, lng: string, lngResources: object, parent?: string): void;
63
+
64
+ export { I18NEnvironment, i18nAddResourceBundle, i18nAssertValidResources, i18nInit };
package/dist/index.js ADDED
@@ -0,0 +1,87 @@
1
+ // src/locale/i18n.ts
2
+ import i18next from "i18next";
3
+ import I18nextBrowserLanguageDetector from "i18next-browser-languagedetector";
4
+ import I18nextCLILanguageDetector from "i18next-cli-language-detector";
5
+ var i18n_default = i18next;
6
+ var pendingResourceBundles = [];
7
+ var I18NEnvironment = /* @__PURE__ */ ((I18NEnvironment2) => {
8
+ I18NEnvironment2[I18NEnvironment2["CLI"] = 0] = "CLI";
9
+ I18NEnvironment2[I18NEnvironment2["Server"] = 1] = "Server";
10
+ I18NEnvironment2[I18NEnvironment2["Browser"] = 2] = "Browser";
11
+ return I18NEnvironment2;
12
+ })(I18NEnvironment || {});
13
+ async function i18nInit(environment, debug = false) {
14
+ let initialized;
15
+ if (pendingResourceBundles !== void 0) {
16
+ initialized = true;
17
+ let module;
18
+ switch (environment) {
19
+ case 0 /* CLI */:
20
+ module = I18nextCLILanguageDetector;
21
+ break;
22
+ case 2 /* Browser */:
23
+ module = I18nextBrowserLanguageDetector;
24
+ break;
25
+ default:
26
+ throw new Error("Not supported");
27
+ }
28
+ const initResourceBundles = pendingResourceBundles;
29
+ pendingResourceBundles = void 0;
30
+ await i18next.use(module).init({
31
+ fallbackLng: "en",
32
+ debug,
33
+ resources: {}
34
+ }).then(() => {
35
+ i18next.services.formatter?.add("toLowerCase", (value) => typeof value === "string" ? value.toLowerCase() : String(value));
36
+ for (const initResourceBundle of initResourceBundles) {
37
+ i18nAddResourceBundle(initResourceBundle.lng, initResourceBundle.ns, initResourceBundle.resources);
38
+ }
39
+ });
40
+ } else {
41
+ initialized = false;
42
+ }
43
+ return initialized;
44
+ }
45
+ function i18nAddResourceBundle(lng, ns, resources) {
46
+ if (pendingResourceBundles !== void 0) {
47
+ pendingResourceBundles.push({
48
+ lng,
49
+ ns,
50
+ resources
51
+ });
52
+ } else {
53
+ i18next.addResourceBundle(lng, ns, resources);
54
+ }
55
+ }
56
+ function i18nAssertValidResources(enResources, lng, lngResources, parent) {
57
+ const enResourcesMap = new Map(Object.entries(enResources));
58
+ const lngResourcesMap = new Map(Object.entries(lngResources));
59
+ const isLocale = lng.includes("-");
60
+ for (const [enKey, enValue] of enResourcesMap) {
61
+ const lngValue = lngResourcesMap.get(enKey);
62
+ if (lngValue !== void 0) {
63
+ const enValueType = typeof enValue;
64
+ const lngValueType = typeof lngValue;
65
+ if (lngValueType !== enValueType) {
66
+ throw new Error(`Invalid value type ${lngValueType} for key ${parent === void 0 ? "" : `${parent}.`}${enKey} in ${lng} resources`);
67
+ }
68
+ if (enValueType === "object") {
69
+ i18nAssertValidResources(enValue, lng, lngValue, `${parent === void 0 ? "" : `${parent}.`}${enKey}`);
70
+ }
71
+ } else if (!isLocale) {
72
+ throw new Error(`Missing key ${parent === void 0 ? "" : `${parent}.`}${enKey} from ${lng} resources`);
73
+ }
74
+ }
75
+ for (const [lngKey] of lngResourcesMap) {
76
+ if (!enResourcesMap.has(lngKey)) {
77
+ throw new Error(`Extraneous key ${parent === void 0 ? "" : `${parent}.`}${lngKey} in ${lng} resources`);
78
+ }
79
+ }
80
+ }
81
+ export {
82
+ I18NEnvironment,
83
+ i18nAddResourceBundle,
84
+ i18nAssertValidResources,
85
+ i18nInit,
86
+ i18n_default as i18next
87
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aidc-toolkit/core",
3
- "version": "0.9.4",
3
+ "version": "0.9.6-beta",
4
4
  "description": "Core functionality for AIDC Toolkit",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -19,19 +19,20 @@
19
19
  "url": "https://www.linkedin.com/in/kdean"
20
20
  },
21
21
  "scripts": {
22
- "eslint": "eslint .",
22
+ "lint": "eslint .",
23
23
  "build": "tsup src/index.ts --clean --format cjs,esm --dts",
24
24
  "build-doc": "npm run build && tsc src/index.ts --outDir dist --target esnext --moduleResolution nodenext --module nodenext --emitDeclarationOnly --declaration --declarationMap"
25
25
  },
26
26
  "devDependencies": {
27
- "@aidc-toolkit/dev": "^0.9.4",
28
- "eslint": "^9.15.0",
27
+ "@aidc-toolkit/dev": "^0.9.6-beta",
28
+ "eslint": "^9.16.0",
29
29
  "ts-node": "^10.9.2",
30
30
  "tsup": "^8.3.5",
31
- "typescript": "^5.6.3"
31
+ "typescript": "^5.7.2"
32
32
  },
33
33
  "dependencies": {
34
- "i18next": "^23.16.5",
34
+ "@rollup/rollup-linux-x64-gnu": "^4.28.0",
35
+ "i18next": "^24.0.5",
35
36
  "i18next-browser-languagedetector": "^8.0.0",
36
37
  "i18next-cli-language-detector": "^1.1.8"
37
38
  }
@@ -1,4 +1,4 @@
1
- import i18next from "i18next";
1
+ import i18next, { type LanguageDetectorModule } from "i18next";
2
2
  import I18nextBrowserLanguageDetector from "i18next-browser-languagedetector";
3
3
  import I18nextCLILanguageDetector from "i18next-cli-language-detector";
4
4
 
@@ -56,12 +56,13 @@ export async function i18nInit(environment: I18NEnvironment, debug = false): Pro
56
56
  // Skip if initialization is not pending.
57
57
  if (pendingResourceBundles !== undefined) {
58
58
  initialized = true;
59
-
60
- let module: object;
59
+
60
+ let module: Parameters<typeof i18next.use>[0];
61
61
 
62
62
  switch (environment) {
63
63
  case I18NEnvironment.CLI:
64
- module = I18nextCLILanguageDetector;
64
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Pending resolution of https://github.com/neet/i18next-cli-language-detector/issues/281.
65
+ module = I18nextCLILanguageDetector as unknown as LanguageDetectorModule;
65
66
  break;
66
67
 
67
68
  case I18NEnvironment.Browser:
@@ -77,13 +78,13 @@ export async function i18nInit(environment: I18NEnvironment, debug = false): Pro
77
78
  // No need to manage pending resource bundles past this point.
78
79
  pendingResourceBundles = undefined;
79
80
 
80
- await i18next.use(module as never).init({
81
+ await i18next.use(module).init({
81
82
  fallbackLng: "en",
82
83
  debug,
83
84
  resources: {}
84
85
  }).then(() => {
85
86
  // Add toLowerCase function.
86
- i18next.services.formatter?.add("toLowerCase", value => (value as string).toLowerCase());
87
+ i18next.services.formatter?.add("toLowerCase", value => typeof value === "string" ? value.toLowerCase() : String(value));
87
88
 
88
89
  // Add pending resource bundles.
89
90
  for (const initResourceBundle of initResourceBundles) {
@@ -1,32 +0,0 @@
1
- ---
2
- name: Bug report
3
- about: Create a report to help us improve
4
- title: ''
5
- labels: ''
6
- assignees: ''
7
-
8
- ---
9
-
10
- **Describe the bug**
11
- A clear and concise description of what the bug is.
12
-
13
- **To Reproduce**
14
- Steps to reproduce the behavior:
15
- 1. Go to '...'
16
- 2. Click on '....'
17
- 3. Scroll down to '....'
18
- 4. See error
19
-
20
- **Expected behavior**
21
- A clear and concise description of what you expected to happen.
22
-
23
- **Screenshots**
24
- If applicable, add screenshots to help explain your problem.
25
-
26
- **Platform**
27
- - OS: [e.g. Windows, iOS]
28
- - Browser [e.g. chrome, safari]
29
- - Browser Version [e.g. 22]
30
-
31
- **Additional context**
32
- Add any other context about the problem here.
@@ -1,20 +0,0 @@
1
- ---
2
- name: Feature request
3
- about: Suggest an idea for this project
4
- title: ''
5
- labels: ''
6
- assignees: ''
7
-
8
- ---
9
-
10
- **Is your feature request related to a problem? Please describe.**
11
- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12
-
13
- **Describe the solution you'd like**
14
- A clear and concise description of what you want to happen.
15
-
16
- **Describe alternatives you've considered**
17
- A clear and concise description of any alternative solutions or features you've considered.
18
-
19
- **Additional context**
20
- Add any other context or screenshots about the feature request here.
@@ -1,32 +0,0 @@
1
- # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
- # For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
3
-
4
- name: Node.js Package
5
-
6
- on:
7
- release:
8
- types: [created]
9
-
10
- jobs:
11
- build:
12
- runs-on: ubuntu-latest
13
- steps:
14
- - uses: actions/checkout@v4
15
- - uses: actions/setup-node@v4
16
- with:
17
- node-version: 22
18
- - run: npm ci
19
-
20
- publish-npm:
21
- needs: build
22
- runs-on: ubuntu-latest
23
- steps:
24
- - uses: actions/checkout@v4
25
- - uses: actions/setup-node@v4
26
- with:
27
- node-version: 22
28
- registry-url: https://registry.npmjs.org/
29
- - run: npm ci
30
- - run: npm publish --access public
31
- env:
32
- NODE_AUTH_TOKEN: ${{secrets.npm_token}}
package/.idea/core.iml DELETED
@@ -1,9 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="JAVA_MODULE" version="4">
3
- <component name="NewModuleRootManager" inherit-compiler-output="true">
4
- <exclude-output />
5
- <content url="file://$MODULE_DIR$" />
6
- <orderEntry type="inheritedJdk" />
7
- <orderEntry type="sourceFolder" forTests="false" />
8
- </component>
9
- </module>
@@ -1,7 +0,0 @@
1
- <component name="InspectionProjectProfileManager">
2
- <profile version="1.0">
3
- <option name="myName" value="Project Default" />
4
- <inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
5
- <inspection_tool class="UpdateDependencyToLatestVersion" enabled="true" level="WARNING" enabled_by_default="true" editorAttributes="WARNING_ATTRIBUTES" />
6
- </profile>
7
- </component>
package/.idea/misc.xml DELETED
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="openjdk-21" project-jdk-type="JavaSDK">
4
- <output url="file://$PROJECT_DIR$/out" />
5
- </component>
6
- </project>
package/.idea/modules.xml DELETED
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectModuleManager">
4
- <modules>
5
- <module fileurl="file://$PROJECT_DIR$/.idea/core.iml" filepath="$PROJECT_DIR$/.idea/core.iml" />
6
- </modules>
7
- </component>
8
- </project>
@@ -1,12 +0,0 @@
1
- <component name="ProjectRunConfigurationManager">
2
- <configuration default="false" name="build" type="js.build_tools.npm" nameIsGenerated="true">
3
- <package-json value="$PROJECT_DIR$/package.json" />
4
- <command value="run" />
5
- <scripts>
6
- <script value="build" />
7
- </scripts>
8
- <node-interpreter value="project" />
9
- <envs />
10
- <method v="2" />
11
- </configuration>
12
- </component>
@@ -1,12 +0,0 @@
1
- <component name="ProjectRunConfigurationManager">
2
- <configuration default="false" name="build-dev" type="js.build_tools.npm" nameIsGenerated="true">
3
- <package-json value="$PROJECT_DIR$/package.json" />
4
- <command value="run" />
5
- <scripts>
6
- <script value="build-dev" />
7
- </scripts>
8
- <node-interpreter value="project" />
9
- <envs />
10
- <method v="2" />
11
- </configuration>
12
- </component>
@@ -1,12 +0,0 @@
1
- <component name="ProjectRunConfigurationManager">
2
- <configuration default="false" name="eslint" type="js.build_tools.npm" nameIsGenerated="true">
3
- <package-json value="$PROJECT_DIR$/package.json" />
4
- <command value="run" />
5
- <scripts>
6
- <script value="eslint" />
7
- </scripts>
8
- <node-interpreter value="project" />
9
- <envs />
10
- <method v="2" />
11
- </configuration>
12
- </component>
package/.idea/vcs.xml DELETED
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="VcsDirectoryMappings">
4
- <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
- </component>
6
- </project>