@i18n-micro/core
Advanced tools
| export { buildInspectorState, buildInspectorTree, countTranslationKeys, decodeInspectorPath, encodeInspectorPath, flattenTranslationNode, getByInspectorPath, parseInspectorNodeId, type BuildInspectorTreeOptions, type I18nDevtoolsInspectorNode, type I18nDevtoolsStateSnapshot, } from './devtools'; |
| "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k={label:"Active",textColor:16777215,backgroundColor:4372611,tooltip:"Current locale and route context"},A="root",m="active",g="locale|",f="chunk|",i="key|",d=e=>e!==null&&typeof e=="object"&&!Array.isArray(e);function T(e){return typeof e=="string"?JSON.stringify(e):e===null?"null":e===void 0?"undefined":typeof e=="object"?Array.isArray(e)?`[Array(${e.length})]`:"{…}":String(e)}function h(e,t,n,o){return e===n&&t===o?[k]:void 0}function $(e,t){const n=`${t}:`,o=new Set;for(const c of e.translations.keys())c.startsWith(n)&&o.add(c.slice(n.length)||"index");return[...o].sort()}function _(e,t){const n=new Set(t.map(o=>o.code));for(const o of e.translations.keys()){const c=o.split(":")[0];c&&n.add(c)}return[...n].sort()}function b(e){return e.map(t=>encodeURIComponent(t)).join("/")}function v(e){return e?e.split("/").map(t=>decodeURIComponent(t)):[]}function N(e,t){let n=e;for(const o of t){if(!d(n)||!Object.prototype.hasOwnProperty.call(n,o))return;n=n[o]}return n}function C(e){if(!e||e===A)return{kind:"root"};if(e===m)return{kind:"active"};if(e.startsWith(g))return{kind:"locale",locale:e.slice(g.length)};if(e.startsWith(f)){const[t="",n="index"]=e.slice(f.length).split("|");return{kind:"chunk",locale:t,routeName:n}}if(e.startsWith(i)){const t=e.slice(i.length).split("|"),n=t[0]??"",o=t[1]??"index",c=t.slice(2).join("|");return{kind:"key",locale:n,routeName:o,path:c,segments:v(c)}}return{kind:"root"}}function y(e,t,n){return{...n,id:`${i}${e}|${t}|${n.id.slice(i.length)}`}}function u(e,t=[]){const n=t.length===0?e:N(e,t);return d(n)?Object.keys(n).filter(o=>o!=="__proto__").map(o=>{const c=[...t,o],r=n[o],a=d(r);return{id:`${i}${b(c)}`,label:a?o:`${o}: ${T(r)}`,children:a?[]:void 0}}).sort((o,c)=>o.label.localeCompare(c.label)):[]}function L(e){const t=C(e.nodeId),n=e.activeLocale,o=e.activeRouteName||"index";if(t.kind==="root"){const c=_(e.storage,e.configuredLocales),r=[{id:m,label:`Active (${n}:${o})`,tags:[k]}];for(const a of c){const l=e.configuredLocales.find(s=>s.code===a),p=$(e.storage,a);r.push({id:`${g}${a}`,label:l?.displayName?`${a} (${l.displayName})`:a,tags:a===n?[{...k,tooltip:"Active locale"}]:void 0});for(const s of p)r.push({id:`${f}${a}|${s}`,label:`${a}:${s}`,tags:h(a,s,n,o)})}return r}if(t.kind==="active")return u(e.activeTranslations??{}).map(c=>y(n,o,c));if(t.kind==="locale"&&t.locale){const c=t.locale;return $(e.storage,c).map(r=>({id:`${f}${c}|${r}`,label:r,children:[],tags:h(c,r,n,o)}))}if(t.kind==="chunk"&&t.locale){const c=t.locale,r=t.routeName||"index",a=e.storage.translations.get(`${c}:${r}`);return u(a??{}).map(l=>y(c,r,l))}if(t.kind==="key"&&t.locale){const c=t.locale,r=t.routeName||"index",a=e.storage.translations.get(`${c}:${r}`),l=t.segments??[],s=n===c&&o===r?e.activeTranslations??a??{}:a??{};return u(s,l).map(I=>y(c,r,I))}return[]}function P(e){return{Context:[{key:"locale",value:e.locale},{key:"routeName",value:e.routeName},{key:"strategy",value:e.strategy??"—"},{key:"defaultLocale",value:e.defaultLocale??"—"},{key:"fallbackLocale",value:e.fallbackLocale??"—"},{key:"cachedChunks",value:e.cachedChunks}],Locales:e.locales.map(t=>({key:t.code,value:t.displayName??t.code,editable:!1}))}}function x(e){if(!e||typeof e!="object")return 0;const t=new Set,n=(o,c="")=>{for(const r of Object.keys(o)){if(r==="__proto__")continue;const a=c?`${c}.${r}`:r;t.add(a);const l=o[r];d(l)&&n(l,a)}};return n(e),t.size}exports.buildInspectorState=P;exports.buildInspectorTree=L;exports.countTranslationKeys=x;exports.decodeInspectorPath=v;exports.encodeInspectorPath=b;exports.flattenTranslationNode=u;exports.getByInspectorPath=N;exports.parseInspectorNodeId=C; |
| import { Locale, Translations } from '@i18n-micro/types'; | ||
| import { TranslationStorage } from './translation'; | ||
| export interface I18nDevtoolsInspectorNode { | ||
| id: string; | ||
| label: string; | ||
| children?: I18nDevtoolsInspectorNode[]; | ||
| tags?: Array<{ | ||
| label: string; | ||
| textColor: number; | ||
| backgroundColor: number; | ||
| tooltip?: string; | ||
| }>; | ||
| } | ||
| export interface I18nDevtoolsStateSnapshot { | ||
| locale: string; | ||
| routeName: string; | ||
| strategy?: string; | ||
| defaultLocale?: string; | ||
| fallbackLocale?: string; | ||
| cachedChunks: number; | ||
| locales: Array<{ | ||
| code: string; | ||
| displayName?: string; | ||
| disabled?: boolean; | ||
| }>; | ||
| } | ||
| export interface BuildInspectorTreeOptions { | ||
| nodeId: string; | ||
| storage: TranslationStorage; | ||
| configuredLocales: Locale[]; | ||
| activeLocale: string; | ||
| activeRouteName: string; | ||
| activeTranslations?: Record<string, unknown>; | ||
| } | ||
| /** | ||
| * Encode path segments so a literal key `"a.b"` and nested path `a → b` get distinct node IDs. | ||
| */ | ||
| export declare function encodeInspectorPath(segments: string[]): string; | ||
| export declare function decodeInspectorPath(encoded: string): string[]; | ||
| export declare function getByInspectorPath(obj: Record<string, unknown>, segments: string[]): unknown; | ||
| export declare function parseInspectorNodeId(nodeId: string): { | ||
| kind: 'root' | 'active' | 'locale' | 'chunk' | 'key'; | ||
| locale?: string; | ||
| routeName?: string; | ||
| path?: string; | ||
| segments?: string[]; | ||
| }; | ||
| export declare function flattenTranslationNode(obj: Record<string, unknown>, parentSegments?: string[]): I18nDevtoolsInspectorNode[]; | ||
| export declare function buildInspectorTree(options: BuildInspectorTreeOptions): I18nDevtoolsInspectorNode[]; | ||
| export declare function buildInspectorState(snapshot: I18nDevtoolsStateSnapshot): Record<string, Array<{ | ||
| key: string; | ||
| value: unknown; | ||
| editable?: boolean; | ||
| }>>; | ||
| export declare function countTranslationKeys(translations: Translations | Record<string, unknown> | undefined): number; |
| import { Locale, Translations } from '@i18n-micro/types'; | ||
| import { TranslationStorage } from './translation'; | ||
| export interface I18nDevtoolsInspectorNode { | ||
| id: string; | ||
| label: string; | ||
| children?: I18nDevtoolsInspectorNode[]; | ||
| tags?: Array<{ | ||
| label: string; | ||
| textColor: number; | ||
| backgroundColor: number; | ||
| tooltip?: string; | ||
| }>; | ||
| } | ||
| export interface I18nDevtoolsStateSnapshot { | ||
| locale: string; | ||
| routeName: string; | ||
| strategy?: string; | ||
| defaultLocale?: string; | ||
| fallbackLocale?: string; | ||
| cachedChunks: number; | ||
| locales: Array<{ | ||
| code: string; | ||
| displayName?: string; | ||
| disabled?: boolean; | ||
| }>; | ||
| } | ||
| export interface BuildInspectorTreeOptions { | ||
| nodeId: string; | ||
| storage: TranslationStorage; | ||
| configuredLocales: Locale[]; | ||
| activeLocale: string; | ||
| activeRouteName: string; | ||
| activeTranslations?: Record<string, unknown>; | ||
| } | ||
| /** | ||
| * Encode path segments so a literal key `"a.b"` and nested path `a → b` get distinct node IDs. | ||
| */ | ||
| export declare function encodeInspectorPath(segments: string[]): string; | ||
| export declare function decodeInspectorPath(encoded: string): string[]; | ||
| export declare function getByInspectorPath(obj: Record<string, unknown>, segments: string[]): unknown; | ||
| export declare function parseInspectorNodeId(nodeId: string): { | ||
| kind: 'root' | 'active' | 'locale' | 'chunk' | 'key'; | ||
| locale?: string; | ||
| routeName?: string; | ||
| path?: string; | ||
| segments?: string[]; | ||
| }; | ||
| export declare function flattenTranslationNode(obj: Record<string, unknown>, parentSegments?: string[]): I18nDevtoolsInspectorNode[]; | ||
| export declare function buildInspectorTree(options: BuildInspectorTreeOptions): I18nDevtoolsInspectorNode[]; | ||
| export declare function buildInspectorState(snapshot: I18nDevtoolsStateSnapshot): Record<string, Array<{ | ||
| key: string; | ||
| value: unknown; | ||
| editable?: boolean; | ||
| }>>; | ||
| export declare function countTranslationKeys(translations: Translations | Record<string, unknown> | undefined): number; |
| const y = { | ||
| label: "Active", | ||
| textColor: 16777215, | ||
| backgroundColor: 4372611, | ||
| tooltip: "Current locale and route context" | ||
| }, b = "root", p = "active", g = "locale|", u = "chunk|", s = "key|", f = (e) => e !== null && typeof e == "object" && !Array.isArray(e); | ||
| function N(e) { | ||
| return typeof e == "string" ? JSON.stringify(e) : e === null ? "null" : e === void 0 ? "undefined" : typeof e == "object" ? Array.isArray(e) ? `[Array(${e.length})]` : "{…}" : String(e); | ||
| } | ||
| function m(e, t, n, o) { | ||
| return e === n && t === o ? [y] : void 0; | ||
| } | ||
| function h(e, t) { | ||
| const n = `${t}:`, o = /* @__PURE__ */ new Set(); | ||
| for (const c of e.translations.keys()) | ||
| c.startsWith(n) && o.add(c.slice(n.length) || "index"); | ||
| return [...o].sort(); | ||
| } | ||
| function C(e, t) { | ||
| const n = new Set(t.map((o) => o.code)); | ||
| for (const o of e.translations.keys()) { | ||
| const c = o.split(":")[0]; | ||
| c && n.add(c); | ||
| } | ||
| return [...n].sort(); | ||
| } | ||
| function A(e) { | ||
| return e.map((t) => encodeURIComponent(t)).join("/"); | ||
| } | ||
| function _(e) { | ||
| return e ? e.split("/").map((t) => decodeURIComponent(t)) : []; | ||
| } | ||
| function x(e, t) { | ||
| let n = e; | ||
| for (const o of t) { | ||
| if (!f(n) || !Object.prototype.hasOwnProperty.call(n, o)) return; | ||
| n = n[o]; | ||
| } | ||
| return n; | ||
| } | ||
| function L(e) { | ||
| if (!e || e === b) return { kind: "root" }; | ||
| if (e === p) return { kind: "active" }; | ||
| if (e.startsWith(g)) | ||
| return { kind: "locale", locale: e.slice(g.length) }; | ||
| if (e.startsWith(u)) { | ||
| const [t = "", n = "index"] = e.slice(u.length).split("|"); | ||
| return { kind: "chunk", locale: t, routeName: n }; | ||
| } | ||
| if (e.startsWith(s)) { | ||
| const t = e.slice(s.length).split("|"), n = t[0] ?? "", o = t[1] ?? "index", c = t.slice(2).join("|"); | ||
| return { kind: "key", locale: n, routeName: o, path: c, segments: _(c) }; | ||
| } | ||
| return { kind: "root" }; | ||
| } | ||
| function d(e, t, n) { | ||
| return { | ||
| ...n, | ||
| id: `${s}${e}|${t}|${n.id.slice(s.length)}` | ||
| }; | ||
| } | ||
| function k(e, t = []) { | ||
| const n = t.length === 0 ? e : x(e, t); | ||
| return f(n) ? Object.keys(n).filter((o) => o !== "__proto__").map((o) => { | ||
| const c = [...t, o], r = n[o], a = f(r); | ||
| return { | ||
| id: `${s}${A(c)}`, | ||
| label: a ? o : `${o}: ${N(r)}`, | ||
| children: a ? [] : void 0 | ||
| }; | ||
| }).sort((o, c) => o.label.localeCompare(c.label)) : []; | ||
| } | ||
| function O(e) { | ||
| const t = L(e.nodeId), n = e.activeLocale, o = e.activeRouteName || "index"; | ||
| if (t.kind === "root") { | ||
| const c = C(e.storage, e.configuredLocales), r = [ | ||
| { | ||
| id: p, | ||
| label: `Active (${n}:${o})`, | ||
| tags: [y] | ||
| } | ||
| ]; | ||
| for (const a of c) { | ||
| const l = e.configuredLocales.find((i) => i.code === a), $ = h(e.storage, a); | ||
| r.push({ | ||
| id: `${g}${a}`, | ||
| label: l?.displayName ? `${a} (${l.displayName})` : a, | ||
| tags: a === n ? [{ ...y, tooltip: "Active locale" }] : void 0 | ||
| }); | ||
| for (const i of $) | ||
| r.push({ | ||
| id: `${u}${a}|${i}`, | ||
| label: `${a}:${i}`, | ||
| tags: m(a, i, n, o) | ||
| }); | ||
| } | ||
| return r; | ||
| } | ||
| if (t.kind === "active") | ||
| return k(e.activeTranslations ?? {}).map((c) => d(n, o, c)); | ||
| if (t.kind === "locale" && t.locale) { | ||
| const c = t.locale; | ||
| return h(e.storage, c).map((r) => ({ | ||
| id: `${u}${c}|${r}`, | ||
| label: r, | ||
| children: [], | ||
| tags: m(c, r, n, o) | ||
| })); | ||
| } | ||
| if (t.kind === "chunk" && t.locale) { | ||
| const c = t.locale, r = t.routeName || "index", a = e.storage.translations.get(`${c}:${r}`); | ||
| return k(a ?? {}).map((l) => d(c, r, l)); | ||
| } | ||
| if (t.kind === "key" && t.locale) { | ||
| const c = t.locale, r = t.routeName || "index", a = e.storage.translations.get(`${c}:${r}`), l = t.segments ?? [], i = n === c && o === r ? e.activeTranslations ?? a ?? {} : a ?? {}; | ||
| return k(i, l).map((v) => d(c, r, v)); | ||
| } | ||
| return []; | ||
| } | ||
| function T(e) { | ||
| return { | ||
| Context: [ | ||
| { key: "locale", value: e.locale }, | ||
| { key: "routeName", value: e.routeName }, | ||
| { key: "strategy", value: e.strategy ?? "—" }, | ||
| { key: "defaultLocale", value: e.defaultLocale ?? "—" }, | ||
| { key: "fallbackLocale", value: e.fallbackLocale ?? "—" }, | ||
| { key: "cachedChunks", value: e.cachedChunks } | ||
| ], | ||
| Locales: e.locales.map((t) => ({ | ||
| key: t.code, | ||
| value: t.displayName ?? t.code, | ||
| editable: !1 | ||
| })) | ||
| }; | ||
| } | ||
| function E(e) { | ||
| if (!e || typeof e != "object") return 0; | ||
| const t = /* @__PURE__ */ new Set(), n = (o, c = "") => { | ||
| for (const r of Object.keys(o)) { | ||
| if (r === "__proto__") continue; | ||
| const a = c ? `${c}.${r}` : r; | ||
| t.add(a); | ||
| const l = o[r]; | ||
| f(l) && n(l, a); | ||
| } | ||
| }; | ||
| return n(e), t.size; | ||
| } | ||
| export { | ||
| T as buildInspectorState, | ||
| O as buildInspectorTree, | ||
| E as countTranslationKeys, | ||
| _ as decodeInspectorPath, | ||
| A as encodeInspectorPath, | ||
| k as flattenTranslationNode, | ||
| x as getByInspectorPath, | ||
| L as parseInspectorNodeId | ||
| }; |
+17
-2
| { | ||
| "name": "@i18n-micro/core", | ||
| "version": "1.3.11", | ||
| "version": "1.3.13", | ||
| "description": "Core utilities for translations, formatting, and locale routing in Nuxt I18n Micro.", | ||
@@ -67,2 +67,17 @@ "keywords": [ | ||
| }, | ||
| "./devtools": { | ||
| "production": { | ||
| "types": "./dist/devtools.d.ts", | ||
| "default": "./dist/devtools.mjs" | ||
| }, | ||
| "import": { | ||
| "types": "./dist/devtools.d.ts", | ||
| "default": "./dist/devtools.mjs" | ||
| }, | ||
| "require": { | ||
| "types": "./dist/devtools.d.cts", | ||
| "default": "./dist/devtools.cjs" | ||
| }, | ||
| "default": "./dist/devtools.mjs" | ||
| }, | ||
| "./package.json": "./package.json" | ||
@@ -74,3 +89,3 @@ }, | ||
| "dependencies": { | ||
| "@i18n-micro/types": "^1.2.10" | ||
| "@i18n-micro/types": "^1.2.11" | ||
| }, | ||
@@ -77,0 +92,0 @@ "devDependencies": { |
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
74523
21.77%21
31.25%1124
25.87%3
50%Updated