@aidc-toolkit/core 0.9.12-beta → 0.9.14-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 +1 -116
- package/dist/index.js +1 -77
- package/package.json +9 -10
package/dist/index.cjs
CHANGED
|
@@ -1,119 +1,4 @@
|
|
|
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
|
-
I18NEnvironment: () => I18NEnvironment,
|
|
34
|
-
i18nAssertValidResources: () => i18nAssertValidResources,
|
|
35
|
-
i18nCoreInit: () => i18nCoreInit
|
|
36
|
-
});
|
|
37
|
-
module.exports = __toCommonJS(index_exports);
|
|
38
|
-
|
|
39
|
-
// src/locale/i18n.ts
|
|
40
|
-
var import_i18next_browser_languagedetector = __toESM(require("i18next-browser-languagedetector"), 1);
|
|
41
|
-
var import_i18next_cli_language_detector = __toESM(require("i18next-cli-language-detector"), 1);
|
|
42
|
-
var I18NEnvironment = /* @__PURE__ */ ((I18NEnvironment2) => {
|
|
43
|
-
I18NEnvironment2[I18NEnvironment2["CLI"] = 0] = "CLI";
|
|
44
|
-
I18NEnvironment2[I18NEnvironment2["Server"] = 1] = "Server";
|
|
45
|
-
I18NEnvironment2[I18NEnvironment2["Browser"] = 2] = "Browser";
|
|
46
|
-
return I18NEnvironment2;
|
|
47
|
-
})(I18NEnvironment || {});
|
|
48
|
-
function i18nAssertValidResources(enResources, lng, lngResources, parent) {
|
|
49
|
-
const enResourcesMap = new Map(Object.entries(enResources));
|
|
50
|
-
const lngResourcesMap = new Map(Object.entries(lngResources));
|
|
51
|
-
const isLocale = lng.includes("-");
|
|
52
|
-
for (const [enKey, enValue] of enResourcesMap) {
|
|
53
|
-
const lngValue = lngResourcesMap.get(enKey);
|
|
54
|
-
if (lngValue !== void 0) {
|
|
55
|
-
const enValueType = typeof enValue;
|
|
56
|
-
const lngValueType = typeof lngValue;
|
|
57
|
-
if (lngValueType !== enValueType) {
|
|
58
|
-
throw new Error(`Invalid value type ${lngValueType} for key ${parent === void 0 ? "" : `${parent}.`}${enKey} in ${lng} resources`);
|
|
59
|
-
}
|
|
60
|
-
if (enValueType === "object") {
|
|
61
|
-
i18nAssertValidResources(enValue, lng, lngValue, `${parent === void 0 ? "" : `${parent}.`}${enKey}`);
|
|
62
|
-
}
|
|
63
|
-
} else if (!isLocale) {
|
|
64
|
-
throw new Error(`Missing key ${parent === void 0 ? "" : `${parent}.`}${enKey} from ${lng} resources`);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
for (const [lngKey] of lngResourcesMap) {
|
|
68
|
-
if (!enResourcesMap.has(lngKey)) {
|
|
69
|
-
throw new Error(`Extraneous key ${parent === void 0 ? "" : `${parent}.`}${lngKey} in ${lng} resources`);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
function toLowerCase(s) {
|
|
74
|
-
return s.split(" ").map((word) => /[a-z]/.test(word) ? word.toLowerCase() : word).join(" ");
|
|
75
|
-
}
|
|
76
|
-
async function i18nCoreInit(i18next, environment, debug, defaultNS, ...resources) {
|
|
77
|
-
if (!i18next.isInitialized) {
|
|
78
|
-
const mergedResource = {};
|
|
79
|
-
for (const resource of resources) {
|
|
80
|
-
for (const [language, resourceLanguage] of Object.entries(resource)) {
|
|
81
|
-
if (!(language in mergedResource)) {
|
|
82
|
-
mergedResource[language] = {};
|
|
83
|
-
}
|
|
84
|
-
const mergedResourceLanguage = mergedResource[language];
|
|
85
|
-
for (const [namespace, resourceKey] of Object.entries(resourceLanguage)) {
|
|
86
|
-
mergedResourceLanguage[namespace] = resourceKey;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
let module2;
|
|
91
|
-
switch (environment) {
|
|
92
|
-
case 0 /* CLI */:
|
|
93
|
-
module2 = import_i18next_cli_language_detector.default;
|
|
94
|
-
break;
|
|
95
|
-
case 2 /* Browser */:
|
|
96
|
-
module2 = import_i18next_browser_languagedetector.default;
|
|
97
|
-
break;
|
|
98
|
-
default:
|
|
99
|
-
throw new Error("Not supported");
|
|
100
|
-
}
|
|
101
|
-
await i18next.use(module2).init({
|
|
102
|
-
debug,
|
|
103
|
-
resources: mergedResource,
|
|
104
|
-
fallbackLng: "en",
|
|
105
|
-
defaultNS
|
|
106
|
-
}).then(() => {
|
|
107
|
-
i18next.services.formatter?.add("toLowerCase", (value) => typeof value === "string" ? toLowerCase(value) : String(value));
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
112
|
-
0 && (module.exports = {
|
|
113
|
-
I18NEnvironment,
|
|
114
|
-
i18nAssertValidResources,
|
|
115
|
-
i18nCoreInit
|
|
116
|
-
});
|
|
1
|
+
"use strict";var b=Object.create;var d=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var h=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var x=(o,e)=>{for(var t in e)d(o,t,{get:e[t],enumerable:!0})},l=(o,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of R(e))!k.call(o,n)&&n!==t&&d(o,n,{get:()=>e[n],enumerable:!(r=j(e,n))||r.enumerable});return o};var p=(o,e,t)=>(t=o!=null?b(h(o)):{},l(e||!o||!o.__esModule?d(t,"default",{value:o,enumerable:!0}):t,o)),C=o=>l(d({},"__esModule",{value:!0}),o);var V={};x(V,{I18NEnvironment:()=>y,i18nAssertValidResources:()=>m,i18nCoreInit:()=>I});module.exports=C(V);var w=p(require("i18next-browser-languagedetector"),1),$=p(require("i18next-cli-language-detector"),1),y=(r=>(r[r.CLI=0]="CLI",r[r.Server=1]="Server",r[r.Browser=2]="Browser",r))(y||{});function m(o,e,t,r){let n=new Map(Object.entries(o)),i=new Map(Object.entries(t)),u=e.includes("-");for(let[s,c]of n){let a=i.get(s);if(a!==void 0){let f=typeof c,g=typeof a;if(g!==f)throw new Error(`Invalid value type ${g} for key ${r===void 0?"":`${r}.`}${s} in ${e} resources`);f==="object"&&m(c,e,a,`${r===void 0?"":`${r}.`}${s}`)}else if(!u)throw new Error(`Missing key ${r===void 0?"":`${r}.`}${s} from ${e} resources`)}for(let[s]of i)if(!n.has(s))throw new Error(`Extraneous key ${r===void 0?"":`${r}.`}${s} in ${e} resources`)}function M(o){return o.split(" ").map(e=>/[a-z]/.test(e)?e.toLowerCase():e).join(" ")}async function I(o,e,t,r,...n){if(!o.isInitialized){let i={};for(let s of n)for(let[c,a]of Object.entries(s)){c in i||(i[c]={});let f=i[c];for(let[g,L]of Object.entries(a))f[g]=L}let u;switch(e){case 0:u=$.default;break;case 2:u=w.default;break;default:throw new Error("Not supported")}await o.use(u).init({debug:t,resources:i,fallbackLng:"en",defaultNS:r}).then(()=>{o.services.formatter?.add("toLowerCase",s=>typeof s=="string"?M(s):String(s))})}}0&&(module.exports={I18NEnvironment,i18nAssertValidResources,i18nCoreInit});
|
|
117
2
|
/*!
|
|
118
3
|
* Copyright © 2024-2025 Dolphin Data Development Ltd. and AIDC Toolkit
|
|
119
4
|
* contributors
|
package/dist/index.js
CHANGED
|
@@ -1,80 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import I18nextBrowserLanguageDetector from "i18next-browser-languagedetector";
|
|
3
|
-
import I18nextCLILanguageDetector from "i18next-cli-language-detector";
|
|
4
|
-
var I18NEnvironment = /* @__PURE__ */ ((I18NEnvironment2) => {
|
|
5
|
-
I18NEnvironment2[I18NEnvironment2["CLI"] = 0] = "CLI";
|
|
6
|
-
I18NEnvironment2[I18NEnvironment2["Server"] = 1] = "Server";
|
|
7
|
-
I18NEnvironment2[I18NEnvironment2["Browser"] = 2] = "Browser";
|
|
8
|
-
return I18NEnvironment2;
|
|
9
|
-
})(I18NEnvironment || {});
|
|
10
|
-
function i18nAssertValidResources(enResources, lng, lngResources, parent) {
|
|
11
|
-
const enResourcesMap = new Map(Object.entries(enResources));
|
|
12
|
-
const lngResourcesMap = new Map(Object.entries(lngResources));
|
|
13
|
-
const isLocale = lng.includes("-");
|
|
14
|
-
for (const [enKey, enValue] of enResourcesMap) {
|
|
15
|
-
const lngValue = lngResourcesMap.get(enKey);
|
|
16
|
-
if (lngValue !== void 0) {
|
|
17
|
-
const enValueType = typeof enValue;
|
|
18
|
-
const lngValueType = typeof lngValue;
|
|
19
|
-
if (lngValueType !== enValueType) {
|
|
20
|
-
throw new Error(`Invalid value type ${lngValueType} for key ${parent === void 0 ? "" : `${parent}.`}${enKey} in ${lng} resources`);
|
|
21
|
-
}
|
|
22
|
-
if (enValueType === "object") {
|
|
23
|
-
i18nAssertValidResources(enValue, lng, lngValue, `${parent === void 0 ? "" : `${parent}.`}${enKey}`);
|
|
24
|
-
}
|
|
25
|
-
} else if (!isLocale) {
|
|
26
|
-
throw new Error(`Missing key ${parent === void 0 ? "" : `${parent}.`}${enKey} from ${lng} resources`);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
for (const [lngKey] of lngResourcesMap) {
|
|
30
|
-
if (!enResourcesMap.has(lngKey)) {
|
|
31
|
-
throw new Error(`Extraneous key ${parent === void 0 ? "" : `${parent}.`}${lngKey} in ${lng} resources`);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
function toLowerCase(s) {
|
|
36
|
-
return s.split(" ").map((word) => /[a-z]/.test(word) ? word.toLowerCase() : word).join(" ");
|
|
37
|
-
}
|
|
38
|
-
async function i18nCoreInit(i18next, environment, debug, defaultNS, ...resources) {
|
|
39
|
-
if (!i18next.isInitialized) {
|
|
40
|
-
const mergedResource = {};
|
|
41
|
-
for (const resource of resources) {
|
|
42
|
-
for (const [language, resourceLanguage] of Object.entries(resource)) {
|
|
43
|
-
if (!(language in mergedResource)) {
|
|
44
|
-
mergedResource[language] = {};
|
|
45
|
-
}
|
|
46
|
-
const mergedResourceLanguage = mergedResource[language];
|
|
47
|
-
for (const [namespace, resourceKey] of Object.entries(resourceLanguage)) {
|
|
48
|
-
mergedResourceLanguage[namespace] = resourceKey;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
let module;
|
|
53
|
-
switch (environment) {
|
|
54
|
-
case 0 /* CLI */:
|
|
55
|
-
module = I18nextCLILanguageDetector;
|
|
56
|
-
break;
|
|
57
|
-
case 2 /* Browser */:
|
|
58
|
-
module = I18nextBrowserLanguageDetector;
|
|
59
|
-
break;
|
|
60
|
-
default:
|
|
61
|
-
throw new Error("Not supported");
|
|
62
|
-
}
|
|
63
|
-
await i18next.use(module).init({
|
|
64
|
-
debug,
|
|
65
|
-
resources: mergedResource,
|
|
66
|
-
fallbackLng: "en",
|
|
67
|
-
defaultNS
|
|
68
|
-
}).then(() => {
|
|
69
|
-
i18next.services.formatter?.add("toLowerCase", (value) => typeof value === "string" ? toLowerCase(value) : String(value));
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
export {
|
|
74
|
-
I18NEnvironment,
|
|
75
|
-
i18nAssertValidResources,
|
|
76
|
-
i18nCoreInit
|
|
77
|
-
};
|
|
1
|
+
import l from"i18next-browser-languagedetector";import p from"i18next-cli-language-detector";var w=(e=>(e[e.CLI=0]="CLI",e[e.Server=1]="Server",e[e.Browser=2]="Browser",e))(w||{});function $(s,r,g,e){let u=new Map(Object.entries(s)),t=new Map(Object.entries(g)),i=r.includes("-");for(let[o,n]of u){let c=t.get(o);if(c!==void 0){let a=typeof n,f=typeof c;if(f!==a)throw new Error(`Invalid value type ${f} for key ${e===void 0?"":`${e}.`}${o} in ${r} resources`);a==="object"&&$(n,r,c,`${e===void 0?"":`${e}.`}${o}`)}else if(!i)throw new Error(`Missing key ${e===void 0?"":`${e}.`}${o} from ${r} resources`)}for(let[o]of t)if(!u.has(o))throw new Error(`Extraneous key ${e===void 0?"":`${e}.`}${o} in ${r} resources`)}function y(s){return s.split(" ").map(r=>/[a-z]/.test(r)?r.toLowerCase():r).join(" ")}async function b(s,r,g,e,...u){if(!s.isInitialized){let t={};for(let o of u)for(let[n,c]of Object.entries(o)){n in t||(t[n]={});let a=t[n];for(let[f,d]of Object.entries(c))a[f]=d}let i;switch(r){case 0:i=p;break;case 2:i=l;break;default:throw new Error("Not supported")}await s.use(i).init({debug:g,resources:t,fallbackLng:"en",defaultNS:e}).then(()=>{s.services.formatter?.add("toLowerCase",o=>typeof o=="string"?y(o):String(o))})}}export{w as I18NEnvironment,$ as i18nAssertValidResources,b as i18nCoreInit};
|
|
78
2
|
/*!
|
|
79
3
|
* Copyright © 2024-2025 Dolphin Data Development Ltd. and AIDC Toolkit
|
|
80
4
|
* contributors
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aidc-toolkit/core",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.14-beta",
|
|
4
4
|
"description": "Core functionality for AIDC Toolkit",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,17 +19,16 @@
|
|
|
19
19
|
"url": "https://www.linkedin.com/in/kdean"
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"build
|
|
22
|
+
"update-aidc-toolkit": "npm update @aidc-toolkit/dev",
|
|
23
|
+
"lint": "eslint",
|
|
24
|
+
"build:core": "tsup --config node_modules/@aidc-toolkit/dev/tsup.config.ts",
|
|
25
|
+
"build:dev": "npm run build:core && tsc --project node_modules/@aidc-toolkit/dev/tsconfig-declaration.json",
|
|
26
|
+
"build:release": "npm run build:core -- --minify",
|
|
27
|
+
"build:doc": "npm run build:dev",
|
|
28
|
+
"publish-dev": "publish-dev"
|
|
25
29
|
},
|
|
26
30
|
"devDependencies": {
|
|
27
|
-
"@aidc-toolkit/dev": "^0.9.
|
|
28
|
-
"eslint": "^9.20.1",
|
|
29
|
-
"jiti": "^2.4.2",
|
|
30
|
-
"ts-node": "^10.9.2",
|
|
31
|
-
"tsup": "^8.3.6",
|
|
32
|
-
"typescript": "^5.7.3"
|
|
31
|
+
"@aidc-toolkit/dev": "^0.9.14-beta"
|
|
33
32
|
},
|
|
34
33
|
"dependencies": {
|
|
35
34
|
"i18next": "^24.2.2",
|