@aidc-toolkit/core 0.9.3 → 0.9.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.
@@ -0,0 +1,21 @@
1
+ name: Build and publish
2
+
3
+ on:
4
+ release:
5
+ types:
6
+ - published
7
+
8
+ jobs:
9
+ build-and-publish:
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - name: Build and publish core
14
+ uses: aidc-toolkit/dev/.github/actions/build-publish@main
15
+ with:
16
+ project: core
17
+ node_version: ${{ vars.NODE_VERSION }}
18
+ node_auth_token: ${{ secrets.NODE_AUTH_TOKEN }}
19
+ no_test: true
20
+ terminal_pre_build: ${{ vars.TERMINAL_PRE_BUILD }}
21
+ terminal_post_build: ${{ vars.TERMINAL_POST_BUILD }}
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) => value.toLowerCase());
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) => value.toLowerCase());
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.3",
3
+ "version": "0.9.5",
4
4
  "description": "Core functionality for AIDC Toolkit",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -24,14 +24,15 @@
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.3",
28
- "eslint": "^9.14.0",
27
+ "@aidc-toolkit/dev": "^0.9.5",
28
+ "eslint": "^9.15.0",
29
29
  "ts-node": "^10.9.2",
30
30
  "tsup": "^8.3.5",
31
31
  "typescript": "^5.6.3"
32
32
  },
33
33
  "dependencies": {
34
- "i18next": "^23.16.5",
34
+ "@rollup/rollup-linux-x64-gnu": "^4.27.3",
35
+ "i18next": "^23.16.8",
35
36
  "i18next-browser-languagedetector": "^8.0.0",
36
37
  "i18next-cli-language-detector": "^1.1.8"
37
38
  }
@@ -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}}
@@ -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>