@i18n-micro/utils 1.0.0 → 1.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.
package/dist/build.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("node:fs"),i=require("node:path"),b=require("globby"),M=require("./deep-merge.cjs");async function x(h,w,c,p,S,r){t.existsSync(c)&&t.rmSync(c,{recursive:!0,force:!0}),t.mkdirSync(c,{recursive:!0});const f=h.map(e=>i.join(e,w)),d=new Set;for(const e of f){if(!t.existsSync(e))continue;(await b.globby("**/*.json",{cwd:e})).forEach(n=>d.add(n))}const u=new Map;for(const e of d){let o={};for(const n of f){const s=i.join(n,e);if(t.existsSync(s))try{o=M.deepMergeTranslationsRecursive(o,JSON.parse(t.readFileSync(s,"utf-8")))}catch{}}u.set(e,o)}const y=new Map,l=new Map;for(const[e,o]of u){const n=i.dirname(e),s=e.slice(e.lastIndexOf("/")+1).replace(".json","");n==="."?y.set(s,o):(l.has(n)||l.set(n,new Map),l.get(n).set(s,o))}const j=new Set(p.map(e=>e.code)),m=e=>{for(const o of p){const n=[S,o.fallbackLocale,o.code].filter(a=>!!a&&j.has(a)).filter((a,g,v)=>v.indexOf(a)===g);if(n.length<=1)continue;let s={};for(const a of n){const g=e.get(a);g&&(s=M.deepMergeTranslationsRecursive(s,g))}e.set(o.code,s)}};m(y);for(const e of l.values())m(e);if(r||l.size===0){const e=new Map;for(const[o,n]of y)e.set(o,{...n});l.set("pages/index",e)}else for(const[,e]of l)for(const[o,n]of y){const s=e.get(o);e.set(o,s?M.deepMergeTranslations(n,s):{...n})}for(const[e,o]of l)for(const[n,s]of o){const a=i.join(c,e,`${n}.json`);t.mkdirSync(i.dirname(a),{recursive:!0}),t.writeFileSync(a,JSON.stringify(s))}}async function P(h,w,c){t.existsSync(c)&&t.rmSync(c,{recursive:!0,force:!0}),t.mkdirSync(c,{recursive:!0});const p=h.map(r=>i.join(r,w)),S=new Set;for(const r of p){if(!t.existsSync(r))continue;(await b.globby("**/*.json",{cwd:r})).forEach(d=>S.add(d))}for(const r of S){let f={};for(const u of p){const y=i.join(u,r);if(t.existsSync(y))try{f=M.deepMergeTranslationsRecursive(f,JSON.parse(t.readFileSync(y,"utf-8")))}catch{}}const d=i.join(c,r);t.mkdirSync(i.dirname(d),{recursive:!0}),t.writeFileSync(d,JSON.stringify(f))}}exports.buildTranslationSourceLayers=P;exports.preMergeLocales=x;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("node:fs"),i=require("node:path"),j=require("globby"),M=require("./deep-merge.cjs");async function P(m,h,r,y,p,w){n.existsSync(r)&&n.rmSync(r,{recursive:!0,force:!0}),n.mkdirSync(r,{recursive:!0});const c=m.map(e=>i.join(e,h)),l=new Set,S=await Promise.all(c.filter(e=>n.existsSync(e)).map(e=>j.globby("**/*.json",{cwd:e})));for(const e of S)e.forEach(o=>l.add(o));const g=new Map;for(const e of l){let o={};for(const t of c){const s=i.join(t,e);if(n.existsSync(s))try{o=M.deepMergeTranslationsRecursive(o,JSON.parse(n.readFileSync(s,"utf-8")))}catch{}}g.set(e,o)}const d=new Map,f=new Map;for(const[e,o]of g){const t=i.dirname(e),s=e.slice(e.lastIndexOf("/")+1).replace(".json","");t==="."?d.set(s,o):(f.has(t)||f.set(t,new Map),f.get(t).set(s,o))}const v=new Set(y.map(e=>e.code)),b=e=>{for(const o of y){const t=[p,o.fallbackLocale,o.code].filter(a=>!!a&&v.has(a)).filter((a,u,x)=>x.indexOf(a)===u);if(t.length<=1)continue;let s={};for(const a of t){const u=e.get(a);u&&(s=M.deepMergeTranslationsRecursive(s,u))}e.set(o.code,s)}};b(d);for(const e of f.values())b(e);if(w||f.size===0){const e=new Map;for(const[o,t]of d)e.set(o,{...t});f.set("pages/index",e)}else for(const[,e]of f)for(const[o,t]of d){const s=e.get(o);e.set(o,s?M.deepMergeTranslations(t,s):{...t})}for(const[e,o]of f)for(const[t,s]of o){const a=i.join(r,e,`${t}.json`);n.mkdirSync(i.dirname(a),{recursive:!0}),n.writeFileSync(a,JSON.stringify(s))}}async function k(m,h,r){n.existsSync(r)&&n.rmSync(r,{recursive:!0,force:!0}),n.mkdirSync(r,{recursive:!0});const y=m.map(c=>i.join(c,h)),p=new Set,w=await Promise.all(y.filter(c=>n.existsSync(c)).map(c=>j.globby("**/*.json",{cwd:c})));for(const c of w)c.forEach(l=>p.add(l));for(const c of p){let l={};for(const g of y){const d=i.join(g,c);if(n.existsSync(d))try{l=M.deepMergeTranslationsRecursive(l,JSON.parse(n.readFileSync(d,"utf-8")))}catch{}}const S=i.join(r,c);n.mkdirSync(i.dirname(S),{recursive:!0}),n.writeFileSync(S,JSON.stringify(l))}}exports.buildTranslationSourceLayers=k;exports.preMergeLocales=P;
package/dist/build.mjs CHANGED
@@ -1,83 +1,81 @@
1
- import P, { existsSync as d, mkdirSync as u, readFileSync as O, writeFileSync as b } from "node:fs";
2
- import { join as p, dirname as S } from "node:path";
3
- import { globby as j } from "globby";
4
- import { deepMergeTranslationsRecursive as v, deepMergeTranslations as J } from "./deep-merge.mjs";
5
- async function z(w, M, c, y, g, s) {
6
- d(c) && P.rmSync(c, { recursive: !0, force: !0 }), u(c, { recursive: !0 });
7
- const f = w.map((e) => p(e, M)), l = /* @__PURE__ */ new Set();
8
- for (const e of f) {
9
- if (!d(e)) continue;
10
- (await j("**/*.json", { cwd: e })).forEach((t) => l.add(t));
11
- }
12
- const h = /* @__PURE__ */ new Map();
13
- for (const e of l) {
1
+ import O, { existsSync as i, mkdirSync as w, readFileSync as b, writeFileSync as j } from "node:fs";
2
+ import { join as p, dirname as v } from "node:path";
3
+ import { globby as F } from "globby";
4
+ import { deepMergeTranslationsRecursive as P, deepMergeTranslations as J } from "./deep-merge.mjs";
5
+ async function z(M, S, c, d, y, u) {
6
+ i(c) && O.rmSync(c, { recursive: !0, force: !0 }), w(c, { recursive: !0 });
7
+ const a = M.map((e) => p(e, S)), r = /* @__PURE__ */ new Set(), m = await Promise.all(a.filter((e) => i(e)).map((e) => F("**/*.json", { cwd: e })));
8
+ for (const e of m)
9
+ e.forEach((o) => r.add(o));
10
+ const g = /* @__PURE__ */ new Map();
11
+ for (const e of r) {
14
12
  let o = {};
15
- for (const t of f) {
16
- const n = p(t, e);
17
- if (d(n))
13
+ for (const t of a) {
14
+ const s = p(t, e);
15
+ if (i(s))
18
16
  try {
19
- o = v(o, JSON.parse(O(n, "utf-8")));
17
+ o = P(o, JSON.parse(b(s, "utf-8")));
20
18
  } catch {
21
19
  }
22
20
  }
23
- h.set(e, o);
21
+ g.set(e, o);
24
22
  }
25
- const i = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
26
- for (const [e, o] of h) {
27
- const t = S(e), n = e.slice(e.lastIndexOf("/") + 1).replace(".json", "");
28
- t === "." ? i.set(n, o) : (r.has(t) || r.set(t, /* @__PURE__ */ new Map()), r.get(t).set(n, o));
23
+ const l = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map();
24
+ for (const [e, o] of g) {
25
+ const t = v(e), s = e.slice(e.lastIndexOf("/") + 1).replace(".json", "");
26
+ t === "." ? l.set(s, o) : (f.has(t) || f.set(t, /* @__PURE__ */ new Map()), f.get(t).set(s, o));
29
27
  }
30
- const F = new Set(y.map((e) => e.code)), x = (e) => {
31
- for (const o of y) {
32
- const t = [g, o.fallbackLocale, o.code].filter((a) => !!a && F.has(a)).filter((a, m, k) => k.indexOf(a) === m);
28
+ const L = new Set(d.map((e) => e.code)), x = (e) => {
29
+ for (const o of d) {
30
+ const t = [y, o.fallbackLocale, o.code].filter((n) => !!n && L.has(n)).filter((n, h, k) => k.indexOf(n) === h);
33
31
  if (t.length <= 1) continue;
34
- let n = {};
35
- for (const a of t) {
36
- const m = e.get(a);
37
- m && (n = v(n, m));
32
+ let s = {};
33
+ for (const n of t) {
34
+ const h = e.get(n);
35
+ h && (s = P(s, h));
38
36
  }
39
- e.set(o.code, n);
37
+ e.set(o.code, s);
40
38
  }
41
39
  };
42
- x(i);
43
- for (const e of r.values())
40
+ x(l);
41
+ for (const e of f.values())
44
42
  x(e);
45
- if (s || r.size === 0) {
43
+ if (u || f.size === 0) {
46
44
  const e = /* @__PURE__ */ new Map();
47
- for (const [o, t] of i)
45
+ for (const [o, t] of l)
48
46
  e.set(o, { ...t });
49
- r.set("pages/index", e);
47
+ f.set("pages/index", e);
50
48
  } else
51
- for (const [, e] of r)
52
- for (const [o, t] of i) {
53
- const n = e.get(o);
54
- e.set(o, n ? J(t, n) : { ...t });
49
+ for (const [, e] of f)
50
+ for (const [o, t] of l) {
51
+ const s = e.get(o);
52
+ e.set(o, s ? J(t, s) : { ...t });
55
53
  }
56
- for (const [e, o] of r)
57
- for (const [t, n] of o) {
58
- const a = p(c, e, `${t}.json`);
59
- u(S(a), { recursive: !0 }), b(a, JSON.stringify(n));
54
+ for (const [e, o] of f)
55
+ for (const [t, s] of o) {
56
+ const n = p(c, e, `${t}.json`);
57
+ w(v(n), { recursive: !0 }), j(n, JSON.stringify(s));
60
58
  }
61
59
  }
62
- async function C(w, M, c) {
63
- d(c) && P.rmSync(c, { recursive: !0, force: !0 }), u(c, { recursive: !0 });
64
- const y = w.map((s) => p(s, M)), g = /* @__PURE__ */ new Set();
65
- for (const s of y) {
66
- if (!d(s)) continue;
67
- (await j("**/*.json", { cwd: s })).forEach((l) => g.add(l));
68
- }
69
- for (const s of g) {
70
- let f = {};
71
- for (const h of y) {
72
- const i = p(h, s);
73
- if (d(i))
60
+ async function C(M, S, c) {
61
+ i(c) && O.rmSync(c, { recursive: !0, force: !0 }), w(c, { recursive: !0 });
62
+ const d = M.map((a) => p(a, S)), y = /* @__PURE__ */ new Set(), u = await Promise.all(
63
+ d.filter((a) => i(a)).map((a) => F("**/*.json", { cwd: a }))
64
+ );
65
+ for (const a of u)
66
+ a.forEach((r) => y.add(r));
67
+ for (const a of y) {
68
+ let r = {};
69
+ for (const g of d) {
70
+ const l = p(g, a);
71
+ if (i(l))
74
72
  try {
75
- f = v(f, JSON.parse(O(i, "utf-8")));
73
+ r = P(r, JSON.parse(b(l, "utf-8")));
76
74
  } catch {
77
75
  }
78
76
  }
79
- const l = p(c, s);
80
- u(S(l), { recursive: !0 }), b(l, JSON.stringify(f));
77
+ const m = p(c, a);
78
+ w(v(m), { recursive: !0 }), j(m, JSON.stringify(r));
81
79
  }
82
80
  }
83
81
  export {
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./deep-merge.cjs");function i(e,a,r){const n=new Set(a.map(o=>o.code)),l=a.find(o=>o.code===e);return[r,l?.fallbackLocale,e].filter(o=>!!o&&n.has(o)).filter((o,g,f)=>f.indexOf(o)===g)}function b(e,a,r){let n={};for(const l of e)n=c.deepMergeTranslations(n,a(r(l)));return n}async function t(e,a,r){let n={};for(const l of e){const o=await a(r(l));n=c.deepMergeTranslations(n,o)}return n}function s(e,a){return a?"index":e||"index"}function u(e){return`${e}.json`}function d(e,a){return`pages/${s(e)}/${a}.json`}function m(e){return`assets:i18n:${e.replace(/\//g,":")}`}async function S(e){const a=s(e.pageName,e.disablePageLocales),r=i(e.locale,e.locales,e.globalFallbackLocale),n=await t(r,e.readLocaleFile,u),l=await t(r,e.readLocaleFile,o=>d(a,o));return c.deepMergeTranslations(n,l)}function F(e){return(e??[]).map(a=>typeof a=="string"?{code:a}:{code:a.code,fallbackLocale:a.fallbackLocale})}exports.buildFallbackLocaleChain=i;exports.buildSourcePagePath=d;exports.buildSourceRootPath=u;exports.mergeSourceTranslations=S;exports.mergeTranslationsFromFallbackChain=b;exports.mergeTranslationsFromFallbackChainAsync=t;exports.normalizeConfiguredLocales=F;exports.resolveSourcePageName=s;exports.toSourceStorageKey=m;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./deep-merge.cjs");function i(e,a,r){const c=new Set(a.map(o=>o.code)),n=a.find(o=>o.code===e);return[r,n?.fallbackLocale,e].filter(o=>!!o&&c.has(o)).filter((o,d,f)=>f.indexOf(o)===d)}function m(e,a,r){let c={};for(const n of e)c=t.deepMergeTranslations(c,a(r(n)));return c}async function l(e,a,r){return(await Promise.all(e.map(n=>a(r(n))))).reduce((n,o)=>t.deepMergeTranslations(n,o),{})}function s(e,a){return a?"index":e||"index"}function u(e){return`${e}.json`}function g(e,a){return`pages/${s(e)}/${a}.json`}function b(e){return`assets:i18n:${e.replace(/\//g,":")}`}async function S(e){const a=s(e.pageName,e.disablePageLocales),r=i(e.locale,e.locales,e.globalFallbackLocale),c=await l(r,e.readLocaleFile,u),n=await l(r,e.readLocaleFile,o=>g(a,o));return t.deepMergeTranslations(c,n)}function h(e){return(e??[]).map(a=>typeof a=="string"?{code:a}:{code:a.code,fallbackLocale:a.fallbackLocale})}exports.buildFallbackLocaleChain=i;exports.buildSourcePagePath=g;exports.buildSourceRootPath=u;exports.mergeSourceTranslations=S;exports.mergeTranslationsFromFallbackChain=m;exports.mergeTranslationsFromFallbackChainAsync=l;exports.normalizeConfiguredLocales=h;exports.resolveSourcePageName=s;exports.toSourceStorageKey=b;
@@ -1,21 +1,16 @@
1
1
  import { deepMergeTranslations as t } from "./deep-merge.mjs";
2
- function u(e, a, r) {
3
- const n = new Set(a.map((o) => o.code)), c = a.find((o) => o.code === e);
4
- return [r, c?.fallbackLocale, e].filter((o) => !!o && n.has(o)).filter((o, i, f) => f.indexOf(o) === i);
2
+ function f(e, a, r) {
3
+ const c = new Set(a.map((o) => o.code)), n = a.find((o) => o.code === e);
4
+ return [r, n?.fallbackLocale, e].filter((o) => !!o && c.has(o)).filter((o, i, u) => u.indexOf(o) === i);
5
5
  }
6
6
  function b(e, a, r) {
7
- let n = {};
8
- for (const c of e)
9
- n = t(n, a(r(c)));
10
- return n;
7
+ let c = {};
8
+ for (const n of e)
9
+ c = t(c, a(r(n)));
10
+ return c;
11
11
  }
12
12
  async function l(e, a, r) {
13
- let n = {};
14
- for (const c of e) {
15
- const o = await a(r(c));
16
- n = t(n, o);
17
- }
18
- return n;
13
+ return (await Promise.all(e.map((n) => a(r(n))))).reduce((n, o) => t(n, o), {});
19
14
  }
20
15
  function s(e, a) {
21
16
  return a ? "index" : e || "index";
@@ -26,26 +21,26 @@ function d(e) {
26
21
  function g(e, a) {
27
22
  return `pages/${s(e)}/${a}.json`;
28
23
  }
29
- function L(e) {
24
+ function k(e) {
30
25
  return `assets:i18n:${e.replace(/\//g, ":")}`;
31
26
  }
32
- async function k(e) {
33
- const a = s(e.pageName, e.disablePageLocales), r = u(e.locale, e.locales, e.globalFallbackLocale), n = await l(r, e.readLocaleFile, d), c = await l(r, e.readLocaleFile, (o) => g(a, o));
34
- return t(n, c);
27
+ async function h(e) {
28
+ const a = s(e.pageName, e.disablePageLocales), r = f(e.locale, e.locales, e.globalFallbackLocale), c = await l(r, e.readLocaleFile, d), n = await l(r, e.readLocaleFile, (o) => g(a, o));
29
+ return t(c, n);
35
30
  }
36
- function C(e) {
31
+ function L(e) {
37
32
  return (e ?? []).map(
38
33
  (a) => typeof a == "string" ? { code: a } : { code: a.code, fallbackLocale: a.fallbackLocale }
39
34
  );
40
35
  }
41
36
  export {
42
- u as buildFallbackLocaleChain,
37
+ f as buildFallbackLocaleChain,
43
38
  g as buildSourcePagePath,
44
39
  d as buildSourceRootPath,
45
- k as mergeSourceTranslations,
40
+ h as mergeSourceTranslations,
46
41
  b as mergeTranslationsFromFallbackChain,
47
42
  l as mergeTranslationsFromFallbackChainAsync,
48
- C as normalizeConfiguredLocales,
43
+ L as normalizeConfiguredLocales,
49
44
  s as resolveSourcePageName,
50
- L as toSourceStorageKey
45
+ k as toSourceStorageKey
51
46
  };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function n(r){return r?typeof r=="object"&&r!==null&&!Array.isArray(r)?r:{}:{}}function o(r){return n(r)}exports.toTranslationRecord=o;exports.toTranslations=n;
@@ -0,0 +1,9 @@
1
+ import { Translations } from '@i18n-micro/types';
2
+ /**
3
+ * Normalize unknown fetch/storage payloads into a plain translation object.
4
+ */
5
+ export declare function toTranslations(data: unknown): Translations;
6
+ /**
7
+ * Normalize unknown payloads into a mutable record (source loader).
8
+ */
9
+ export declare function toTranslationRecord(data: unknown): Record<string, unknown>;
@@ -0,0 +1,9 @@
1
+ import { Translations } from '@i18n-micro/types';
2
+ /**
3
+ * Normalize unknown fetch/storage payloads into a plain translation object.
4
+ */
5
+ export declare function toTranslations(data: unknown): Translations;
6
+ /**
7
+ * Normalize unknown payloads into a mutable record (source loader).
8
+ */
9
+ export declare function toTranslationRecord(data: unknown): Record<string, unknown>;
@@ -0,0 +1,10 @@
1
+ function n(r) {
2
+ return r ? typeof r == "object" && r !== null && !Array.isArray(r) ? r : {} : {};
3
+ }
4
+ function o(r) {
5
+ return n(r);
6
+ }
7
+ export {
8
+ o as toTranslationRecord,
9
+ n as toTranslations
10
+ };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./payload-url.cjs");function l(e){return e?typeof e=="object"&&e!==null&&!Array.isArray(e)?e:{}:{}}async function n(e,a,t,s){if(!e.apiBaseServerHost)return{};const r=i.buildTranslationPayloadFetchRequest({apiBaseUrl:e.apiBaseUrl??"_locales",routeName:t,locale:a,isServer:!0,baseURL:e.apiBaseServerHost,apiBaseServerHost:e.apiBaseServerHost,dateBuild:e.dateBuild});try{const o=await s(r.path,{baseURL:r.baseURL,params:r.params});return l(o)}catch{return{}}}exports.fetchTranslationPayloadFromHost=n;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./normalize.cjs"),i=require("./payload-url.cjs");async function n(a,r,t,s){if(!a.apiBaseServerHost)return{};const e=i.buildTranslationPayloadFetchRequest({apiBaseUrl:a.apiBaseUrl??"_locales",routeName:t,locale:r,isServer:!0,baseURL:a.apiBaseServerHost,apiBaseServerHost:a.apiBaseServerHost,dateBuild:a.dateBuild});try{const o=await s(e.path,{baseURL:e.baseURL,params:e.params});return l.toTranslations(o)}catch{return{}}}exports.fetchTranslationPayloadFromHost=n;
@@ -1,28 +1,26 @@
1
- import { buildTranslationPayloadFetchRequest as i } from "./payload-url.mjs";
2
- function n(r) {
3
- return r ? typeof r == "object" && r !== null && !Array.isArray(r) ? r : {} : {};
4
- }
5
- async function l(r, a, t, s) {
6
- if (!r.apiBaseServerHost) return {};
7
- const e = i({
8
- apiBaseUrl: r.apiBaseUrl ?? "_locales",
1
+ import { toTranslations as i } from "./normalize.mjs";
2
+ import { buildTranslationPayloadFetchRequest as l } from "./payload-url.mjs";
3
+ async function n(a, r, t, s) {
4
+ if (!a.apiBaseServerHost) return {};
5
+ const e = l({
6
+ apiBaseUrl: a.apiBaseUrl ?? "_locales",
9
7
  routeName: t,
10
- locale: a,
8
+ locale: r,
11
9
  isServer: !0,
12
- baseURL: r.apiBaseServerHost,
13
- apiBaseServerHost: r.apiBaseServerHost,
14
- dateBuild: r.dateBuild
10
+ baseURL: a.apiBaseServerHost,
11
+ apiBaseServerHost: a.apiBaseServerHost,
12
+ dateBuild: a.dateBuild
15
13
  });
16
14
  try {
17
15
  const o = await s(e.path, {
18
16
  baseURL: e.baseURL,
19
17
  params: e.params
20
18
  });
21
- return n(o);
19
+ return i(o);
22
20
  } catch {
23
21
  return {};
24
22
  }
25
23
  }
26
24
  export {
27
- l as fetchTranslationPayloadFromHost
25
+ n as fetchTranslationPayloadFromHost
28
26
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function r(l){if(typeof l!="string")return;const t=l.trim();return t.length>0?t:void 0}function L(l){if(Array.isArray(l)){const t=l.map(e=>r(e)).filter(e=>!!e);return t.length>0?t:void 0}if(typeof l=="string"){const t=l.split(",").map(e=>e.trim()).filter(e=>e.length>0);return t.length>0?t:void 0}}function m(){return{defaultLocale:r(process.env.NUXT_I18N_DEFAULT_LOCALE)??r(process.env.NUXT_PUBLIC_I18N_RUNTIME_DEFAULT_LOCALE),fallbackLocale:r(process.env.NUXT_I18N_FALLBACK_LOCALE)??r(process.env.NUXT_PUBLIC_I18N_RUNTIME_FALLBACK_LOCALE),disabledLocales:L(process.env.NUXT_I18N_DISABLED_LOCALES)??L(process.env.NUXT_PUBLIC_I18N_RUNTIME_DISABLED_LOCALES),strategy:r(process.env.NUXT_I18N_STRATEGY)??r(process.env.NUXT_PUBLIC_I18N_RUNTIME_STRATEGY)}}function _(l){const t=l?.i18nRuntime;if(!t||typeof t!="object")return{};const e=t;return{defaultLocale:r(e.defaultLocale),fallbackLocale:r(e.fallbackLocale),disabledLocales:L(e.disabledLocales),strategy:r(e.strategy)}}function g(l){const t=m(),e=_(l);return{defaultLocale:e.defaultLocale??t.defaultLocale,fallbackLocale:e.fallbackLocale??t.fallbackLocale,disabledLocales:e.disabledLocales??t.disabledLocales,strategy:e.strategy??t.strategy}}function v(l,t,e=a=>console.warn(a)){const a=g(t),i=(l.locales??[]).map(o=>({...o}));if(a.strategy&&a.strategy!==l.strategy&&e(`[nuxt-i18n-micro] runtime i18n strategy override is ignored: "${a.strategy}" (build strategy: "${l.strategy}"). Build a separate artifact for each strategy.`),a.disabledLocales&&a.disabledLocales.length>0){const o=new Set(a.disabledLocales);for(const u of i)u.disabled=o.has(u.code)}const n=i.filter(o=>!o.disabled);if(n.length===0)return a.disabledLocales&&a.disabledLocales.length>0&&e("[nuxt-i18n-micro] runtime disabledLocales override would disable all locales; override ignored."),{...l,locales:(l.locales??[]).map(o=>({...o}))};const b=new Set(i.map(o=>o.code));let c=a.defaultLocale??l.defaultLocale,s=a.fallbackLocale??l.fallbackLocale;s&&!b.has(s)&&(e(`[nuxt-i18n-micro] runtime fallbackLocale "${s}" is not defined in locales; override ignored.`),s=l.fallbackLocale);const f=new Set(n.map(o=>o.code)),d=n[0]?.code??l.defaultLocale??"en";return(!c||!f.has(c))&&(a.defaultLocale?e(`[nuxt-i18n-micro] runtime defaultLocale "${a.defaultLocale}" is not enabled; falling back to "${d}".`):c&&!f.has(c)&&e(`[nuxt-i18n-micro] defaultLocale "${c}" is disabled by runtime overrides; falling back to "${d}".`),c=d),{...l,locales:i,defaultLocale:c,fallbackLocale:s}}exports.resolveI18nConfigWithRuntimeOverrides=v;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function o(e){if(typeof e!="string")return;const t=e.trim();return t.length>0?t:void 0}function L(e){if(Array.isArray(e)){const t=e.map(l=>o(l)).filter(l=>!!l);return t.length>0?t:void 0}if(typeof e=="string"){const t=e.split(",").map(l=>l.trim()).filter(l=>l.length>0);return t.length>0?t:void 0}}function m(){return{defaultLocale:o(process.env.NUXT_I18N_DEFAULT_LOCALE)??o(process.env.NUXT_PUBLIC_I18N_RUNTIME_DEFAULT_LOCALE),fallbackLocale:o(process.env.NUXT_I18N_FALLBACK_LOCALE)??o(process.env.NUXT_PUBLIC_I18N_RUNTIME_FALLBACK_LOCALE),disabledLocales:L(process.env.NUXT_I18N_DISABLED_LOCALES)??L(process.env.NUXT_PUBLIC_I18N_RUNTIME_DISABLED_LOCALES),strategy:o(process.env.NUXT_I18N_STRATEGY)??o(process.env.NUXT_PUBLIC_I18N_RUNTIME_STRATEGY)}}function g(e){const t=e?.i18nRuntime;if(!t||typeof t!="object")return{};const l=t;return{defaultLocale:o(l.defaultLocale),fallbackLocale:o(l.fallbackLocale),disabledLocales:L(l.disabledLocales),strategy:o(l.strategy)}}function v(e){return Object.assign({},e)}function b(e){return e.map(t=>v(t))}function y(e){const t=m(),l=g(e);return{defaultLocale:l.defaultLocale??t.defaultLocale,fallbackLocale:l.fallbackLocale??t.fallbackLocale,disabledLocales:l.disabledLocales??t.disabledLocales,strategy:l.strategy??t.strategy}}function p(e,t,l=a=>console.warn(a)){const a=y(t),n=b(e.locales??[]);if(a.strategy&&a.strategy!==e.strategy&&l(`[nuxt-i18n-micro] runtime i18n strategy override is ignored: "${a.strategy}" (build strategy: "${e.strategy}"). Build a separate artifact for each strategy.`),a.disabledLocales&&a.disabledLocales.length>0){const r=new Set(a.disabledLocales);for(const u of n)u.disabled=r.has(u.code)}const i=n.filter(r=>!r.disabled);if(i.length===0)return a.disabledLocales&&a.disabledLocales.length>0&&l("[nuxt-i18n-micro] runtime disabledLocales override would disable all locales; override ignored."),{...e,locales:b(e.locales??[])};const _=new Set(n.map(r=>r.code));let c=a.defaultLocale??e.defaultLocale,s=a.fallbackLocale??e.fallbackLocale;s&&!_.has(s)&&(l(`[nuxt-i18n-micro] runtime fallbackLocale "${s}" is not defined in locales; override ignored.`),s=e.fallbackLocale);const f=new Set(i.map(r=>r.code)),d=i[0]?.code??e.defaultLocale??"en";return(!c||!f.has(c))&&(a.defaultLocale?l(`[nuxt-i18n-micro] runtime defaultLocale "${a.defaultLocale}" is not enabled; falling back to "${d}".`):c&&!f.has(c)&&l(`[nuxt-i18n-micro] defaultLocale "${c}" is disabled by runtime overrides; falling back to "${d}".`),c=d),{...e,locales:n,defaultLocale:c,fallbackLocale:s}}exports.resolveI18nConfigWithRuntimeOverrides=p;
@@ -1,69 +1,75 @@
1
- function c(l) {
2
- if (typeof l != "string") return;
3
- const a = l.trim();
1
+ function o(e) {
2
+ if (typeof e != "string") return;
3
+ const a = e.trim();
4
4
  return a.length > 0 ? a : void 0;
5
5
  }
6
- function L(l) {
7
- if (Array.isArray(l)) {
8
- const a = l.map((e) => c(e)).filter((e) => !!e);
6
+ function L(e) {
7
+ if (Array.isArray(e)) {
8
+ const a = e.map((l) => o(l)).filter((l) => !!l);
9
9
  return a.length > 0 ? a : void 0;
10
10
  }
11
- if (typeof l == "string") {
12
- const a = l.split(",").map((e) => e.trim()).filter((e) => e.length > 0);
11
+ if (typeof e == "string") {
12
+ const a = e.split(",").map((l) => l.trim()).filter((l) => l.length > 0);
13
13
  return a.length > 0 ? a : void 0;
14
14
  }
15
15
  }
16
- function b() {
16
+ function m() {
17
17
  return {
18
- defaultLocale: c(process.env.NUXT_I18N_DEFAULT_LOCALE) ?? c(process.env.NUXT_PUBLIC_I18N_RUNTIME_DEFAULT_LOCALE),
19
- fallbackLocale: c(process.env.NUXT_I18N_FALLBACK_LOCALE) ?? c(process.env.NUXT_PUBLIC_I18N_RUNTIME_FALLBACK_LOCALE),
18
+ defaultLocale: o(process.env.NUXT_I18N_DEFAULT_LOCALE) ?? o(process.env.NUXT_PUBLIC_I18N_RUNTIME_DEFAULT_LOCALE),
19
+ fallbackLocale: o(process.env.NUXT_I18N_FALLBACK_LOCALE) ?? o(process.env.NUXT_PUBLIC_I18N_RUNTIME_FALLBACK_LOCALE),
20
20
  disabledLocales: L(process.env.NUXT_I18N_DISABLED_LOCALES) ?? L(process.env.NUXT_PUBLIC_I18N_RUNTIME_DISABLED_LOCALES),
21
- strategy: c(process.env.NUXT_I18N_STRATEGY) ?? c(process.env.NUXT_PUBLIC_I18N_RUNTIME_STRATEGY)
21
+ strategy: o(process.env.NUXT_I18N_STRATEGY) ?? o(process.env.NUXT_PUBLIC_I18N_RUNTIME_STRATEGY)
22
22
  };
23
23
  }
24
- function m(l) {
25
- const a = l?.i18nRuntime;
24
+ function g(e) {
25
+ const a = e?.i18nRuntime;
26
26
  if (!a || typeof a != "object") return {};
27
- const e = a;
27
+ const l = a;
28
28
  return {
29
- defaultLocale: c(e.defaultLocale),
30
- fallbackLocale: c(e.fallbackLocale),
31
- disabledLocales: L(e.disabledLocales),
32
- strategy: c(e.strategy)
29
+ defaultLocale: o(l.defaultLocale),
30
+ fallbackLocale: o(l.fallbackLocale),
31
+ disabledLocales: L(l.disabledLocales),
32
+ strategy: o(l.strategy)
33
33
  };
34
34
  }
35
- function g(l) {
36
- const a = b(), e = m(l);
35
+ function v(e) {
36
+ return Object.assign({}, e);
37
+ }
38
+ function _(e) {
39
+ return e.map((a) => v(a));
40
+ }
41
+ function p(e) {
42
+ const a = m(), l = g(e);
37
43
  return {
38
- defaultLocale: e.defaultLocale ?? a.defaultLocale,
39
- fallbackLocale: e.fallbackLocale ?? a.fallbackLocale,
40
- disabledLocales: e.disabledLocales ?? a.disabledLocales,
41
- strategy: e.strategy ?? a.strategy
44
+ defaultLocale: l.defaultLocale ?? a.defaultLocale,
45
+ fallbackLocale: l.fallbackLocale ?? a.fallbackLocale,
46
+ disabledLocales: l.disabledLocales ?? a.disabledLocales,
47
+ strategy: l.strategy ?? a.strategy
42
48
  };
43
49
  }
44
- function p(l, a, e = (t) => console.warn(t)) {
45
- const t = g(a), i = (l.locales ?? []).map((o) => ({ ...o }));
46
- if (t.strategy && t.strategy !== l.strategy && e(
47
- `[nuxt-i18n-micro] runtime i18n strategy override is ignored: "${t.strategy}" (build strategy: "${l.strategy}"). Build a separate artifact for each strategy.`
50
+ function y(e, a, l = (t) => console.warn(t)) {
51
+ const t = p(a), n = _(e.locales ?? []);
52
+ if (t.strategy && t.strategy !== e.strategy && l(
53
+ `[nuxt-i18n-micro] runtime i18n strategy override is ignored: "${t.strategy}" (build strategy: "${e.strategy}"). Build a separate artifact for each strategy.`
48
54
  ), t.disabledLocales && t.disabledLocales.length > 0) {
49
- const o = new Set(t.disabledLocales);
50
- for (const u of i)
51
- u.disabled = o.has(u.code);
55
+ const r = new Set(t.disabledLocales);
56
+ for (const u of n)
57
+ u.disabled = r.has(u.code);
52
58
  }
53
- const n = i.filter((o) => !o.disabled);
54
- if (n.length === 0)
55
- return t.disabledLocales && t.disabledLocales.length > 0 && e("[nuxt-i18n-micro] runtime disabledLocales override would disable all locales; override ignored."), { ...l, locales: (l.locales ?? []).map((o) => ({ ...o })) };
56
- const _ = new Set(i.map((o) => o.code));
57
- let s = t.defaultLocale ?? l.defaultLocale, r = t.fallbackLocale ?? l.fallbackLocale;
58
- r && !_.has(r) && (e(`[nuxt-i18n-micro] runtime fallbackLocale "${r}" is not defined in locales; override ignored.`), r = l.fallbackLocale);
59
- const f = new Set(n.map((o) => o.code)), d = n[0]?.code ?? l.defaultLocale ?? "en";
60
- return (!s || !f.has(s)) && (t.defaultLocale ? e(`[nuxt-i18n-micro] runtime defaultLocale "${t.defaultLocale}" is not enabled; falling back to "${d}".`) : s && !f.has(s) && e(`[nuxt-i18n-micro] defaultLocale "${s}" is disabled by runtime overrides; falling back to "${d}".`), s = d), {
61
- ...l,
62
- locales: i,
63
- defaultLocale: s,
64
- fallbackLocale: r
59
+ const i = n.filter((r) => !r.disabled);
60
+ if (i.length === 0)
61
+ return t.disabledLocales && t.disabledLocales.length > 0 && l("[nuxt-i18n-micro] runtime disabledLocales override would disable all locales; override ignored."), { ...e, locales: _(e.locales ?? []) };
62
+ const b = new Set(n.map((r) => r.code));
63
+ let c = t.defaultLocale ?? e.defaultLocale, s = t.fallbackLocale ?? e.fallbackLocale;
64
+ s && !b.has(s) && (l(`[nuxt-i18n-micro] runtime fallbackLocale "${s}" is not defined in locales; override ignored.`), s = e.fallbackLocale);
65
+ const f = new Set(i.map((r) => r.code)), d = i[0]?.code ?? e.defaultLocale ?? "en";
66
+ return (!c || !f.has(c)) && (t.defaultLocale ? l(`[nuxt-i18n-micro] runtime defaultLocale "${t.defaultLocale}" is not enabled; falling back to "${d}".`) : c && !f.has(c) && l(`[nuxt-i18n-micro] defaultLocale "${c}" is disabled by runtime overrides; falling back to "${d}".`), c = d), {
67
+ ...e,
68
+ locales: n,
69
+ defaultLocale: c,
70
+ fallbackLocale: s
65
71
  };
66
72
  }
67
73
  export {
68
- p as resolveI18nConfigWithRuntimeOverrides
74
+ y as resolveI18nConfigWithRuntimeOverrides
69
75
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./merge-source.cjs");function u(r){return r?typeof r=="object"&&r!==null&&!Array.isArray(r)?r:{}:{}}async function a(r,o){return e.mergeSourceTranslations({...o,readLocaleFile:async t=>{const n=await r.getItem(e.toSourceStorageKey(t));return u(n)}})}exports.loadSourceTranslationsFromStorage=a;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./merge-source.cjs"),n=require("./normalize.cjs");async function c(r,o){return e.mergeSourceTranslations({...o,readLocaleFile:async t=>{const a=await r.getItem(e.toSourceStorageKey(t));return n.toTranslationRecord(a)}})}exports.loadSourceTranslationsFromStorage=c;
@@ -1,16 +1,14 @@
1
- import { mergeSourceTranslations as t, toSourceStorageKey as i } from "./merge-source.mjs";
2
- function u(r) {
3
- return r ? typeof r == "object" && r !== null && !Array.isArray(r) ? r : {} : {};
4
- }
5
- async function c(r, e) {
6
- return t({
7
- ...e,
8
- readLocaleFile: async (o) => {
9
- const n = await r.getItem(i(o));
10
- return u(n);
1
+ import { mergeSourceTranslations as a, toSourceStorageKey as n } from "./merge-source.mjs";
2
+ import { toTranslationRecord as c } from "./normalize.mjs";
3
+ async function l(o, r) {
4
+ return a({
5
+ ...r,
6
+ readLocaleFile: async (e) => {
7
+ const t = await o.getItem(n(e));
8
+ return c(t);
11
9
  }
12
10
  });
13
11
  }
14
12
  export {
15
- c as loadSourceTranslationsFromStorage
13
+ l as loadSourceTranslationsFromStorage
16
14
  };
package/package.json CHANGED
@@ -1,27 +1,34 @@
1
1
  {
2
2
  "name": "@i18n-micro/utils",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Framework-agnostic utilities for Nuxt I18n Micro (granular subpath imports).",
5
- "repository": {
6
- "type": "git",
7
- "url": "git+https://github.com/s00d/nuxt-i18n-micro.git",
8
- "directory": "packages/utils"
5
+ "keywords": [
6
+ "i18n",
7
+ "locale",
8
+ "translations",
9
+ "utils"
10
+ ],
11
+ "homepage": "https://github.com/s00d/nuxt-i18n-micro/tree/main/packages/utils#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/s00d/nuxt-i18n-micro/issues"
9
14
  },
10
15
  "license": "MIT",
11
- "type": "module",
12
- "sideEffects": false,
13
16
  "author": {
14
17
  "name": "s00d",
15
18
  "email": "Virus191288@gmail.com",
16
19
  "url": "https://s00d.github.io/"
17
20
  },
18
- "homepage": "https://github.com/s00d/nuxt-i18n-micro/tree/main/packages/utils#readme",
19
- "bugs": {
20
- "url": "https://github.com/s00d/nuxt-i18n-micro/issues"
21
- },
22
- "engines": {
23
- "node": ">=18"
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/s00d/nuxt-i18n-micro.git",
24
+ "directory": "packages/utils"
24
25
  },
26
+ "files": [
27
+ "dist",
28
+ "README.md"
29
+ ],
30
+ "type": "module",
31
+ "sideEffects": false,
25
32
  "exports": {
26
33
  "./deep-merge": {
27
34
  "import": {
@@ -199,6 +206,17 @@
199
206
  },
200
207
  "default": "./dist/runtime-config.mjs"
201
208
  },
209
+ "./normalize": {
210
+ "import": {
211
+ "types": "./dist/normalize.d.ts",
212
+ "default": "./dist/normalize.mjs"
213
+ },
214
+ "require": {
215
+ "types": "./dist/normalize.d.cts",
216
+ "default": "./dist/normalize.cjs"
217
+ },
218
+ "default": "./dist/normalize.mjs"
219
+ },
202
220
  "./build": {
203
221
  "import": {
204
222
  "types": "./dist/build.d.ts",
@@ -216,26 +234,19 @@
216
234
  "publishConfig": {
217
235
  "access": "public"
218
236
  },
219
- "keywords": [
220
- "i18n",
221
- "translations",
222
- "utils",
223
- "locale"
224
- ],
225
- "files": [
226
- "dist",
227
- "README.md"
228
- ],
229
237
  "dependencies": {
230
238
  "globby": "^14.1.0",
231
- "@i18n-micro/types": "1.2.3"
239
+ "@i18n-micro/types": "1.2.4"
232
240
  },
233
241
  "devDependencies": {
234
242
  "publint": "^0.3.17",
235
243
  "vite": "^7.3.1",
236
244
  "vite-plugin-dts": "^4.5.4",
237
245
  "vitest": "^3.2.4",
238
- "@i18n-micro/test-utils": "1.2.1"
246
+ "@i18n-micro/test-utils": "1.2.2"
247
+ },
248
+ "engines": {
249
+ "node": ">=18"
239
250
  },
240
251
  "scripts": {
241
252
  "build": "vite build",