@aidc-toolkit/core 0.0.1

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,32 @@
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 ADDED
@@ -0,0 +1,9 @@
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>
@@ -0,0 +1,7 @@
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 ADDED
@@ -0,0 +1,6 @@
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>
@@ -0,0 +1,8 @@
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>
@@ -0,0 +1,12 @@
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>
@@ -0,0 +1,12 @@
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 ADDED
@@ -0,0 +1,6 @@
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>
package/README.md ADDED
@@ -0,0 +1,38 @@
1
+ The AIDC Toolkit `core` package contains artefacts to support other AIDC Toolkit packages; it does not itself provide
2
+ any of the functionality of the AIDC Toolkit. It is a required dependency for all AIDC Toolkit packages.
3
+
4
+ ## Localization
5
+
6
+ All AIDC Toolkit packages require localization. The localization functionality in this package simplifies initialization
7
+ and allows packages to share a common internationalization engine, whose initialization is the responsibility of the
8
+ client application. Packages install their resources as follows in `i18n.ts` or similar:
9
+
10
+ ```typescript
11
+ import { i18nAddResourceBundle, i18next } from "@aidc-toolkit/core";
12
+ import { localeStrings as enLocaleStrings } from "./en/locale_strings.js";
13
+
14
+ export const packageNS = "aidct_package";
15
+
16
+ i18nAddResourceBundle("en", packageNS, enLocaleStrings);
17
+
18
+ export default i18next;
19
+ ```
20
+
21
+ The resource types are declared in `i18next.d.ts` or similar:
22
+
23
+ ```typescript
24
+ import type { localeStrings } from "./en/locale_strings.js";
25
+
26
+ declare module "i18next" {
27
+ interface CustomTypeOptions {
28
+ resources: {
29
+ // Extract the type from the English locale strings object.
30
+ aidct_package: typeof localeStrings;
31
+ };
32
+ }
33
+ }
34
+ ```
35
+
36
+ ## Resources
37
+
38
+ The `resource` folder contains common resources (e.g., AIDC Toolkit icon) usable by all AIDC Toolkit packages.
@@ -0,0 +1,15 @@
1
+ import tseslint from "typescript-eslint";
2
+ import js from "@eslint/js";
3
+ import stylistic from "@stylistic/eslint-plugin";
4
+ import jsdoc from "eslint-plugin-jsdoc";
5
+ import esLintConfigLove from "eslint-config-love";
6
+ import { esLintConfigAIDCToolkit } from "@aidc-toolkit/dev";
7
+
8
+ export default tseslint.config(
9
+ js.configs.recommended,
10
+ ...tseslint.configs.strictTypeChecked,
11
+ stylistic.configs["recommended-flat"],
12
+ jsdoc.configs["flat/recommended-typescript"],
13
+ esLintConfigLove,
14
+ esLintConfigAIDCToolkit
15
+ );
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@aidc-toolkit/core",
3
+ "version": "0.0.1",
4
+ "description": "Core functionality for AIDC Toolkit",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "homepage": "https://github.com/aidc-toolkit",
8
+ "repository": "github:aidc-toolkit/core",
9
+ "bugs": {
10
+ "url": "https://github.com/aidc-toolkit/core/issues"
11
+ },
12
+ "license": "Apache-2.0",
13
+ "author": {
14
+ "name": "Kevin Dean",
15
+ "email": "Kevin.Dean@datadevelopment.com",
16
+ "url": "https://www.linkedin.com/in/kdean"
17
+ },
18
+ "scripts": {
19
+ "eslint": "eslint .",
20
+ "build": "tsup src/index.ts --format cjs,esm --dts",
21
+ "test": "vitest run"
22
+ },
23
+ "devDependencies": {
24
+ "@aidc-toolkit/dev": "^0.0.1",
25
+ "@eslint/js": "^9.10.0",
26
+ "@stylistic/eslint-plugin": "^2.7.2",
27
+ "eslint-config-love": "^64.0.0",
28
+ "eslint-plugin-jsdoc": "^50.2.2",
29
+ "ts-node": "^10.9.2",
30
+ "tsup": "^8.2.4",
31
+ "typescript": "^5.5.4",
32
+ "typescript-eslint": "^8.4.0",
33
+ "vitest": "^2.0.5"
34
+ },
35
+ "dependencies": {
36
+ "i18next": "^23.14.0",
37
+ "i18next-browser-languagedetector": "^8.0.0",
38
+ "i18next-cli-language-detector": "^1.1.8"
39
+ }
40
+ }
Binary file
Binary file
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./locale/i18n.js";
2
+ export { default as i18next } from "./locale/i18n.js";
@@ -0,0 +1,110 @@
1
+ import i18next from "i18next";
2
+ import I18nextBrowserLanguageDetector from "i18next-browser-languageDetector";
3
+ import I18nextCLILanguageDetector from "i18next-cli-language-detector";
4
+
5
+ export default i18next;
6
+
7
+ /**
8
+ * Internal type to maintain resource bundles added before initialization.
9
+ */
10
+ interface ResourceBundle {
11
+ lng: string;
12
+ ns: string;
13
+ resources: object;
14
+ }
15
+
16
+ /**
17
+ * Internal array to maintain resource bundles added before initialization.
18
+ */
19
+ let pendingResourceBundles: ResourceBundle[] | undefined = [];
20
+
21
+ /**
22
+ * Internationalization operating environment.
23
+ */
24
+ export enum I18NEnvironment {
25
+ /**
26
+ * Command-line interface (e.g., unit tests).
27
+ */
28
+ CLI,
29
+
30
+ /**
31
+ * Web server.
32
+ */
33
+ Server,
34
+
35
+ /**
36
+ * Web browser.
37
+ */
38
+ Browser
39
+ }
40
+
41
+ /**
42
+ * Initialize internationalization.
43
+ *
44
+ * @param environment
45
+ * Environment in which the application is running.
46
+ *
47
+ * @param debug
48
+ * Debug setting.
49
+ */
50
+ export async function i18nInit(environment: I18NEnvironment, debug = false): Promise<void> {
51
+ if (pendingResourceBundles !== undefined) {
52
+ let module: object;
53
+
54
+ switch (environment) {
55
+ case I18NEnvironment.CLI:
56
+ module = I18nextCLILanguageDetector;
57
+ break;
58
+
59
+ case I18NEnvironment.Browser:
60
+ module = I18nextBrowserLanguageDetector;
61
+ break;
62
+
63
+ default:
64
+ throw new Error("Not supported");
65
+ }
66
+
67
+ await i18next.use(module as never).init({
68
+ fallbackLng: "en",
69
+ debug,
70
+ resources: {}
71
+ }).then(() => {
72
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
73
+ const initResourceBundles = pendingResourceBundles!;
74
+
75
+ // No need to manage pending resource bundles past this point.
76
+ pendingResourceBundles = undefined;
77
+
78
+ // Add pending resource bundles.
79
+ initResourceBundles.forEach((initResourceBundle) => {
80
+ i18nAddResourceBundle(initResourceBundle.lng, initResourceBundle.ns, initResourceBundle.resources);
81
+ });
82
+ });
83
+ } else {
84
+ throw new Error("i18n already initialized");
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Add a resource bundle.
90
+ *
91
+ * @param lng
92
+ * Language.
93
+ *
94
+ * @param ns
95
+ * Namespace.
96
+ *
97
+ * @param resources
98
+ * Resources.
99
+ */
100
+ export function i18nAddResourceBundle(lng: string, ns: string, resources: object): void {
101
+ if (pendingResourceBundles !== undefined) {
102
+ pendingResourceBundles.push({
103
+ lng,
104
+ ns,
105
+ resources
106
+ });
107
+ } else {
108
+ i18next.addResourceBundle(lng, ns, resources);
109
+ }
110
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "@aidc-toolkit/dev/tsconfig.json"
3
+ }
package/typedoc.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "$schema": "https://typedoc.org/schema.json",
3
+ "extends": [
4
+ "@aidc-toolkit/dev/typedoc.json"
5
+ ],
6
+ "name": "Core",
7
+ "entryPoints": [
8
+ "src/index.ts"
9
+ ]
10
+ }