@i18n-micro/utils 1.0.2 → 1.0.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/README.md CHANGED
@@ -9,6 +9,9 @@ import { findAllowedLocalesForRoute } from '@i18n-micro/utils/route'
9
9
  import { extractBaseRoutePattern } from '@i18n-micro/utils/route-pattern'
10
10
  import { resolveI18nConfigWithRuntimeOverrides } from '@i18n-micro/utils/runtime-config'
11
11
  import { preMergeLocales } from '@i18n-micro/utils/build'
12
+ import { mergeI18nHead } from '@i18n-micro/utils/merge-i18n-head'
12
13
  ```
13
14
 
15
+ `mergeI18nHead` merges `useLocaleHead` output with page-level overrides (`I18nHeadInput`). Used by the `02.meta` plugin; import it directly for custom tooling or unit tests that need the same merge rules (replace hreflang/canonical/og, disable groups, append meta/link).
16
+
14
17
  No Vue, Nuxt, or Nitro dependencies. `sideEffects: false` for tree-shaking friendly bundlers.
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("./resolve-og-locale.cjs");function u(e){return e.rel==="alternate"}function s(e){return e.rel==="alternate"&&e.hreflang==="x-default"}function m(e){return e.rel==="alternate"&&e.hreflang!=="x-default"}function g(e,t){const n=e[t];return n?`id:${n}`:e.property?`property:${e.property}`:e.name?`name:${e.name}`:`meta:${JSON.stringify(e)}`}function A(e,t){const n=e[t];return n?`id:${n}`:`link:${e.rel}:${e.hreflang??""}`}function p(e,t){const n=new Set([A(e,t)]);return e.rel==="alternate"&&e.hreflang&&n.add(`link:${e.rel}:${e.hreflang}`),e.rel==="canonical"&&n.add("link:canonical:"),[...n]}function $(e,t,n){if(g(e,n)===g(t,n)||t.property&&e.property===t.property||t.name&&e.name===t.name)return!0;const o=t[n];return!!(o&&e[n]===o)}function L(e,t,n){const o=e.filter(i=>!$(i,t,n));return o.push(t),o}function k(e,t,n){const o=new Set(p(t,n)),i=e.filter(c=>!p(c,n).some(l=>o.has(l)));return i.push(t),i}function x(e,t,n){let o=!1;const i=e.map(c=>c.rel!=="canonical"?c:(o=!0,{...c,href:t}));return o||i.unshift({[n]:"i18n-can",rel:"canonical",href:t}),i}function h(e,t,n,o,i){const c=e.filter(l=>l.property!==t);return c.push({[o]:t==="og:locale"?"i18n-og":t==="og:url"?"i18n-og-url":`i18n-page-${t}`,property:t,content:n}),c}function S(e,t,n,o){const i=[];for(const c of e){if(n&&c===n)continue;const l=t.find(f=>f.code===c);if(!l)continue;const a=d.resolveOgLocale(l);a&&i.push({[o]:`i18n-og-alt-${a}`,property:"og:locale:alternate",content:a})}return i}function M(e,t,n={}){if(!t)return{htmlAttrs:{...e.htmlAttrs},meta:[...e.meta],link:[...e.link]};const o=n.identifierAttribute??"id",i=new Set(t.disable??[]);let c={...e.htmlAttrs},l=[...e.meta],a=[...e.link];i.has("html")&&(c={}),i.has("hreflang")&&(a=a.filter(r=>!m(r))),i.has("x-default")&&(a=a.filter(r=>!s(r))),i.has("canonical")&&(a=a.filter(r=>r.rel!=="canonical")),i.has("og")&&(l=l.filter(r=>r.property!=="og:locale"&&r.property!=="og:url")),i.has("og-alternates")&&(l=l.filter(r=>r.property!=="og:locale:alternate"));const f=t.replace;if(f){if(f.canonical===!1?a=a.filter(r=>r.rel!=="canonical"):typeof f.canonical=="string"&&(a=x(a,f.canonical,o)),f.hreflang===!1?a=a.filter(r=>!u(r)):Array.isArray(f.hreflang)&&(a=a.filter(r=>!u(r)),a.push(...f.hreflang)),f.xDefault===!1?a=a.filter(r=>!s(r)):f.xDefault&&(a=a.filter(r=>!s(r)),a.push(f.xDefault)),f.ogLocale===!1?l=l.filter(r=>r.property!=="og:locale"):typeof f.ogLocale=="string"&&(l=h(l,"og:locale",f.ogLocale,o)),f.ogUrl===!1?l=l.filter(r=>r.property!=="og:url"):typeof f.ogUrl=="string"&&(l=h(l,"og:url",f.ogUrl,o)),f.ogAlternates===!1)l=l.filter(r=>r.property!=="og:locale:alternate");else if(Array.isArray(f.ogAlternates)){l=l.filter(y=>y.property!=="og:locale:alternate");const r=n.locales??[];l.push(...S(f.ogAlternates,r,n.currentLocale,o))}}t.htmlAttrs&&(c={...c,...t.htmlAttrs});for(const r of t.meta??[])l=L(l,r,o);for(const r of t.link??[])a=k(a,r,o);return{htmlAttrs:c,meta:l,link:a}}exports.mergeI18nHead=M;
@@ -0,0 +1,12 @@
1
+ import { I18nHeadInput, I18nHeadLink, I18nHeadMeta, Locale } from '@i18n-micro/types';
2
+ export interface I18nHeadObject {
3
+ htmlAttrs: Record<string, string | undefined>;
4
+ meta: I18nHeadMeta[];
5
+ link: I18nHeadLink[];
6
+ }
7
+ export interface MergeI18nHeadOptions {
8
+ identifierAttribute?: string;
9
+ locales?: Locale[];
10
+ currentLocale?: string;
11
+ }
12
+ export declare function mergeI18nHead(base: I18nHeadObject, override: I18nHeadInput | null | undefined, options?: MergeI18nHeadOptions): I18nHeadObject;
@@ -0,0 +1,12 @@
1
+ import { I18nHeadInput, I18nHeadLink, I18nHeadMeta, Locale } from '@i18n-micro/types';
2
+ export interface I18nHeadObject {
3
+ htmlAttrs: Record<string, string | undefined>;
4
+ meta: I18nHeadMeta[];
5
+ link: I18nHeadLink[];
6
+ }
7
+ export interface MergeI18nHeadOptions {
8
+ identifierAttribute?: string;
9
+ locales?: Locale[];
10
+ currentLocale?: string;
11
+ }
12
+ export declare function mergeI18nHead(base: I18nHeadObject, override: I18nHeadInput | null | undefined, options?: MergeI18nHeadOptions): I18nHeadObject;
@@ -0,0 +1,97 @@
1
+ import { resolveOgLocale as d } from "./resolve-og-locale.mjs";
2
+ function u(e) {
3
+ return e.rel === "alternate";
4
+ }
5
+ function s(e) {
6
+ return e.rel === "alternate" && e.hreflang === "x-default";
7
+ }
8
+ function m(e) {
9
+ return e.rel === "alternate" && e.hreflang !== "x-default";
10
+ }
11
+ function p(e, t) {
12
+ const n = e[t];
13
+ return n ? `id:${n}` : e.property ? `property:${e.property}` : e.name ? `name:${e.name}` : `meta:${JSON.stringify(e)}`;
14
+ }
15
+ function A(e, t) {
16
+ const n = e[t];
17
+ return n ? `id:${n}` : `link:${e.rel}:${e.hreflang ?? ""}`;
18
+ }
19
+ function g(e, t) {
20
+ const n = /* @__PURE__ */ new Set([A(e, t)]);
21
+ return e.rel === "alternate" && e.hreflang && n.add(`link:${e.rel}:${e.hreflang}`), e.rel === "canonical" && n.add("link:canonical:"), [...n];
22
+ }
23
+ function $(e, t, n) {
24
+ if (p(e, n) === p(t, n) || t.property && e.property === t.property || t.name && e.name === t.name) return !0;
25
+ const o = t[n];
26
+ return !!(o && e[n] === o);
27
+ }
28
+ function L(e, t, n) {
29
+ const o = e.filter((i) => !$(i, t, n));
30
+ return o.push(t), o;
31
+ }
32
+ function x(e, t, n) {
33
+ const o = new Set(g(t, n)), i = e.filter((c) => !g(c, n).some((l) => o.has(l)));
34
+ return i.push(t), i;
35
+ }
36
+ function k(e, t, n) {
37
+ let o = !1;
38
+ const i = e.map((c) => c.rel !== "canonical" ? c : (o = !0, { ...c, href: t }));
39
+ return o || i.unshift({
40
+ [n]: "i18n-can",
41
+ rel: "canonical",
42
+ href: t
43
+ }), i;
44
+ }
45
+ function h(e, t, n, o, i) {
46
+ const c = e.filter((l) => l.property !== t);
47
+ return c.push({
48
+ [o]: t === "og:locale" ? "i18n-og" : t === "og:url" ? "i18n-og-url" : `i18n-page-${t}`,
49
+ property: t,
50
+ content: n
51
+ }), c;
52
+ }
53
+ function D(e, t, n, o) {
54
+ const i = [];
55
+ for (const c of e) {
56
+ if (n && c === n) continue;
57
+ const l = t.find((f) => f.code === c);
58
+ if (!l) continue;
59
+ const a = d(l);
60
+ a && i.push({
61
+ [o]: `i18n-og-alt-${a}`,
62
+ property: "og:locale:alternate",
63
+ content: a
64
+ });
65
+ }
66
+ return i;
67
+ }
68
+ function S(e, t, n = {}) {
69
+ if (!t)
70
+ return {
71
+ htmlAttrs: { ...e.htmlAttrs },
72
+ meta: [...e.meta],
73
+ link: [...e.link]
74
+ };
75
+ const o = n.identifierAttribute ?? "id", i = new Set(t.disable ?? []);
76
+ let c = { ...e.htmlAttrs }, l = [...e.meta], a = [...e.link];
77
+ i.has("html") && (c = {}), i.has("hreflang") && (a = a.filter((r) => !m(r))), i.has("x-default") && (a = a.filter((r) => !s(r))), i.has("canonical") && (a = a.filter((r) => r.rel !== "canonical")), i.has("og") && (l = l.filter((r) => r.property !== "og:locale" && r.property !== "og:url")), i.has("og-alternates") && (l = l.filter((r) => r.property !== "og:locale:alternate"));
78
+ const f = t.replace;
79
+ if (f) {
80
+ if (f.canonical === !1 ? a = a.filter((r) => r.rel !== "canonical") : typeof f.canonical == "string" && (a = k(a, f.canonical, o)), f.hreflang === !1 ? a = a.filter((r) => !u(r)) : Array.isArray(f.hreflang) && (a = a.filter((r) => !u(r)), a.push(...f.hreflang)), f.xDefault === !1 ? a = a.filter((r) => !s(r)) : f.xDefault && (a = a.filter((r) => !s(r)), a.push(f.xDefault)), f.ogLocale === !1 ? l = l.filter((r) => r.property !== "og:locale") : typeof f.ogLocale == "string" && (l = h(l, "og:locale", f.ogLocale, o)), f.ogUrl === !1 ? l = l.filter((r) => r.property !== "og:url") : typeof f.ogUrl == "string" && (l = h(l, "og:url", f.ogUrl, o)), f.ogAlternates === !1)
81
+ l = l.filter((r) => r.property !== "og:locale:alternate");
82
+ else if (Array.isArray(f.ogAlternates)) {
83
+ l = l.filter((y) => y.property !== "og:locale:alternate");
84
+ const r = n.locales ?? [];
85
+ l.push(...D(f.ogAlternates, r, n.currentLocale, o));
86
+ }
87
+ }
88
+ t.htmlAttrs && (c = { ...c, ...t.htmlAttrs });
89
+ for (const r of t.meta ?? [])
90
+ l = L(l, r, o);
91
+ for (const r of t.link ?? [])
92
+ a = x(a, r, o);
93
+ return { htmlAttrs: c, meta: l, link: a };
94
+ }
95
+ export {
96
+ S as mergeI18nHead
97
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@i18n-micro/utils",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Framework-agnostic utilities for Nuxt I18n Micro (granular subpath imports).",
5
5
  "keywords": [
6
6
  "i18n",
@@ -31,6 +31,10 @@
31
31
  "sideEffects": false,
32
32
  "exports": {
33
33
  "./deep-merge": {
34
+ "production": {
35
+ "types": "./dist/deep-merge.d.ts",
36
+ "default": "./dist/deep-merge.mjs"
37
+ },
34
38
  "import": {
35
39
  "types": "./dist/deep-merge.d.ts",
36
40
  "default": "./dist/deep-merge.mjs"
@@ -42,6 +46,10 @@
42
46
  "default": "./dist/deep-merge.mjs"
43
47
  },
44
48
  "./merge-source": {
49
+ "production": {
50
+ "types": "./dist/merge-source.d.ts",
51
+ "default": "./dist/merge-source.mjs"
52
+ },
45
53
  "import": {
46
54
  "types": "./dist/merge-source.d.ts",
47
55
  "default": "./dist/merge-source.mjs"
@@ -53,6 +61,10 @@
53
61
  "default": "./dist/merge-source.mjs"
54
62
  },
55
63
  "./source-loader": {
64
+ "production": {
65
+ "types": "./dist/source-loader.d.ts",
66
+ "default": "./dist/source-loader.mjs"
67
+ },
56
68
  "import": {
57
69
  "types": "./dist/source-loader.d.ts",
58
70
  "default": "./dist/source-loader.mjs"
@@ -64,6 +76,10 @@
64
76
  "default": "./dist/source-loader.mjs"
65
77
  },
66
78
  "./payload-config": {
79
+ "production": {
80
+ "types": "./dist/payload-config.d.ts",
81
+ "default": "./dist/payload-config.mjs"
82
+ },
67
83
  "import": {
68
84
  "types": "./dist/payload-config.d.ts",
69
85
  "default": "./dist/payload-config.mjs"
@@ -75,6 +91,10 @@
75
91
  "default": "./dist/payload-config.mjs"
76
92
  },
77
93
  "./payload-url": {
94
+ "production": {
95
+ "types": "./dist/payload-url.d.ts",
96
+ "default": "./dist/payload-url.mjs"
97
+ },
78
98
  "import": {
79
99
  "types": "./dist/payload-url.d.ts",
80
100
  "default": "./dist/payload-url.mjs"
@@ -86,6 +106,10 @@
86
106
  "default": "./dist/payload-url.mjs"
87
107
  },
88
108
  "./payload-fetch": {
109
+ "production": {
110
+ "types": "./dist/payload-fetch.d.ts",
111
+ "default": "./dist/payload-fetch.mjs"
112
+ },
89
113
  "import": {
90
114
  "types": "./dist/payload-fetch.d.ts",
91
115
  "default": "./dist/payload-fetch.mjs"
@@ -97,6 +121,10 @@
97
121
  "default": "./dist/payload-fetch.mjs"
98
122
  },
99
123
  "./payload-stats": {
124
+ "production": {
125
+ "types": "./dist/payload-stats.d.ts",
126
+ "default": "./dist/payload-stats.mjs"
127
+ },
100
128
  "import": {
101
129
  "types": "./dist/payload-stats.d.ts",
102
130
  "default": "./dist/payload-stats.mjs"
@@ -108,6 +136,10 @@
108
136
  "default": "./dist/payload-stats.mjs"
109
137
  },
110
138
  "./accept-language": {
139
+ "production": {
140
+ "types": "./dist/accept-language.d.ts",
141
+ "default": "./dist/accept-language.mjs"
142
+ },
111
143
  "import": {
112
144
  "types": "./dist/accept-language.d.ts",
113
145
  "default": "./dist/accept-language.mjs"
@@ -119,6 +151,10 @@
119
151
  "default": "./dist/accept-language.mjs"
120
152
  },
121
153
  "./resolve-locale": {
154
+ "production": {
155
+ "types": "./dist/resolve-locale.d.ts",
156
+ "default": "./dist/resolve-locale.mjs"
157
+ },
122
158
  "import": {
123
159
  "types": "./dist/resolve-locale.d.ts",
124
160
  "default": "./dist/resolve-locale.mjs"
@@ -130,6 +166,10 @@
130
166
  "default": "./dist/resolve-locale.mjs"
131
167
  },
132
168
  "./resolve-og-locale": {
169
+ "production": {
170
+ "types": "./dist/resolve-og-locale.d.ts",
171
+ "default": "./dist/resolve-og-locale.mjs"
172
+ },
133
173
  "import": {
134
174
  "types": "./dist/resolve-og-locale.d.ts",
135
175
  "default": "./dist/resolve-og-locale.mjs"
@@ -140,7 +180,26 @@
140
180
  },
141
181
  "default": "./dist/resolve-og-locale.mjs"
142
182
  },
183
+ "./merge-i18n-head": {
184
+ "production": {
185
+ "types": "./dist/merge-i18n-head.d.ts",
186
+ "default": "./dist/merge-i18n-head.mjs"
187
+ },
188
+ "import": {
189
+ "types": "./dist/merge-i18n-head.d.ts",
190
+ "default": "./dist/merge-i18n-head.mjs"
191
+ },
192
+ "require": {
193
+ "types": "./dist/merge-i18n-head.d.cts",
194
+ "default": "./dist/merge-i18n-head.cjs"
195
+ },
196
+ "default": "./dist/merge-i18n-head.mjs"
197
+ },
143
198
  "./active-locales": {
199
+ "production": {
200
+ "types": "./dist/active-locales.d.ts",
201
+ "default": "./dist/active-locales.mjs"
202
+ },
144
203
  "import": {
145
204
  "types": "./dist/active-locales.d.ts",
146
205
  "default": "./dist/active-locales.mjs"
@@ -152,6 +211,10 @@
152
211
  "default": "./dist/active-locales.mjs"
153
212
  },
154
213
  "./cookie": {
214
+ "production": {
215
+ "types": "./dist/cookie.d.ts",
216
+ "default": "./dist/cookie.mjs"
217
+ },
155
218
  "import": {
156
219
  "types": "./dist/cookie.d.ts",
157
220
  "default": "./dist/cookie.mjs"
@@ -163,6 +226,10 @@
163
226
  "default": "./dist/cookie.mjs"
164
227
  },
165
228
  "./cache-control": {
229
+ "production": {
230
+ "types": "./dist/cache-control.d.ts",
231
+ "default": "./dist/cache-control.mjs"
232
+ },
166
233
  "import": {
167
234
  "types": "./dist/cache-control.d.ts",
168
235
  "default": "./dist/cache-control.mjs"
@@ -174,6 +241,10 @@
174
241
  "default": "./dist/cache-control.mjs"
175
242
  },
176
243
  "./parse-path": {
244
+ "production": {
245
+ "types": "./dist/parse-path.d.ts",
246
+ "default": "./dist/parse-path.mjs"
247
+ },
177
248
  "import": {
178
249
  "types": "./dist/parse-path.d.ts",
179
250
  "default": "./dist/parse-path.mjs"
@@ -185,6 +256,10 @@
185
256
  "default": "./dist/parse-path.mjs"
186
257
  },
187
258
  "./route-pattern": {
259
+ "production": {
260
+ "types": "./dist/route-pattern.d.ts",
261
+ "default": "./dist/route-pattern.mjs"
262
+ },
188
263
  "import": {
189
264
  "types": "./dist/route-pattern.d.ts",
190
265
  "default": "./dist/route-pattern.mjs"
@@ -196,6 +271,10 @@
196
271
  "default": "./dist/route-pattern.mjs"
197
272
  },
198
273
  "./route": {
274
+ "production": {
275
+ "types": "./dist/route.d.ts",
276
+ "default": "./dist/route.mjs"
277
+ },
199
278
  "import": {
200
279
  "types": "./dist/route.d.ts",
201
280
  "default": "./dist/route.mjs"
@@ -207,6 +286,10 @@
207
286
  "default": "./dist/route.mjs"
208
287
  },
209
288
  "./runtime-config": {
289
+ "production": {
290
+ "types": "./dist/runtime-config.d.ts",
291
+ "default": "./dist/runtime-config.mjs"
292
+ },
210
293
  "import": {
211
294
  "types": "./dist/runtime-config.d.ts",
212
295
  "default": "./dist/runtime-config.mjs"
@@ -218,6 +301,10 @@
218
301
  "default": "./dist/runtime-config.mjs"
219
302
  },
220
303
  "./normalize": {
304
+ "production": {
305
+ "types": "./dist/normalize.d.ts",
306
+ "default": "./dist/normalize.mjs"
307
+ },
221
308
  "import": {
222
309
  "types": "./dist/normalize.d.ts",
223
310
  "default": "./dist/normalize.mjs"
@@ -229,6 +316,10 @@
229
316
  "default": "./dist/normalize.mjs"
230
317
  },
231
318
  "./build": {
319
+ "production": {
320
+ "types": "./dist/build.d.ts",
321
+ "default": "./dist/build.mjs"
322
+ },
232
323
  "import": {
233
324
  "types": "./dist/build.d.ts",
234
325
  "default": "./dist/build.mjs"
@@ -247,7 +338,7 @@
247
338
  },
248
339
  "dependencies": {
249
340
  "globby": "^14.1.0",
250
- "@i18n-micro/types": "1.2.5"
341
+ "@i18n-micro/types": "1.2.6"
251
342
  },
252
343
  "devDependencies": {
253
344
  "publint": "^0.3.17",