@i18n-micro/route-strategy 1.1.2 → 1.1.3
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 +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +8 -5
- package/dist/utils/common.d.ts +2 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ At a high level, `@i18n-micro/route-strategy`:
|
|
|
28
28
|
- `globalLocaleRoutes` (custom paths per locale),
|
|
29
29
|
- `filesLocaleRoutes` (file‑level locale paths),
|
|
30
30
|
- `routeLocales` (locale restrictions),
|
|
31
|
-
- `noPrefixRedirect`
|
|
31
|
+
- `noPrefixRedirect` flag;
|
|
32
32
|
- keeps aliases, children and internal/excluded routes consistent.
|
|
33
33
|
|
|
34
34
|
All of this is done without any Nuxt runtime / Vue Router dependency – it operates purely on plain `NuxtPage` objects, so it is safe to run in Node during build and easy to test.
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("node:path"),S=require("node:fs"),k=require("@i18n-micro/core"),b=l=>l.map(e=>({...e})),K=l=>!!(l.redirect&&!l.file),F=(l,e,t,a="localized-")=>t?`${a}${l}-${e}`:`${a}${l}`,C=(l,e)=>l??(e??"").replace(/[^a-z0-9]/gi,"-").replace(/^-+|-+$/g,""),M=(l,e,t,a)=>t&&!(l===e.code&&!a),T=(l,e,t)=>(typeof l=="string"?l:l.code)===e.code&&!t,H=[/^\/sitemap.*\.xml$/,/^\/sitemap\.xml$/,/^\/robots\.txt$/,/^\/favicon\.ico$/,/^\/apple-touch-icon.*\.png$/,/^\/manifest\.json$/,/^\/sw\.js$/,/^\/workbox-.*\.js$/,/\.(xml|txt|ico|json|js|css|png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)$/];function E(l,e){if(/(?:^|\/)__[^/]+/.test(l))return!0;for(const t of H)if(t.test(l))return!0;if(e){for(const t of e)if(typeof t=="string"){if(t.includes("*")||t.includes("?")){if(new RegExp(t.replace(/\*/g,".*").replace(/\?/g,".")).test(l))return!0}else if(l===t||l.startsWith(t))return!0}else if(t instanceof RegExp&&t.test(l))return!0}return!1}function J(l,e){const t=l.reduce((o,s)=>{const i=o.find(r=>r.code===s.code);return i?Object.assign(i,s):o.push(s),o},[]).filter(o=>!o.disabled),a=t.find(o=>o.code===e)??{code:e};return{locales:t,defaultLocale:a}}function x(l){return l.split("/").map(e=>e.startsWith("[...")&&e.endsWith("]")?`:${e.substring(4,e.length-1)}(.*)*`:e.startsWith("[")&&e.endsWith("]")?`:${e.substring(1,e.length-1)}`:e).join("/")}const R=l=>{if(!l)return"";const e=w.posix.normalize(l).replace(/\/+$/,"");return e==="."?"":e},g=l=>l.startsWith("/")?l.slice(1):l;function O(...l){return w.posix.join(...l)}function Q(l){if(!(typeof l>"u"))return l.startsWith("/")&&l.endsWith("/")?l?.slice(1,-1):l}function V(l){return!l||!/[\u0080-\uFFFF]/.test(l)?l:l.split("/").map(e=>!e||e.startsWith(":")||!/[\u0080-\uFFFF]/.test(e)?e:encodeURI(e)).join("/")}function N(l,e,t){const a=Q(t?.toString()),o=a||(Array.isArray(l)?l.join("|"):l),s=V(e);return R(w.posix.join("/",`:locale(${o})`,s))}function I(l){const e=V(l);return R(e)}const X=(l,e)=>l??(e??"").replace(/[^a-z0-9]/gi,"-").replace(/^-+|-+$/g,"");function j(l){return g(l)||"/"}function _(l,e,t,a=""){const o={};return l.forEach(s=>{const i=X(s.name,s.path),r=R(O(a,s.path??"")),c=j(r),d=x(r),n=e[c]||e[d]||e[i];if(n)typeof n=="object"&&(o[c]=n);else{const h=t[i];h&&typeof h=="object"&&!Array.isArray(h)&&(o[c]=h)}if(s.children?.length){const h=R(O(a,s.path??""));Object.assign(o,_(s.children,e,t,h))}}),o}function Y(l){const e={};if(!l)return e;for(const t in l){const a=x(t),o=l[t];if(typeof o=="object"){const s={};for(const i in o){const r=o[i];r&&(s[i]=x(r))}e[a]=s}else e[a]=o}return e}class Z{constructor(e){this.locales=e.locales,this.defaultLocale=this.findLocaleByCode(e.locales,e.defaultLocaleCode)??{code:e.defaultLocaleCode},this.strategy=e.strategy,this.globalLocaleRoutes=Y(e.globalLocaleRoutes??{}),this.filesLocaleRoutes=e.filesLocaleRoutes??{},this.routeLocales=e.routeLocales??{},this.localizedPaths=_(e.pages,this.globalLocaleRoutes,this.filesLocaleRoutes),this.activeLocaleCodes=this.locales.filter(t=>t.code!==this.defaultLocale.code||k.isPrefixAndDefaultStrategy(this.strategy)||k.isPrefixStrategy(this.strategy)).map(t=>t.code),this.excludePatterns=e.excludePatterns,this.customRegex=e.customRegex,this.noPrefixRedirect=e.noPrefixRedirect??!1,this.localizedRouteNamePrefix=e.localizedRouteNamePrefix??"localized-",this.fallbackRedirectComponentPath=e.fallbackRedirectComponentPath,this.rawGlobalLocaleRoutes=e.rawGlobalLocaleRoutes}findLocaleByCode(e,t){return e.find(a=>a.code===t)}getAllowedLocales(e,t){const a=this.routeLocales[e]??this.routeLocales[t];return a?.length?a.filter(o=>this.locales.some(s=>s.code===o)):this.locales.map(o=>o.code)}getCustomPath(e,t){const a=j(e);return this.localizedPaths[a]?.[t]}getCustomPathsForPage(e,t){const a=j(e);return this.localizedPaths[a]??this.localizedPaths[t]}hasLocaleRestrictions(e,t){return!!(this.routeLocales[e]??this.routeLocales[t])}filterLocaleCodesWithoutCustomPaths(e){const t=j(e);return this.activeLocaleCodes.filter(a=>!this.localizedPaths[t]?.[a])}}function z(l,e){const t=(e??"").trim();return t.startsWith("/")?R(t):R(w.posix.join(l||"",t))}function p(l,e){const{path:t,name:a,children:o,meta:s,alias:i}=e,r={...l,path:t};return a!==void 0&&(r.name=a),o!==void 0&&(r.children=o),s!==void 0&&(r.meta={...l.meta,...s}),i!==void 0?(r.alias=i,r.meta={...r.meta,alias:i}):"alias"in e&&(r.alias=void 0,r.meta={...r.meta,alias:void 0}),r}function ee(l){const e=l.alias,t=l.meta?.alias,a=e??t;return Array.isArray(a)?a:[]}function D(l,e,t,a="localized-"){const o=ee(l);if(!o.length)return[];const s=[];for(const i of o){const r=N(e,i,t);s.push(p(l,{path:r,name:`${a}${l.name??""}`,alias:void 0,meta:{alias:void 0},children:l.children}))}return s}class W{processPage(e,t){if(e.path===void 0)throw new Error("page.path is required");if(K(e))return[e];if(e.path&&E(e.path,t.excludePatterns))return[e];const a=e.path??"",o=C(e.name,e.path),s=x(a);return t.globalLocaleRoutes[o]===!1||t.globalLocaleRoutes[s]===!1?[e]:this.generateVariants(e,t)}postProcess(e,t){return e}localizeChildren(e,t,a,o,s,i){return e.flatMap(r=>this.localizeChild(r,t,a,o,s,i))}localizeChildrenAllLocales(e,t,a,o,s){return e.flatMap(i=>this.localizeChildAllLocales(i,t,a,o,s))}localizeChildAllLocales(e,t,a,o,s){const i=z(a,e.path??""),r=z(t,e.path??""),c=j(r),d=s.localizedPaths[c];if(d)return o.flatMap(f=>{const P=d[f]??z(t,e.path??"");return this.localizeChild(e,P,a,f,s,!0)});const n=R(e.path??""),h=g(n),u=this.localizeChildrenAllLocales(b(e.children??[]),r,i,o,s),m=`${s.localizedRouteNamePrefix}${e.name??""}`;return[p(e,{path:h,name:m,children:u})]}localizeChild(e,t,a,o,s,i){const r=z(a,e.path??""),c=s.getCustomPath(r,o),d=g(R(c||(e.path??""))),n=c??z(t,e.path??""),h=this.localizeChildren(b(e.children??[]),n,r,o,s,i),u=C(e.name,e.path),m=`${s.localizedRouteNamePrefix}${u}-${o}`;return[p(e,{path:d,name:m,children:h})]}buildRoutePathForLocales(e,t,a,o,s,i,r){if(o){const c=e.includes(r);return i||!c?N(e,a,s):R(a)}return N(e,t,s)}}class te extends W{generateVariants(e,t){const a=e.path??"",o=C(e.name,e.path),s=t.getAllowedLocales(a,o),i=t.getCustomPathsForPage(a,o),r=b(e.children??[]),c=[];if(c.push(e),i)for(const d of s){const n=i[d];if(!n)continue;const h=R(n),u=R(a);if(h===u)continue;const m=I(n),f=F(o,d,!0),P=this.localizeChildrenForNoPrefix(r,h,a,a,d,t,1);c.push(p(e,{path:m,name:f,children:P,alias:[],meta:{alias:[]}})),t.noPrefixRedirect&&d===t.defaultLocale.code&&h!==u&&(e.redirect=h)}return c.push(...D(e,s,t.customRegex,t.localizedRouteNamePrefix)),c}localizeChildrenForNoPrefix(e,t,a,o,s,i,r){return e.map(c=>{const d=z(a,c.path??"");let n,h;if(r===1){const P=i.getCustomPath(d,s);if(P){const L=R(P);n=g(L),h=L}else{const L=R(c.path??"");n=g(L),h=z(t,c.path??"")}}else{const P=R(c.path??"");n=g(P),h=z(t,c.path??"")}const u=this.localizeChildrenForNoPrefix(b(c.children??[]),h,d,o,s,i,r+1),m=C(c.name,c.path),f=F(m,s,!0);return p(c,{path:n,name:f,children:u})})}}function ae(l){const e=l.alias??l.meta?.alias;return Array.isArray(e)?e:[]}class se extends W{generateVariants(e,t){const a=e.path??"",o=C(e.name,e.path),s=t.getAllowedLocales(a,o),i=t.getCustomPathsForPage(a,o),r=b(e.children??[]),c=[];if(i)for(const n of s){const h=i[n],u=h?R(h):a,m=N(n,u,t.customRegex),f=F(o,n,!!h,t.localizedRouteNamePrefix),P=h??a,L=this.localizeChildren(r,P,a,n,t,!0);c.push(p(e,{path:m,name:f,children:L,alias:[],meta:{alias:[]}}))}else{const n=N(s,a,t.customRegex),h=F(o,s[0],!1,t.localizedRouteNamePrefix),u=this.localizeChildrenAllLocales(r,a,a,s,t);c.push(p(e,{path:n,name:h,children:u,alias:[],meta:{alias:[]}}))}const d=ae(e);if(d.length)for(const n of d){const h=N(s,n,t.customRegex);c.push(p(e,{path:h,name:`${t.localizedRouteNamePrefix}${e.name??""}`,alias:void 0,meta:{alias:void 0}}))}return c}postProcess(e,t){const a=e.filter(s=>{if(s.name==="index"&&s.path==="/")return!1;const i=s.path??"";return!!(i&&E(i,t.excludePatterns)||t.globalLocaleRoutes[s.name??""]===!1||/^\/:locale/.test(i)||i==="/")}),o=t.defaultLocale.code;for(const[s,i]of Object.entries(t.globalLocaleRoutes)){if(i===!1||typeof i!="object")continue;const r=i[o];if(!r)continue;const c=s.startsWith("/")?s:`/${s}`,d=`/${o}${r.startsWith("/")?r:`/${r}`}`;c!==d&&a.push({path:c,name:`redirect-${s.replace(/\//g,"-")}`,redirect:d})}return t.fallbackRedirectComponentPath&&a.push({path:"/:pathMatch(.*)*",name:"custom-fallback-route",file:t.fallbackRedirectComponentPath,meta:{globalLocaleRoutes:t.rawGlobalLocaleRoutes??t.globalLocaleRoutes}}),a}}class oe extends W{generateVariants(e,t){const a=e.path??"",o=C(e.name,e.path),s=t.getAllowedLocales(a,o),i=t.getCustomPathsForPage(a,o),r=b(e.children??[]),c=[],d=t.defaultLocale.code;c.push(e);const n=t.locales.filter(u=>s.includes(u.code));if(n.length>0)if(i)for(const u of n){const m=i[u.code];if(m)if(u.code===d){const f=this.createLocalizedRoute(e,[u.code],r,!0,m,t.customRegex,!1,u.code,a,t);f&&c.push(f);const P=this.createLocalizedRoute(e,[u.code],r,!0,m,t.customRegex,!0,u.code,a,t);P&&c.push(P)}else{const f=this.createLocalizedRoute(e,[u.code],r,!0,m,t.customRegex,!1,u.code,a,t);f&&c.push(f)}else{const f=this.createLocalizedRoute(e,[u.code],r,!1,"",t.customRegex,!1,u.code,a,t);f&&c.push(f)}}else{const u=n.map(f=>f.code),m=this.createLocalizedRoute(e,u,r,!1,"",t.customRegex,!1,!0,a,t);m&&c.push(m)}const h=D(e,s,t.customRegex,t.localizedRouteNamePrefix);return h.length&&c.push(...h),c}postProcess(e,t){const a=[],o=[];for(const s of e){const i=s.name??"";typeof i=="string"&&i.startsWith(t.localizedRouteNamePrefix)?o.push(s):a.push(s)}return[...a,...o]}createLocalizedRoute(e,t,a,o,s="",i,r=!1,c=!1,d,n){const h=this.buildRoutePathForLocales(t,e.path??"",encodeURI(s),o,i,r,n.defaultLocale.code);if(!h||!(o&&s)&&h===e.path||t.length===0)return null;const m=t[0];if(!m)return null;const f=d??e.path??"",P=F(C(e.name??"",f),m,o,n.localizedRouteNamePrefix),L=r||m!==n.defaultLocale.code,y=t.length===1?this.localizeChildren(a,h,f,m,n,L):this.localizeChildrenAllLocales(a,h,f,t,n);return p(e,{path:h,name:P,children:y,alias:[],meta:{alias:[]}})}}class le extends W{generateVariants(e,t){const a=e.path??"",o=C(e.name,e.path),s=t.getAllowedLocales(a,o),i=t.getCustomPathsForPage(a,o),r=b(e.children??[]),c=[],d=t.defaultLocale.code;if(s.includes(d)){const u=i?.[d],m=u?R(u):a,f=u?{[d]:u}:{},P=this.createLocalizedChildren(r,a,[d],!1,!1,!1,f,t);c.push(p(e,{path:m,name:e.name,children:P}))}const n=t.locales.filter(u=>s.includes(u.code)&&u.code!==d);if(n.length)if(i)for(const u of n){const m=i[u.code];if(m){const f=this.createLocalizedRoute(e,[u.code],r,!0,m,t.customRegex,!1,u.code,a,t);f&&c.push(f)}else{const f=this.createLocalizedRoute(e,[u.code],r,!1,"",t.customRegex,!1,u.code,a,t);f&&c.push(f)}}else{const u=n.map(f=>f.code),m=this.createLocalizedRoute(e,u,r,!1,"",t.customRegex,!1,!0,a,t);m&&c.push(m)}const h=D(e,s,t.customRegex,t.localizedRouteNamePrefix);return h.length&&c.push(...h),c}postProcess(e,t){const a=[],o=[];for(const i of e){const r=i.name??"";typeof r=="string"&&r.startsWith(t.localizedRouteNamePrefix)?o.push(i):a.push(i)}const s=[...a,...o];return t.fallbackRedirectComponentPath&&s.push({path:"/:pathMatch(.*)*",name:"custom-fallback-route",file:t.fallbackRedirectComponentPath,meta:{globalLocaleRoutes:t.rawGlobalLocaleRoutes??t.globalLocaleRoutes}}),s}createLocalizedChildren(e,t,a,o=!0,s=!1,i=!1,r={},c){return e.flatMap(d=>this.createLocalizedVariants(d,t,a,o,s,i,r,c))}createLocalizedVariants(e,t,a,o,s,i=!1,r,c){const d=R(e.path??""),n=z(t,e.path??""),h=j(n),u=c.localizedPaths[h],m=!!u,f=[];if(!m){const P=g(d),L=this.createLocalizedChildren(b(e.children??[]),z(t,e.path??""),a,o,s,i,r,c),y=this.buildChildRouteName(e.name,i,c);return f.push(p(e,{path:P,name:y,children:L})),f}for(const P of a){const L=r?.[P],y=!!L,$=u?.[P];let A=R($||(e.path??""));y&&L&&($?A=R($):A=z(L,e.path??""));const v=M(P,c.defaultLocale,s,!1)?N(P,A,c.customRegex):A,q=g(v),G=$?R($):y?L:z(t,e.path??""),B=this.createLocalizedChildren(b(e.children??[]),G,[P],o,s,P,{...r,[P]:G},c),U=this.buildLocalizedRouteName(C(e.name,e.path),P,o,!!u,c);f.push(p(e,{path:q,name:U,children:B}))}return f}buildChildRouteName(e,t,a){return t===!0?`${a.localizedRouteNamePrefix}${e}`:typeof t=="string"?`${a.localizedRouteNamePrefix}${e}-${t}`:e}createLocalizedRoute(e,t,a,o,s="",i,r=!1,c=!1,d,n){const h=this.buildRoutePathForLocales(t,e.path??"",encodeURI(s),o,i,r,n.defaultLocale.code);if(!h||h===e.path||t.length===0)return null;const u=t[0];if(!u)return null;const m=d??e.path??"",f=F(C(e.name??"",m),u,o,n.localizedRouteNamePrefix);return p(e,{path:h,name:f,children:this.createLocalizedChildren(a,m,t,!0,!1,c,{[u]:s},n),alias:[],meta:{alias:[]}})}buildLocalizedRouteName(e,t,a,o=!1,s){return a?o?`${s.localizedRouteNamePrefix}${e}-${t}`:t&&!T(t,s.defaultLocale,!1)?`${s.localizedRouteNamePrefix}${e}-${t}`:`${s.localizedRouteNamePrefix}${e}`:e}}function ie(l){switch(l){case"no_prefix":return new te;case"prefix":return new se;case"prefix_and_default":return new oe;case"prefix_except_default":return new le;default:throw new Error(`Unknown route strategy: ${l}`)}}class re{constructor(e){this.localizedPaths={};const{locales:t,defaultLocaleCode:a,strategy:o,globalLocaleRoutes:s,filesLocaleRoutes:i={},routeLocales:r={},noPrefixRedirect:c,excludePatterns:d,localizedRouteNamePrefix:n="localized-",customRegexMatcher:h,fallbackRedirectComponentPath:u}=e,m=J(t,a);this.locales=m.locales,this.defaultLocale=m.defaultLocale,this.strategy=o,this.noPrefixRedirect=c,this.excludePatterns=d,this.localizedRouteNamePrefix=n,this.customRegex=h,this.fallbackRedirectComponentPath=u,this.activeLocaleCodes=this.computeActiveLocaleCodes();const f={};for(const P in s){const L=x(P),y=s[P];if(typeof y=="object"){const $={};for(const A in y){const v=y[A];v&&($[A]=x(v))}f[L]=$}else f[L]=y}this.globalLocaleRoutes=f,this.rawGlobalLocaleRoutes=s??{},this.filesLocaleRoutes=i??{},this.routeLocales=r??{}}computeActiveLocaleCodes(){return this.locales.filter(e=>e.code!==this.defaultLocale.code||k.isPrefixAndDefaultStrategy(this.strategy)||k.isPrefixStrategy(this.strategy)).map(e=>e.code)}extendPages(e){const t=new Z({locales:this.locales,defaultLocaleCode:this.defaultLocale.code,strategy:this.strategy,globalLocaleRoutes:this.globalLocaleRoutes,filesLocaleRoutes:this.filesLocaleRoutes,routeLocales:this.routeLocales,pages:e,excludePatterns:this.excludePatterns,customRegex:this.customRegex,noPrefixRedirect:this.noPrefixRedirect,localizedRouteNamePrefix:this.localizedRouteNamePrefix,fallbackRedirectComponentPath:this.fallbackRedirectComponentPath,rawGlobalLocaleRoutes:this.rawGlobalLocaleRoutes});this.localizedPaths=t.localizedPaths;const a=ie(this.strategy),o=[...e],s=[];for(const r of o)s.push(...a.processPage(r,t));const i=a.postProcess(s,t);e.length=0,e.push(...i)}extractLocalizedPaths(e,t=""){return _(e,this.globalLocaleRoutes,this.filesLocaleRoutes,t)}ensureTranslationFilesExist(e,t,a,o){this.locales.forEach(s=>{const i=w.join(a,t,`${s.code}.json`);this.ensureFileExists(i),o||e.forEach(r=>{const c=w.join(a,t,"pages",`${r}/${s.code}.json`);this.ensureFileExists(c)})})}ensureFileExists(e){const t=w.dirname(e);S.existsSync(t)||S.mkdirSync(t,{recursive:!0}),S.existsSync(e)||S.writeFileSync(e,JSON.stringify({}),"utf-8")}resolveLocalizedPath(e,t){const a=x(e),o=g(a)||"/";let s;const i=this.globalLocaleRoutes[o],r=this.globalLocaleRoutes[a];i&&typeof i=="object"&&!Array.isArray(i)?s=i[t]:r&&typeof r=="object"&&!Array.isArray(r)&&(s=r[t]);const c=!!s,d=s?R(s):R(a)||"";let n=!1;if(this.strategy==="no_prefix"?n=!1:this.strategy==="prefix"||this.strategy==="prefix_and_default"?n=!0:this.strategy==="prefix_except_default"&&(n=t!==this.defaultLocale.code),t===this.defaultLocale.code&&!c&&(this.strategy==="prefix_except_default"||this.strategy==="no_prefix")&&(n=!1),!n)return R(d)||"/";const h=g(d);return h?R(`/${t}/${h}`):`/${t}`}generateDataRoutes(e,t,a){const o=[],s=e.map(i=>i.name).filter(i=>typeof i=="string"&&i.length>0);for(const i of this.locales)if(o.push(`/${t}/general/${i.code}/data.json`),!a)for(const r of s)o.push(`/${t}/${r}/${i.code}/data.json`);return o}}exports.RouteGenerator=re;exports.buildFullPath=N;exports.buildFullPathNoPrefix=I;exports.buildRouteName=F;exports.cloneArray=b;exports.extractLocalizedPaths=_;exports.isInternalPath=E;exports.isLocaleDefault=T;exports.isPageRedirectOnly=K;exports.normalizePath=R;exports.normalizeRouteKey=x;exports.removeLeadingSlash=g;exports.shouldAddLocalePrefix=M;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("node:path"),S=require("node:fs"),k=require("@i18n-micro/core"),b=l=>l.map(e=>({...e})),K=l=>!!(l.redirect&&!l.file),F=(l,e,t,a="localized-")=>t?`${a}${l}-${e}`:`${a}${l}`,C=(l,e)=>l??(e??"").replace(/[^a-z0-9]/gi,"-").replace(/^-+|-+$/g,""),M=(l,e,t)=>t&&l!==e.code,T=(l,e)=>(typeof l=="string"?l:l.code)===e.code,H=[/^\/sitemap.*\.xml$/,/^\/sitemap\.xml$/,/^\/robots\.txt$/,/^\/favicon\.ico$/,/^\/apple-touch-icon.*\.png$/,/^\/manifest\.json$/,/^\/sw\.js$/,/^\/workbox-.*\.js$/,/\.(xml|txt|ico|json|js|css|png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)$/];function E(l,e){if(/(?:^|\/)__[^/]+/.test(l))return!0;for(const t of H)if(t.test(l))return!0;if(e){for(const t of e)if(typeof t=="string"){if(t.includes("*")||t.includes("?")){if(new RegExp(t.replace(/\*/g,".*").replace(/\?/g,".")).test(l))return!0}else if(l===t||l.startsWith(t))return!0}else if(t instanceof RegExp&&t.test(l))return!0}return!1}function J(l,e){const t=l.reduce((o,s)=>{const i=o.find(r=>r.code===s.code);return i?Object.assign(i,s):o.push(s),o},[]).filter(o=>!o.disabled),a=t.find(o=>o.code===e)??{code:e};return{locales:t,defaultLocale:a}}function x(l){return l.split("/").map(e=>e.startsWith("[...")&&e.endsWith("]")?`:${e.substring(4,e.length-1)}(.*)*`:e.startsWith("[")&&e.endsWith("]")?`:${e.substring(1,e.length-1)}`:e).join("/")}const R=l=>{if(!l)return"";const e=w.posix.normalize(l).replace(/\/+$/,"");return e==="."?"":e},g=l=>l.startsWith("/")?l.slice(1):l;function O(...l){return w.posix.join(...l)}function Q(l){if(!(typeof l>"u"))return l.startsWith("/")&&l.endsWith("/")?l?.slice(1,-1):l}function V(l){return!l||!/[\u0080-\uFFFF]/.test(l)?l:l.split("/").map(e=>!e||e.startsWith(":")||!/[\u0080-\uFFFF]/.test(e)?e:encodeURI(e)).join("/")}function N(l,e,t){const a=Q(t?.toString()),o=a||(Array.isArray(l)?l.join("|"):l),s=V(e);return R(w.posix.join("/",`:locale(${o})`,s))}function I(l){const e=V(l);return R(e)}const X=(l,e)=>l??(e??"").replace(/[^a-z0-9]/gi,"-").replace(/^-+|-+$/g,"");function j(l){return g(l)||"/"}function _(l,e,t,a=""){const o={};return l.forEach(s=>{const i=X(s.name,s.path),r=R(O(a,s.path??"")),c=j(r),d=x(r),n=e[c]||e[d]||e[i];if(n)typeof n=="object"&&(o[c]=n);else{const h=t[i];h&&typeof h=="object"&&!Array.isArray(h)&&(o[c]=h)}if(s.children?.length){const h=R(O(a,s.path??""));Object.assign(o,_(s.children,e,t,h))}}),o}function Y(l){const e={};if(!l)return e;for(const t in l){const a=x(t),o=l[t];if(typeof o=="object"){const s={};for(const i in o){const r=o[i];r&&(s[i]=x(r))}e[a]=s}else e[a]=o}return e}class Z{constructor(e){this.locales=e.locales,this.defaultLocale=this.findLocaleByCode(e.locales,e.defaultLocaleCode)??{code:e.defaultLocaleCode},this.strategy=e.strategy,this.globalLocaleRoutes=Y(e.globalLocaleRoutes??{}),this.filesLocaleRoutes=e.filesLocaleRoutes??{},this.routeLocales=e.routeLocales??{},this.localizedPaths=_(e.pages,this.globalLocaleRoutes,this.filesLocaleRoutes),this.activeLocaleCodes=this.locales.filter(t=>t.code!==this.defaultLocale.code||k.isPrefixAndDefaultStrategy(this.strategy)||k.isPrefixStrategy(this.strategy)).map(t=>t.code),this.excludePatterns=e.excludePatterns,this.customRegex=e.customRegex,this.noPrefixRedirect=e.noPrefixRedirect??!1,this.localizedRouteNamePrefix=e.localizedRouteNamePrefix??"localized-",this.fallbackRedirectComponentPath=e.fallbackRedirectComponentPath,this.rawGlobalLocaleRoutes=e.rawGlobalLocaleRoutes}findLocaleByCode(e,t){return e.find(a=>a.code===t)}getAllowedLocales(e,t){const a=this.routeLocales[e]??this.routeLocales[t];return a?.length?a.filter(o=>this.locales.some(s=>s.code===o)):this.locales.map(o=>o.code)}getCustomPath(e,t){const a=j(e);return this.localizedPaths[a]?.[t]}getCustomPathsForPage(e,t){const a=j(e);return this.localizedPaths[a]??this.localizedPaths[t]}hasLocaleRestrictions(e,t){return!!(this.routeLocales[e]??this.routeLocales[t])}filterLocaleCodesWithoutCustomPaths(e){const t=j(e);return this.activeLocaleCodes.filter(a=>!this.localizedPaths[t]?.[a])}}function z(l,e){const t=(e??"").trim();return t.startsWith("/")?R(t):R(w.posix.join(l||"",t))}function p(l,e){const{path:t,name:a,children:o,meta:s,alias:i}=e,r={...l,path:t};return a!==void 0&&(r.name=a),o!==void 0&&(r.children=o),s!==void 0&&(r.meta={...l.meta,...s}),i!==void 0?(r.alias=i,r.meta={...r.meta,alias:i}):"alias"in e&&(r.alias=void 0,r.meta={...r.meta,alias:void 0}),r}function ee(l){const e=l.alias,t=l.meta?.alias,a=e??t;return Array.isArray(a)?a:[]}function D(l,e,t,a="localized-"){const o=ee(l);if(!o.length)return[];const s=[];for(const i of o){const r=N(e,i,t);s.push(p(l,{path:r,name:`${a}${l.name??""}`,alias:void 0,meta:{alias:void 0},children:l.children}))}return s}class W{processPage(e,t){if(e.path===void 0)throw new Error("page.path is required");if(K(e))return[e];if(e.path&&E(e.path,t.excludePatterns))return[e];const a=e.path??"",o=C(e.name,e.path),s=x(a);return t.globalLocaleRoutes[o]===!1||t.globalLocaleRoutes[s]===!1?[e]:this.generateVariants(e,t)}postProcess(e,t){return e}localizeChildren(e,t,a,o,s,i){return e.flatMap(r=>this.localizeChild(r,t,a,o,s,i))}localizeChildrenAllLocales(e,t,a,o,s){return e.flatMap(i=>this.localizeChildAllLocales(i,t,a,o,s))}localizeChildAllLocales(e,t,a,o,s){const i=z(a,e.path??""),r=z(t,e.path??""),c=j(r),d=s.localizedPaths[c];if(d)return o.flatMap(f=>{const P=d[f]??z(t,e.path??"");return this.localizeChild(e,P,a,f,s,!0)});const n=R(e.path??""),h=g(n),u=this.localizeChildrenAllLocales(b(e.children??[]),r,i,o,s),m=`${s.localizedRouteNamePrefix}${e.name??""}`;return[p(e,{path:h,name:m,children:u})]}localizeChild(e,t,a,o,s,i){const r=z(a,e.path??""),c=s.getCustomPath(r,o),d=g(R(c||(e.path??""))),n=c??z(t,e.path??""),h=this.localizeChildren(b(e.children??[]),n,r,o,s,i),u=C(e.name,e.path),m=`${s.localizedRouteNamePrefix}${u}-${o}`;return[p(e,{path:d,name:m,children:h})]}buildRoutePathForLocales(e,t,a,o,s,i,r){if(o){const c=e.includes(r);return i||!c?N(e,a,s):R(a)}return N(e,t,s)}}class te extends W{generateVariants(e,t){const a=e.path??"",o=C(e.name,e.path),s=t.getAllowedLocales(a,o),i=t.getCustomPathsForPage(a,o),r=b(e.children??[]),c=[];if(c.push(e),i)for(const d of s){const n=i[d];if(!n)continue;const h=R(n),u=R(a);if(h===u)continue;const m=I(n),f=F(o,d,!0),P=this.localizeChildrenForNoPrefix(r,h,a,a,d,t,1);c.push(p(e,{path:m,name:f,children:P,alias:[],meta:{alias:[]}})),t.noPrefixRedirect&&d===t.defaultLocale.code&&h!==u&&(e.redirect=h)}return c.push(...D(e,s,t.customRegex,t.localizedRouteNamePrefix)),c}localizeChildrenForNoPrefix(e,t,a,o,s,i,r){return e.map(c=>{const d=z(a,c.path??"");let n,h;if(r===1){const P=i.getCustomPath(d,s);if(P){const L=R(P);n=g(L),h=L}else{const L=R(c.path??"");n=g(L),h=z(t,c.path??"")}}else{const P=R(c.path??"");n=g(P),h=z(t,c.path??"")}const u=this.localizeChildrenForNoPrefix(b(c.children??[]),h,d,o,s,i,r+1),m=C(c.name,c.path),f=F(m,s,!0);return p(c,{path:n,name:f,children:u})})}}function ae(l){const e=l.alias??l.meta?.alias;return Array.isArray(e)?e:[]}class se extends W{generateVariants(e,t){const a=e.path??"",o=C(e.name,e.path),s=t.getAllowedLocales(a,o),i=t.getCustomPathsForPage(a,o),r=b(e.children??[]),c=[];if(i)for(const n of s){const h=i[n],u=h?R(h):a,m=N(n,u,t.customRegex),f=F(o,n,!!h,t.localizedRouteNamePrefix),P=h??a,L=this.localizeChildren(r,P,a,n,t,!0);c.push(p(e,{path:m,name:f,children:L,alias:[],meta:{alias:[]}}))}else{const n=N(s,a,t.customRegex),h=F(o,s[0],!1,t.localizedRouteNamePrefix),u=this.localizeChildrenAllLocales(r,a,a,s,t);c.push(p(e,{path:n,name:h,children:u,alias:[],meta:{alias:[]}}))}const d=ae(e);if(d.length)for(const n of d){const h=N(s,n,t.customRegex);c.push(p(e,{path:h,name:`${t.localizedRouteNamePrefix}${e.name??""}`,alias:void 0,meta:{alias:void 0}}))}return c}postProcess(e,t){const a=e.filter(s=>{if(s.name==="index"&&s.path==="/")return!1;const i=s.path??"";return!!(i&&E(i,t.excludePatterns)||t.globalLocaleRoutes[s.name??""]===!1||/^\/:locale/.test(i)||i==="/")}),o=t.defaultLocale.code;for(const[s,i]of Object.entries(t.globalLocaleRoutes)){if(i===!1||typeof i!="object")continue;const r=i[o];if(!r)continue;const c=s.startsWith("/")?s:`/${s}`,d=`/${o}${r.startsWith("/")?r:`/${r}`}`;c!==d&&a.push({path:c,name:`redirect-${s.replace(/\//g,"-")}`,redirect:d})}return t.fallbackRedirectComponentPath&&a.push({path:"/:pathMatch(.*)*",name:"custom-fallback-route",file:t.fallbackRedirectComponentPath,meta:{globalLocaleRoutes:t.rawGlobalLocaleRoutes??t.globalLocaleRoutes}}),a}}class oe extends W{generateVariants(e,t){const a=e.path??"",o=C(e.name,e.path),s=t.getAllowedLocales(a,o),i=t.getCustomPathsForPage(a,o),r=b(e.children??[]),c=[],d=t.defaultLocale.code;c.push(e);const n=t.locales.filter(u=>s.includes(u.code));if(n.length>0)if(i)for(const u of n){const m=i[u.code];if(m)if(u.code===d){const f=this.createLocalizedRoute(e,[u.code],r,!0,m,t.customRegex,!1,u.code,a,t);f&&c.push(f);const P=this.createLocalizedRoute(e,[u.code],r,!0,m,t.customRegex,!0,u.code,a,t);P&&c.push(P)}else{const f=this.createLocalizedRoute(e,[u.code],r,!0,m,t.customRegex,!1,u.code,a,t);f&&c.push(f)}else{const f=this.createLocalizedRoute(e,[u.code],r,!1,"",t.customRegex,!1,u.code,a,t);f&&c.push(f)}}else{const u=n.map(f=>f.code),m=this.createLocalizedRoute(e,u,r,!1,"",t.customRegex,!1,!0,a,t);m&&c.push(m)}const h=D(e,s,t.customRegex,t.localizedRouteNamePrefix);return h.length&&c.push(...h),c}postProcess(e,t){const a=[],o=[];for(const s of e){const i=s.name??"";typeof i=="string"&&i.startsWith(t.localizedRouteNamePrefix)?o.push(s):a.push(s)}return[...a,...o]}createLocalizedRoute(e,t,a,o,s="",i,r=!1,c=!1,d,n){const h=this.buildRoutePathForLocales(t,e.path??"",encodeURI(s),o,i,r,n.defaultLocale.code);if(!h||!(o&&s)&&h===e.path||t.length===0)return null;const m=t[0];if(!m)return null;const f=d??e.path??"",P=F(C(e.name??"",f),m,o,n.localizedRouteNamePrefix),L=r||m!==n.defaultLocale.code,y=t.length===1?this.localizeChildren(a,h,f,m,n,L):this.localizeChildrenAllLocales(a,h,f,t,n);return p(e,{path:h,name:P,children:y,alias:[],meta:{alias:[]}})}}class le extends W{generateVariants(e,t){const a=e.path??"",o=C(e.name,e.path),s=t.getAllowedLocales(a,o),i=t.getCustomPathsForPage(a,o),r=b(e.children??[]),c=[],d=t.defaultLocale.code;if(s.includes(d)){const u=i?.[d],m=u?R(u):a,f=u?{[d]:u}:{},P=this.createLocalizedChildren(r,a,[d],!1,!1,!1,f,t);c.push(p(e,{path:m,name:e.name,children:P}))}const n=t.locales.filter(u=>s.includes(u.code)&&u.code!==d);if(n.length)if(i)for(const u of n){const m=i[u.code];if(m){const f=this.createLocalizedRoute(e,[u.code],r,!0,m,t.customRegex,!1,u.code,a,t);f&&c.push(f)}else{const f=this.createLocalizedRoute(e,[u.code],r,!1,"",t.customRegex,!1,u.code,a,t);f&&c.push(f)}}else{const u=n.map(f=>f.code),m=this.createLocalizedRoute(e,u,r,!1,"",t.customRegex,!1,!0,a,t);m&&c.push(m)}const h=D(e,s,t.customRegex,t.localizedRouteNamePrefix);return h.length&&c.push(...h),c}postProcess(e,t){const a=[],o=[];for(const i of e){const r=i.name??"";typeof r=="string"&&r.startsWith(t.localizedRouteNamePrefix)?o.push(i):a.push(i)}const s=[...a,...o];return t.fallbackRedirectComponentPath&&s.push({path:"/:pathMatch(.*)*",name:"custom-fallback-route",file:t.fallbackRedirectComponentPath,meta:{globalLocaleRoutes:t.rawGlobalLocaleRoutes??t.globalLocaleRoutes}}),s}createLocalizedChildren(e,t,a,o=!0,s=!1,i=!1,r={},c){return e.flatMap(d=>this.createLocalizedVariants(d,t,a,o,s,i,r,c))}createLocalizedVariants(e,t,a,o,s,i=!1,r,c){const d=R(e.path??""),n=z(t,e.path??""),h=j(n),u=c.localizedPaths[h],m=!!u,f=[];if(!m){const P=g(d),L=this.createLocalizedChildren(b(e.children??[]),z(t,e.path??""),a,o,s,i,r,c),y=this.buildChildRouteName(e.name,i,c);return f.push(p(e,{path:P,name:y,children:L})),f}for(const P of a){const L=r?.[P],y=!!L,$=u?.[P];let A=R($||(e.path??""));y&&L&&($?A=R($):A=z(L,e.path??""));const v=M(P,c.defaultLocale,s)?N(P,A,c.customRegex):A,q=g(v),G=$?R($):y?L:z(t,e.path??""),B=this.createLocalizedChildren(b(e.children??[]),G,[P],o,s,P,{...r,[P]:G},c),U=this.buildLocalizedRouteName(C(e.name,e.path),P,o,!!u,c);f.push(p(e,{path:q,name:U,children:B}))}return f}buildChildRouteName(e,t,a){return t===!0?`${a.localizedRouteNamePrefix}${e}`:typeof t=="string"?`${a.localizedRouteNamePrefix}${e}-${t}`:e}createLocalizedRoute(e,t,a,o,s="",i,r=!1,c=!1,d,n){const h=this.buildRoutePathForLocales(t,e.path??"",encodeURI(s),o,i,r,n.defaultLocale.code);if(!h||h===e.path||t.length===0)return null;const u=t[0];if(!u)return null;const m=d??e.path??"",f=F(C(e.name??"",m),u,o,n.localizedRouteNamePrefix);return p(e,{path:h,name:f,children:this.createLocalizedChildren(a,m,t,!0,!1,c,{[u]:s},n),alias:[],meta:{alias:[]}})}buildLocalizedRouteName(e,t,a,o=!1,s){return a?o?`${s.localizedRouteNamePrefix}${e}-${t}`:t&&!T(t,s.defaultLocale)?`${s.localizedRouteNamePrefix}${e}-${t}`:`${s.localizedRouteNamePrefix}${e}`:e}}function ie(l){switch(l){case"no_prefix":return new te;case"prefix":return new se;case"prefix_and_default":return new oe;case"prefix_except_default":return new le;default:throw new Error(`Unknown route strategy: ${l}`)}}class re{constructor(e){this.localizedPaths={};const{locales:t,defaultLocaleCode:a,strategy:o,globalLocaleRoutes:s,filesLocaleRoutes:i={},routeLocales:r={},noPrefixRedirect:c,excludePatterns:d,localizedRouteNamePrefix:n="localized-",customRegexMatcher:h,fallbackRedirectComponentPath:u}=e,m=J(t,a);this.locales=m.locales,this.defaultLocale=m.defaultLocale,this.strategy=o,this.noPrefixRedirect=c,this.excludePatterns=d,this.localizedRouteNamePrefix=n,this.customRegex=h,this.fallbackRedirectComponentPath=u,this.activeLocaleCodes=this.computeActiveLocaleCodes();const f={};for(const P in s){const L=x(P),y=s[P];if(typeof y=="object"){const $={};for(const A in y){const v=y[A];v&&($[A]=x(v))}f[L]=$}else f[L]=y}this.globalLocaleRoutes=f,this.rawGlobalLocaleRoutes=s??{},this.filesLocaleRoutes=i??{},this.routeLocales=r??{}}computeActiveLocaleCodes(){return this.locales.filter(e=>e.code!==this.defaultLocale.code||k.isPrefixAndDefaultStrategy(this.strategy)||k.isPrefixStrategy(this.strategy)).map(e=>e.code)}extendPages(e){const t=new Z({locales:this.locales,defaultLocaleCode:this.defaultLocale.code,strategy:this.strategy,globalLocaleRoutes:this.globalLocaleRoutes,filesLocaleRoutes:this.filesLocaleRoutes,routeLocales:this.routeLocales,pages:e,excludePatterns:this.excludePatterns,customRegex:this.customRegex,noPrefixRedirect:this.noPrefixRedirect,localizedRouteNamePrefix:this.localizedRouteNamePrefix,fallbackRedirectComponentPath:this.fallbackRedirectComponentPath,rawGlobalLocaleRoutes:this.rawGlobalLocaleRoutes});this.localizedPaths=t.localizedPaths;const a=ie(this.strategy),o=[...e],s=[];for(const r of o)s.push(...a.processPage(r,t));const i=a.postProcess(s,t);e.length=0,e.push(...i)}extractLocalizedPaths(e,t=""){return _(e,this.globalLocaleRoutes,this.filesLocaleRoutes,t)}ensureTranslationFilesExist(e,t,a,o){this.locales.forEach(s=>{const i=w.join(a,t,`${s.code}.json`);this.ensureFileExists(i),o||e.forEach(r=>{const c=w.join(a,t,"pages",`${r}/${s.code}.json`);this.ensureFileExists(c)})})}ensureFileExists(e){try{const t=w.dirname(e);S.existsSync(t)||S.mkdirSync(t,{recursive:!0}),S.existsSync(e)||S.writeFileSync(e,JSON.stringify({}),"utf-8")}catch{}}resolveLocalizedPath(e,t){const a=x(e),o=g(a)||"/";let s;const i=this.globalLocaleRoutes[o],r=this.globalLocaleRoutes[a];i&&typeof i=="object"&&!Array.isArray(i)?s=i[t]:r&&typeof r=="object"&&!Array.isArray(r)&&(s=r[t]);const c=!!s,d=s?R(s):R(a)||"";let n=!1;if(this.strategy==="no_prefix"?n=!1:this.strategy==="prefix"||this.strategy==="prefix_and_default"?n=!0:this.strategy==="prefix_except_default"&&(n=t!==this.defaultLocale.code),t===this.defaultLocale.code&&!c&&(this.strategy==="prefix_except_default"||this.strategy==="no_prefix")&&(n=!1),!n)return R(d)||"/";const h=g(d);return h?R(`/${t}/${h}`):`/${t}`}generateDataRoutes(e,t,a){const o=[],s=e.map(i=>i.name).filter(i=>typeof i=="string"&&i.length>0);for(const i of this.locales)if(o.push(`/${t}/general/${i.code}/data.json`),!a)for(const r of s)o.push(`/${t}/${r}/${i.code}/data.json`);return o}}exports.RouteGenerator=re;exports.buildFullPath=N;exports.buildFullPathNoPrefix=I;exports.buildRouteName=F;exports.cloneArray=b;exports.extractLocalizedPaths=_;exports.isInternalPath=E;exports.isLocaleDefault=T;exports.isPageRedirectOnly=K;exports.normalizePath=R;exports.normalizeRouteKey=x;exports.removeLeadingSlash=g;exports.shouldAddLocalePrefix=M;
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import N from "node:path";
|
|
2
2
|
import { existsSync as E, mkdirSync as B, writeFileSync as U } from "node:fs";
|
|
3
3
|
import { isPrefixAndDefaultStrategy as D, isPrefixStrategy as O } from "@i18n-micro/core";
|
|
4
|
-
const $ = (l) => l.map((e) => ({ ...e })), q = (l) => !!(l.redirect && !l.file), j = (l, e, t, a = "localized-") => t ? `${a}${l}-${e}` : `${a}${l}`, b = (l, e) => l ?? (e ?? "").replace(/[^a-z0-9]/gi, "-").replace(/^-+|-+$/g, ""), H = (l, e, t
|
|
4
|
+
const $ = (l) => l.map((e) => ({ ...e })), q = (l) => !!(l.redirect && !l.file), j = (l, e, t, a = "localized-") => t ? `${a}${l}-${e}` : `${a}${l}`, b = (l, e) => l ?? (e ?? "").replace(/[^a-z0-9]/gi, "-").replace(/^-+|-+$/g, ""), H = (l, e, t) => t && l !== e.code, J = (l, e) => (typeof l == "string" ? l : l.code) === e.code, Q = [
|
|
5
5
|
/^\/sitemap.*\.xml$/,
|
|
6
6
|
/^\/sitemap\.xml$/,
|
|
7
7
|
/^\/robots\.txt$/,
|
|
@@ -624,7 +624,7 @@ class ce extends k {
|
|
|
624
624
|
const L = r?.[P], g = !!L, C = u?.[P];
|
|
625
625
|
let x = R(C || (e.path ?? ""));
|
|
626
626
|
g && L && (C ? x = R(C) : x = z(L, e.path ?? ""));
|
|
627
|
-
const v = H(P, c.defaultLocale, s
|
|
627
|
+
const v = H(P, c.defaultLocale, s) ? A(P, x, c.customRegex) : x, T = y(v), W = C ? R(C) : g ? L : z(t, e.path ?? ""), V = this.createLocalizedChildren(
|
|
628
628
|
$(e.children ?? []),
|
|
629
629
|
W,
|
|
630
630
|
[P],
|
|
@@ -693,7 +693,7 @@ class ce extends k {
|
|
|
693
693
|
});
|
|
694
694
|
}
|
|
695
695
|
buildLocalizedRouteName(e, t, a, o = !1, s) {
|
|
696
|
-
return a ? o ? `${s.localizedRouteNamePrefix}${e}-${t}` : t && !J(t, s.defaultLocale
|
|
696
|
+
return a ? o ? `${s.localizedRouteNamePrefix}${e}-${t}` : t && !J(t, s.defaultLocale) ? `${s.localizedRouteNamePrefix}${e}-${t}` : `${s.localizedRouteNamePrefix}${e}` : e;
|
|
697
697
|
}
|
|
698
698
|
}
|
|
699
699
|
function ne(l) {
|
|
@@ -784,8 +784,11 @@ class de {
|
|
|
784
784
|
});
|
|
785
785
|
}
|
|
786
786
|
ensureFileExists(e) {
|
|
787
|
-
|
|
788
|
-
|
|
787
|
+
try {
|
|
788
|
+
const t = N.dirname(e);
|
|
789
|
+
E(t) || B(t, { recursive: !0 }), E(e) || U(e, JSON.stringify({}), "utf-8");
|
|
790
|
+
} catch {
|
|
791
|
+
}
|
|
789
792
|
}
|
|
790
793
|
/**
|
|
791
794
|
* Returns the localized path for a given URL and locale,
|
package/dist/utils/common.d.ts
CHANGED
|
@@ -4,6 +4,6 @@ export declare const cloneArray: <T extends object>(array: T[]) => T[];
|
|
|
4
4
|
export declare const isPageRedirectOnly: (page: NuxtPage) => boolean;
|
|
5
5
|
export declare const buildRouteName: (baseName: string, localeCode: string, isCustom: boolean, prefix?: string) => string;
|
|
6
6
|
export declare const buildRouteNameFromRoute: (name: string | null | undefined, routePath: string | null | undefined) => string;
|
|
7
|
-
export declare const shouldAddLocalePrefix: (locale: string, defaultLocale: Locale, addLocalePrefix: boolean
|
|
8
|
-
export declare const isLocaleDefault: (locale: string | Locale, defaultLocale: Locale
|
|
7
|
+
export declare const shouldAddLocalePrefix: (locale: string, defaultLocale: Locale, addLocalePrefix: boolean) => boolean;
|
|
8
|
+
export declare const isLocaleDefault: (locale: string | Locale, defaultLocale: Locale) => boolean;
|
|
9
9
|
export declare function isInternalPath(path: string, excludePatterns?: (string | RegExp | object)[]): boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@i18n-micro/route-strategy",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "Locale-aware route generator for Nuxt i18n micro",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"sideEffects": false,
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"@nuxt/schema": "^3.18.1 || ^4.0.0",
|
|
58
|
-
"@i18n-micro/
|
|
59
|
-
"@i18n-micro/
|
|
58
|
+
"@i18n-micro/core": "1.1.3",
|
|
59
|
+
"@i18n-micro/types": "1.1.3"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@types/jest": "^29.5.14",
|