@i18n-micro/utils 1.0.1 → 1.0.2

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.
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function c(n){const t=n.og?.trim();if(t)return t;const e=n.iso?.trim();if(!e)return null;const r=e.indexOf("_");if(r>0){const s=e.slice(0,r),o=e.slice(r+1);if(s.length>=2&&o.length===2)return`${s.toLowerCase()}_${o.toUpperCase()}`}const i=e.indexOf("-");if(i>0){const s=e.slice(0,i),o=e.slice(i+1);if(s.length>=2&&o.length===2&&/^[A-Za-z]{2}$/.test(o))return`${s.toLowerCase()}_${o.toUpperCase()}`}return null}function l(n,t={}){if(c(n)!==null||t.missingWarn===!1||process.env.NODE_ENV==="production")return;const e=t.tag??"og:locale",r=String(n.code??"unknown"),i=n.iso?`, iso: '${n.iso}'`:"";console.warn(`[i18n] Cannot derive ${e} for locale '${r}'${i}. Set locale.og (e.g. 'en_US') or use iso with a 2-letter region (e.g. 'en-US').`)}exports.resolveOgLocale=c;exports.warnUnresolvedOgLocale=l;
@@ -0,0 +1,17 @@
1
+ import { Locale } from '@i18n-micro/types';
2
+ type OgLocaleInput = Pick<Locale, 'og' | 'iso' | 'code'>;
3
+ export interface WarnUnresolvedOgLocaleOptions {
4
+ /** When false, suppresses the warning (same flag as missing translation keys). */
5
+ missingWarn?: boolean;
6
+ tag?: 'og:locale' | 'og:locale:alternate';
7
+ }
8
+ /**
9
+ * Resolve Open Graph locale (`language_TERRITORY`, underscore) for `og:locale` meta tags.
10
+ * Returns null when the value cannot be determined safely — no tag should be emitted.
11
+ */
12
+ export declare function resolveOgLocale(locale: OgLocaleInput): string | null;
13
+ /**
14
+ * Log a dev-only hint when `og:locale` / `og:locale:alternate` cannot be derived.
15
+ */
16
+ export declare function warnUnresolvedOgLocale(locale: OgLocaleInput, options?: WarnUnresolvedOgLocaleOptions): void;
17
+ export {};
@@ -0,0 +1,17 @@
1
+ import { Locale } from '@i18n-micro/types';
2
+ type OgLocaleInput = Pick<Locale, 'og' | 'iso' | 'code'>;
3
+ export interface WarnUnresolvedOgLocaleOptions {
4
+ /** When false, suppresses the warning (same flag as missing translation keys). */
5
+ missingWarn?: boolean;
6
+ tag?: 'og:locale' | 'og:locale:alternate';
7
+ }
8
+ /**
9
+ * Resolve Open Graph locale (`language_TERRITORY`, underscore) for `og:locale` meta tags.
10
+ * Returns null when the value cannot be determined safely — no tag should be emitted.
11
+ */
12
+ export declare function resolveOgLocale(locale: OgLocaleInput): string | null;
13
+ /**
14
+ * Log a dev-only hint when `og:locale` / `og:locale:alternate` cannot be derived.
15
+ */
16
+ export declare function warnUnresolvedOgLocale(locale: OgLocaleInput, options?: WarnUnresolvedOgLocaleOptions): void;
17
+ export {};
@@ -0,0 +1,30 @@
1
+ function c(n) {
2
+ const t = n.og?.trim();
3
+ if (t) return t;
4
+ const e = n.iso?.trim();
5
+ if (!e) return null;
6
+ const r = e.indexOf("_");
7
+ if (r > 0) {
8
+ const s = e.slice(0, r), o = e.slice(r + 1);
9
+ if (s.length >= 2 && o.length === 2)
10
+ return `${s.toLowerCase()}_${o.toUpperCase()}`;
11
+ }
12
+ const i = e.indexOf("-");
13
+ if (i > 0) {
14
+ const s = e.slice(0, i), o = e.slice(i + 1);
15
+ if (s.length >= 2 && o.length === 2 && /^[A-Za-z]{2}$/.test(o))
16
+ return `${s.toLowerCase()}_${o.toUpperCase()}`;
17
+ }
18
+ return null;
19
+ }
20
+ function l(n, t = {}) {
21
+ if (c(n) !== null || t.missingWarn === !1 || process.env.NODE_ENV === "production") return;
22
+ const e = t.tag ?? "og:locale", r = String(n.code ?? "unknown"), i = n.iso ? `, iso: '${n.iso}'` : "";
23
+ console.warn(
24
+ `[i18n] Cannot derive ${e} for locale '${r}'${i}. Set locale.og (e.g. 'en_US') or use iso with a 2-letter region (e.g. 'en-US').`
25
+ );
26
+ }
27
+ export {
28
+ c as resolveOgLocale,
29
+ l as warnUnresolvedOgLocale
30
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@i18n-micro/utils",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Framework-agnostic utilities for Nuxt I18n Micro (granular subpath imports).",
5
5
  "keywords": [
6
6
  "i18n",
@@ -129,6 +129,17 @@
129
129
  },
130
130
  "default": "./dist/resolve-locale.mjs"
131
131
  },
132
+ "./resolve-og-locale": {
133
+ "import": {
134
+ "types": "./dist/resolve-og-locale.d.ts",
135
+ "default": "./dist/resolve-og-locale.mjs"
136
+ },
137
+ "require": {
138
+ "types": "./dist/resolve-og-locale.d.cts",
139
+ "default": "./dist/resolve-og-locale.cjs"
140
+ },
141
+ "default": "./dist/resolve-og-locale.mjs"
142
+ },
132
143
  "./active-locales": {
133
144
  "import": {
134
145
  "types": "./dist/active-locales.d.ts",
@@ -236,7 +247,7 @@
236
247
  },
237
248
  "dependencies": {
238
249
  "globby": "^14.1.0",
239
- "@i18n-micro/types": "1.2.4"
250
+ "@i18n-micro/types": "1.2.5"
240
251
  },
241
252
  "devDependencies": {
242
253
  "publint": "^0.3.17",