@aidc-toolkit/core 0.9.2 → 0.9.4

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/eslint.config.js CHANGED
@@ -1,13 +1,3 @@
1
- import tseslint from "typescript-eslint";
2
- import stylistic from "@stylistic/eslint-plugin";
3
- import jsdoc from "eslint-plugin-jsdoc";
4
- import esLintConfigLove from "eslint-config-love";
5
1
  import { esLintConfigAIDCToolkit } from "@aidc-toolkit/dev";
6
2
 
7
- export default tseslint.config(
8
- ...tseslint.configs.strictTypeChecked,
9
- stylistic.configs["recommended-flat"],
10
- jsdoc.configs["flat/recommended-typescript"],
11
- esLintConfigLove,
12
- ...esLintConfigAIDCToolkit
13
- );
3
+ export default esLintConfigAIDCToolkit;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aidc-toolkit/core",
3
- "version": "0.9.2",
3
+ "version": "0.9.4",
4
4
  "description": "Core functionality for AIDC Toolkit",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -21,17 +21,14 @@
21
21
  "scripts": {
22
22
  "eslint": "eslint .",
23
23
  "build": "tsup src/index.ts --clean --format cjs,esm --dts",
24
- "build-dev": "npm run build && tsc src/index.ts --outDir dist --target esnext --moduleResolution nodenext --module nodenext --emitDeclarationOnly --declaration --declarationMap"
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.2",
28
- "@stylistic/eslint-plugin": "^2.10.1",
29
- "eslint-config-love": "^98.0.2",
30
- "eslint-plugin-jsdoc": "^50.5.0",
27
+ "@aidc-toolkit/dev": "^0.9.4",
28
+ "eslint": "^9.15.0",
31
29
  "ts-node": "^10.9.2",
32
30
  "tsup": "^8.3.5",
33
- "typescript": "^5.6.3",
34
- "typescript-eslint": "^8.14.0"
31
+ "typescript": "^5.6.3"
35
32
  },
36
33
  "dependencies": {
37
34
  "i18next": "^23.16.5",
@@ -82,6 +82,9 @@ export async function i18nInit(environment: I18NEnvironment, debug = false): Pro
82
82
  debug,
83
83
  resources: {}
84
84
  }).then(() => {
85
+ // Add toLowerCase function.
86
+ i18next.services.formatter?.add("toLowerCase", value => (value as string).toLowerCase());
87
+
85
88
  // Add pending resource bundles.
86
89
  for (const initResourceBundle of initResourceBundles) {
87
90
  i18nAddResourceBundle(initResourceBundle.lng, initResourceBundle.ns, initResourceBundle.resources);
@@ -114,6 +117,55 @@ export function i18nAddResourceBundle(lng: string, ns: string, resources: object
114
117
  resources
115
118
  });
116
119
  } else {
120
+ // Already initialized; add resource bundle directly.
117
121
  i18next.addResourceBundle(lng, ns, resources);
118
122
  }
119
123
  }
124
+
125
+ /**
126
+ * Assert that language resources are a type match for English (default) resources.
127
+ *
128
+ * @param enResources
129
+ * English resources.
130
+ *
131
+ * @param lng
132
+ * Language.
133
+ *
134
+ * @param lngResources
135
+ * Language resources.
136
+ *
137
+ * @param parent
138
+ * Parent key name (set recursively).
139
+ */
140
+ export function i18nAssertValidResources(enResources: object, lng: string, lngResources: object, parent?: string): void {
141
+ const enResourcesMap = new Map<string, object>(Object.entries(enResources));
142
+ const lngResourcesMap = new Map<string, object>(Object.entries(lngResources));
143
+
144
+ const isLocale = lng.includes("-");
145
+
146
+ for (const [enKey, enValue] of enResourcesMap) {
147
+ const lngValue = lngResourcesMap.get(enKey);
148
+
149
+ if (lngValue !== undefined) {
150
+ const enValueType = typeof enValue;
151
+ const lngValueType = typeof lngValue;
152
+
153
+ if (lngValueType !== enValueType) {
154
+ throw new Error(`Invalid value type ${lngValueType} for key ${parent === undefined ? "" : `${parent}.`}${enKey} in ${lng} resources`);
155
+ }
156
+
157
+ if (enValueType === "object") {
158
+ i18nAssertValidResources(enValue, lng, lngValue, `${parent === undefined ? "" : `${parent}.`}${enKey}`);
159
+ }
160
+ // Locale falls back to raw language so ignore if missing.
161
+ } else if (!isLocale) {
162
+ throw new Error(`Missing key ${parent === undefined ? "" : `${parent}.`}${enKey} from ${lng} resources`);
163
+ }
164
+ }
165
+
166
+ for (const [lngKey] of lngResourcesMap) {
167
+ if (!enResourcesMap.has(lngKey)) {
168
+ throw new Error(`Extraneous key ${parent === undefined ? "" : `${parent}.`}${lngKey} in ${lng} resources`);
169
+ }
170
+ }
171
+ }