next-intl 3.15.3-canary.0 → 3.15.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/dist/development/middleware/utils.js +2 -50
- package/dist/development/navigation/react-client/createLocalizedPathnamesNavigation.js +1 -5
- package/dist/development/navigation/shared/utils.js +15 -15
- package/dist/development/shared/utils.js +46 -0
- package/dist/esm/middleware/utils.js +1 -1
- package/dist/esm/navigation/react-client/createLocalizedPathnamesNavigation.js +1 -1
- package/dist/esm/navigation/shared/utils.js +1 -1
- package/dist/esm/shared/utils.js +1 -1
- package/dist/production/middleware/utils.js +1 -1
- package/dist/production/navigation/react-client/createLocalizedPathnamesNavigation.js +1 -1
- package/dist/production/navigation/shared/utils.js +1 -1
- package/dist/production/shared/utils.js +1 -1
- package/dist/types/src/middleware/utils.d.ts +0 -2
- package/dist/types/src/navigation/shared/utils.d.ts +1 -5
- package/dist/types/src/shared/utils.d.ts +1 -0
- package/package.json +5 -5
|
@@ -4,54 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var utils = require('../shared/utils.js');
|
|
6
6
|
|
|
7
|
-
function isOptionalCatchAllSegment(pathname) {
|
|
8
|
-
return pathname.includes('[[...');
|
|
9
|
-
}
|
|
10
|
-
function isCatchAllSegment(pathname) {
|
|
11
|
-
return pathname.includes('[...');
|
|
12
|
-
}
|
|
13
|
-
function isDynamicSegment(pathname) {
|
|
14
|
-
return pathname.includes('[');
|
|
15
|
-
}
|
|
16
|
-
function comparePathnamePairs(a, b) {
|
|
17
|
-
const pathA = a.split('/');
|
|
18
|
-
const pathB = b.split('/');
|
|
19
|
-
const maxLength = Math.max(pathA.length, pathB.length);
|
|
20
|
-
for (let i = 0; i < maxLength; i++) {
|
|
21
|
-
const segmentA = pathA[i];
|
|
22
|
-
const segmentB = pathB[i];
|
|
23
|
-
|
|
24
|
-
// If one of the paths ends, prioritize the shorter path
|
|
25
|
-
if (!segmentA && segmentB) return -1;
|
|
26
|
-
if (segmentA && !segmentB) return 1;
|
|
27
|
-
|
|
28
|
-
// Prioritize static segments over dynamic segments
|
|
29
|
-
if (!isDynamicSegment(segmentA) && isDynamicSegment(segmentB)) return -1;
|
|
30
|
-
if (isDynamicSegment(segmentA) && !isDynamicSegment(segmentB)) return 1;
|
|
31
|
-
|
|
32
|
-
// Prioritize non-catch-all segments over catch-all segments
|
|
33
|
-
if (!isCatchAllSegment(segmentA) && isCatchAllSegment(segmentB)) return -1;
|
|
34
|
-
if (isCatchAllSegment(segmentA) && !isCatchAllSegment(segmentB)) return 1;
|
|
35
|
-
|
|
36
|
-
// Prioritize non-optional catch-all segments over optional catch-all segments
|
|
37
|
-
if (!isOptionalCatchAllSegment(segmentA) && isOptionalCatchAllSegment(segmentB)) {
|
|
38
|
-
return -1;
|
|
39
|
-
}
|
|
40
|
-
if (isOptionalCatchAllSegment(segmentA) && !isOptionalCatchAllSegment(segmentB)) {
|
|
41
|
-
return 1;
|
|
42
|
-
}
|
|
43
|
-
if (segmentA === segmentB) continue;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Both pathnames are completely static
|
|
47
|
-
return 0;
|
|
48
|
-
}
|
|
49
|
-
function getSortedPathnames(pathnames) {
|
|
50
|
-
const sortedPathnames = pathnames.sort(comparePathnamePairs);
|
|
51
|
-
return sortedPathnames;
|
|
52
|
-
}
|
|
53
7
|
function getInternalTemplate(pathnames, pathname, locale) {
|
|
54
|
-
const sortedPathnames = getSortedPathnames(Object.keys(pathnames));
|
|
8
|
+
const sortedPathnames = utils.getSortedPathnames(Object.keys(pathnames));
|
|
55
9
|
|
|
56
10
|
// Try to find a localized pathname that matches
|
|
57
11
|
for (const internalPathname of sortedPathnames) {
|
|
@@ -81,7 +35,7 @@ function getInternalTemplate(pathnames, pathname, locale) {
|
|
|
81
35
|
}
|
|
82
36
|
|
|
83
37
|
// Try to find an internal pathname that matches (this can be the case
|
|
84
|
-
// if all localized pathnames are different from the internal pathnames)
|
|
38
|
+
// if all localized pathnames are different from the internal pathnames)
|
|
85
39
|
for (const internalPathname of Object.keys(pathnames)) {
|
|
86
40
|
if (utils.matchesPathname(internalPathname, pathname)) {
|
|
87
41
|
return [undefined, internalPathname];
|
|
@@ -232,7 +186,6 @@ function getLocaleAsPrefix(locale) {
|
|
|
232
186
|
}
|
|
233
187
|
|
|
234
188
|
exports.applyBasePath = applyBasePath;
|
|
235
|
-
exports.comparePathnamePairs = comparePathnamePairs;
|
|
236
189
|
exports.formatPathname = formatPathname;
|
|
237
190
|
exports.formatPathnameTemplate = formatPathnameTemplate;
|
|
238
191
|
exports.formatTemplatePathname = formatTemplatePathname;
|
|
@@ -244,6 +197,5 @@ exports.getLocalePrefixes = getLocalePrefixes;
|
|
|
244
197
|
exports.getNormalizedPathname = getNormalizedPathname;
|
|
245
198
|
exports.getPathnameMatch = getPathnameMatch;
|
|
246
199
|
exports.getRouteParams = getRouteParams;
|
|
247
|
-
exports.getSortedPathnames = getSortedPathnames;
|
|
248
200
|
exports.isLocaleSupportedOnDomain = isLocaleSupportedOnDomain;
|
|
249
201
|
exports.normalizeTrailingSlash = normalizeTrailingSlash;
|
|
@@ -125,11 +125,7 @@ function createLocalizedPathnamesNavigation(input) {
|
|
|
125
125
|
const locale = useTypedLocale();
|
|
126
126
|
|
|
127
127
|
// @ts-expect-error -- Mirror the behavior from Next.js, where `null` is returned when `usePathname` is used outside of Next, but the types indicate that a string is always returned.
|
|
128
|
-
return pathname ? utils.getRoute(
|
|
129
|
-
pathname,
|
|
130
|
-
locale,
|
|
131
|
-
pathnames: config$1.pathnames
|
|
132
|
-
}) : pathname;
|
|
128
|
+
return pathname ? utils.getRoute(locale, pathname, config$1.pathnames) : pathname;
|
|
133
129
|
}
|
|
134
130
|
function getPathname(_ref2) {
|
|
135
131
|
let {
|
|
@@ -84,23 +84,23 @@ function compileLocalizedPathname(_ref) {
|
|
|
84
84
|
return result;
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
-
function getRoute(
|
|
88
|
-
|
|
89
|
-
let {
|
|
90
|
-
locale,
|
|
91
|
-
pathname,
|
|
92
|
-
pathnames
|
|
93
|
-
} = _ref3;
|
|
87
|
+
function getRoute(locale, pathname, pathnames) {
|
|
88
|
+
const sortedPathnames = utils.getSortedPathnames(Object.keys(pathnames));
|
|
94
89
|
const decoded = decodeURI(pathname);
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
90
|
+
for (const internalPathname of sortedPathnames) {
|
|
91
|
+
const localizedPathnamesOrPathname = pathnames[internalPathname];
|
|
92
|
+
if (typeof localizedPathnamesOrPathname === 'string') {
|
|
93
|
+
const localizedPathname = localizedPathnamesOrPathname;
|
|
94
|
+
if (utils.matchesPathname(localizedPathname, decoded)) {
|
|
95
|
+
return internalPathname;
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
if (utils.matchesPathname(localizedPathnamesOrPathname[locale], decoded)) {
|
|
99
|
+
return internalPathname;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
102
|
}
|
|
103
|
-
return
|
|
103
|
+
return pathname;
|
|
104
104
|
}
|
|
105
105
|
function getBasePath(pathname) {
|
|
106
106
|
let windowPathname = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : window.location.pathname;
|
|
@@ -85,8 +85,54 @@ function templateToRegex(template) {
|
|
|
85
85
|
.replace(/\[([^\]]+)\]/g, '([^/]+)');
|
|
86
86
|
return new RegExp("^".concat(regexPattern, "$"));
|
|
87
87
|
}
|
|
88
|
+
function isOptionalCatchAllSegment(pathname) {
|
|
89
|
+
return pathname.includes('[[...');
|
|
90
|
+
}
|
|
91
|
+
function isCatchAllSegment(pathname) {
|
|
92
|
+
return pathname.includes('[...');
|
|
93
|
+
}
|
|
94
|
+
function isDynamicSegment(pathname) {
|
|
95
|
+
return pathname.includes('[');
|
|
96
|
+
}
|
|
97
|
+
function comparePathnamePairs(a, b) {
|
|
98
|
+
const pathA = a.split('/');
|
|
99
|
+
const pathB = b.split('/');
|
|
100
|
+
const maxLength = Math.max(pathA.length, pathB.length);
|
|
101
|
+
for (let i = 0; i < maxLength; i++) {
|
|
102
|
+
const segmentA = pathA[i];
|
|
103
|
+
const segmentB = pathB[i];
|
|
104
|
+
|
|
105
|
+
// If one of the paths ends, prioritize the shorter path
|
|
106
|
+
if (!segmentA && segmentB) return -1;
|
|
107
|
+
if (segmentA && !segmentB) return 1;
|
|
108
|
+
|
|
109
|
+
// Prioritize static segments over dynamic segments
|
|
110
|
+
if (!isDynamicSegment(segmentA) && isDynamicSegment(segmentB)) return -1;
|
|
111
|
+
if (isDynamicSegment(segmentA) && !isDynamicSegment(segmentB)) return 1;
|
|
112
|
+
|
|
113
|
+
// Prioritize non-catch-all segments over catch-all segments
|
|
114
|
+
if (!isCatchAllSegment(segmentA) && isCatchAllSegment(segmentB)) return -1;
|
|
115
|
+
if (isCatchAllSegment(segmentA) && !isCatchAllSegment(segmentB)) return 1;
|
|
116
|
+
|
|
117
|
+
// Prioritize non-optional catch-all segments over optional catch-all segments
|
|
118
|
+
if (!isOptionalCatchAllSegment(segmentA) && isOptionalCatchAllSegment(segmentB)) {
|
|
119
|
+
return -1;
|
|
120
|
+
}
|
|
121
|
+
if (isOptionalCatchAllSegment(segmentA) && !isOptionalCatchAllSegment(segmentB)) {
|
|
122
|
+
return 1;
|
|
123
|
+
}
|
|
124
|
+
if (segmentA === segmentB) continue;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Both pathnames are completely static
|
|
128
|
+
return 0;
|
|
129
|
+
}
|
|
130
|
+
function getSortedPathnames(pathnames) {
|
|
131
|
+
return pathnames.sort(comparePathnamePairs);
|
|
132
|
+
}
|
|
88
133
|
|
|
89
134
|
exports.getLocalePrefix = getLocalePrefix;
|
|
135
|
+
exports.getSortedPathnames = getSortedPathnames;
|
|
90
136
|
exports.hasPathnamePrefixed = hasPathnamePrefixed;
|
|
91
137
|
exports.isLocalHref = isLocalHref;
|
|
92
138
|
exports.isLocalizableHref = isLocalizableHref;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{getSortedPathnames as t,matchesPathname as e,getLocalePrefix as n,templateToRegex as o,prefixPathname as r}from"../shared/utils.js";function c(n,o,r){const c=t(Object.keys(n));for(const t of c){const c=n[t];if("string"==typeof c){if(e(c,o))return[void 0,t]}else{const n=Object.entries(c),l=n.findIndex((t=>{let[e]=t;return e===r}));l>0&&n.unshift(n.splice(l,1)[0]);for(const[r,c]of n)if(e(c,o))return[r,t]}}for(const t of Object.keys(n))if(e(t,o))return[void 0,t];return[void 0,void 0]}function l(t,e,n,o){let r="";return r+=a(n,f(e,t)),r=x(r),r}function i(t,e,n){t.endsWith("/")||(t+="/");const o=u(e,n),r=new RegExp("^(".concat(o.map((t=>{let[,e]=t;return e.replaceAll("/","\\/")})).join("|"),")/(.*)"),"i"),c=t.match(r);let l=c?"/"+c[2]:t;return"/"!==l&&(l=x(l)),l}function u(t,e){return t.map((t=>[t,n(t,e)]))}function s(t,e,n){const o=u(e,n);for(const[e,n]of o){let o,r;if(t===n||t.startsWith(n+"/"))o=r=!0;else{const e=t.toLowerCase(),c=n.toLowerCase();(e===c||e.startsWith(c+"/"))&&(o=!1,r=!0)}if(r)return{locale:e,prefix:n,matchedPrefix:t.slice(0,n.length),exact:o}}}function f(t,e){const n=o(t).exec(e);if(!n)return;const r={};for(let e=1;e<n.length;e++){var c;const o=null===(c=t.match(/\[([^\]]+)\]/g))||void 0===c?void 0:c[e-1].replace(/[[\]]/g,"");o&&(r[o]=n[e])}return r}function a(t,e){if(!e)return t;let n=t=t.replace(/\[\[/g,"[").replace(/\]\]/g,"]");return Object.entries(e).forEach((t=>{let[e,o]=t;n=n.replace("[".concat(e,"]"),o)})),n}function d(t,e,n){let o=t;return e&&(o=r(e,o)),n&&(o+=n),o}function h(t){var e,n;return null!==(e=null!==(n=t.get("x-forwarded-host"))&&void 0!==n?n:t.get("host"))&&void 0!==e?e:void 0}function p(t,e){return e.defaultLocale===t||!e.locales||e.locales.includes(t)}function v(t,e,n){let o;return t&&p(e,t)&&(o=t),o||(o=n.find((t=>t.defaultLocale===e))),o||(o=n.find((t=>null!=t.locales&&t.locales.includes(e)))),o||null!=(null==t?void 0:t.locales)||(o=t),o||(o=n.find((t=>!t.locales))),o}function g(t,e){return x(e+t)}function x(t){return"/"!==t&&t.endsWith("/")&&(t=t.slice(0,-1)),t}function m(t){return"/".concat(t)}export{g as applyBasePath,d as formatPathname,a as formatPathnameTemplate,l as formatTemplatePathname,v as getBestMatchingDomain,h as getHost,c as getInternalTemplate,m as getLocaleAsPrefix,u as getLocalePrefixes,i as getNormalizedPathname,s as getPathnameMatch,f as getRouteParams,p as isLocaleSupportedOnDomain,x as normalizeTrailingSlash};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r,{forwardRef as o}from"react";import t from"../../react-client/useLocale.js";import{receiveLocalizedNavigationRoutingConfig as
|
|
1
|
+
import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r,{forwardRef as o}from"react";import t from"../../react-client/useLocale.js";import{receiveLocalizedNavigationRoutingConfig as n}from"../shared/config.js";import{getRoute as a,compileLocalizedPathname as l,normalizeNameOrNameWithParams as c}from"../shared/utils.js";import i from"./ClientLink.js";import{clientRedirect as s,clientPermanentRedirect as f}from"./redirects.js";import u from"./useBasePathname.js";import m from"./useBaseRouter.js";function h(h){const p=n(h);function d(){const e=t();if(!p.locales.includes(e))throw new Error('Unknown locale encountered: "'.concat(e,'". Make sure to validate the locale in `i18n.ts`.'));return e}function v(o,t){let{href:n,locale:a,...c}=o;const s=d(),f=a||s;return r.createElement(i,e({ref:t,href:l({locale:f,pathname:n,params:"object"==typeof n?n.params:void 0,pathnames:p.pathnames}),locale:a,localePrefix:p.localePrefix},c))}const P=o(v);function x(e){let{href:r,locale:o}=e;return l({...c(r),locale:o,pathnames:p.pathnames})}return P.displayName="Link",{Link:P,redirect:function(e){const r=x({href:e,locale:d()});for(var o=arguments.length,t=new Array(o>1?o-1:0),n=1;n<o;n++)t[n-1]=arguments[n];return s({pathname:r,localePrefix:p.localePrefix},...t)},permanentRedirect:function(e){const r=x({href:e,locale:d()});for(var o=arguments.length,t=new Array(o>1?o-1:0),n=1;n<o;n++)t[n-1]=arguments[n];return f({pathname:r,localePrefix:p.localePrefix},...t)},usePathname:function(){const e=u(p.localePrefix),r=d();return e?a(r,e,p.pathnames):e},useRouter:function(){const e=m(p.localePrefix),r=d();return{...e,push(o){for(var t,n=arguments.length,a=new Array(n>1?n-1:0),l=1;l<n;l++)a[l-1]=arguments[l];const c=x({href:o,locale:(null===(t=a[0])||void 0===t?void 0:t.locale)||r});return e.push(c,...a)},replace(o){for(var t,n=arguments.length,a=new Array(n>1?n-1:0),l=1;l<n;l++)a[l-1]=arguments[l];const c=x({href:o,locale:(null===(t=a[0])||void 0===t?void 0:t.locale)||r});return e.replace(c,...a)},prefetch(o){for(var t,n=arguments.length,a=new Array(n>1?n-1:0),l=1;l<n;l++)a[l-1]=arguments[l];const c=x({href:o,locale:(null===(t=a[0])||void 0===t?void 0:t.locale)||r});return e.prefetch(c,...a)}}},getPathname:x}}export{h as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{matchesPathname as
|
|
1
|
+
import{getSortedPathnames as t,matchesPathname as n}from"../../shared/utils.js";function r(t){return"string"==typeof t?{pathname:t}:t}function e(t){function n(t){return String(t)}const r=new URLSearchParams;for(const[e,o]of Object.entries(t))Array.isArray(o)?o.forEach((t=>{r.append(e,n(t))})):r.set(e,n(o));return"?"+r.toString()}function o(t){let{pathname:n,locale:r,params:o,pathnames:a,query:c}=t;function i(t){let n=a[t];return n||(n=t),n}function s(t){const n="string"==typeof t?t:t[r];let a=n;if(o&&Object.entries(o).forEach((t=>{let[n,r]=t;a=Array.isArray(r)?a.replace(new RegExp("(\\[)?\\[...".concat(n,"\\](\\])?"),"g"),r.map((t=>String(t))).join("/")):a.replace("[".concat(n,"]"),String(r))})),a.includes("["))throw new Error("Insufficient params provided for localized pathname.\nTemplate: ".concat(n,"\nParams: ").concat(JSON.stringify(o)));return c&&(a+=e(c)),a}if("string"==typeof n){return s(i(n))}{const{pathname:t,...r}=n;return{...r,pathname:s(i(t))}}}function a(r,e,o){const a=t(Object.keys(o)),c=decodeURI(e);for(const t of a){const e=o[t];if("string"==typeof e){if(n(e,c))return t}else if(n(e[r],c))return t}return e}function c(t){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:window.location.pathname;return"/"===t?n:n.replace(t,"")}export{o as compileLocalizedPathname,c as getBasePath,a as getRoute,r as normalizeNameOrNameWithParams,e as serializeSearchParams};
|
package/dist/esm/shared/utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function n(n){const t="object"==typeof n?n.pathname:n;return null!=t&&!t.startsWith("/")}function t(n){if("object"==typeof n)return null==n.host&&null==n.hostname;return!/^[a-z]+:/i.test(n)}function e(e){return t(e)&&!n(e)}function r(n,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,i=arguments.length>3?arguments[3]:void 0,o=arguments.length>4?arguments[4]:void 0;if(!e(n))return n;const f=t!==r,l=c(o,i);return(f||l)&&null!=o?u(n,o):n}function u(n,t){let e;return"string"==typeof n?e=o(t,n):(e={...n},n.pathname&&(e.pathname=o(t,n.pathname))),e}function i(n,t){return n.replace(new RegExp("^".concat(t)),"")||"/"}function o(n,t){let e=n;return/^\/(\?.*)?$/.test(t)&&(t=t.slice(1)),e+=t,e}function c(n,t){return t===n||t.startsWith("".concat(n,"/"))}function f(n,t){return s(n).test(t)}function l(n,t){var e;return"never"!==t.mode&&(null===(e=t.prefixes)||void 0===e?void 0:e[n])||"/"+n}function s(n){const t=n.replace(/\[\[(\.\.\.[^\]]+)\]\]/g,"?(.*)").replace(/\[(\.\.\.[^\]]+)\]/g,"(.+)").replace(/\[([^\]]+)\]/g,"([^/]+)");return new RegExp("^".concat(t,"$"))}function a(n){return n.includes("[[...")}function p(n){return n.includes("[...")}function h(n){return n.includes("[")}function g(n,t){const e=n.split("/"),r=t.split("/"),u=Math.max(e.length,r.length);for(let n=0;n<u;n++){const t=e[n],u=r[n];if(!t&&u)return-1;if(t&&!u)return 1;if(!h(t)&&h(u))return-1;if(h(t)&&!h(u))return 1;if(!p(t)&&p(u))return-1;if(p(t)&&!p(u))return 1;if(!a(t)&&a(u))return-1;if(a(t)&&!a(u))return 1}return 0}function d(n){return n.sort(g)}export{l as getLocalePrefix,d as getSortedPathnames,c as hasPathnamePrefixed,t as isLocalHref,e as isLocalizableHref,n as isRelativeHref,r as localizeHref,f as matchesPathname,u as prefixHref,o as prefixPathname,s as templateToRegex,i as unprefixPathname};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../shared/utils.js");function t(
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../shared/utils.js");function t(t,n){return t.map((t=>[t,e.getLocalePrefix(t,n)]))}function n(t,n){const o=e.templateToRegex(t).exec(n);if(!o)return;const r={};for(let e=1;e<o.length;e++){var a;const n=null===(a=t.match(/\[([^\]]+)\]/g))||void 0===a?void 0:a[e-1].replace(/[[\]]/g,"");n&&(r[n]=o[e])}return r}function o(e,t){if(!t)return e;let n=e=e.replace(/\[\[/g,"[").replace(/\]\]/g,"]");return Object.entries(t).forEach((e=>{let[t,o]=e;n=n.replace("[".concat(t,"]"),o)})),n}function r(e,t){return t.defaultLocale===e||!t.locales||t.locales.includes(e)}function a(e){return"/"!==e&&e.endsWith("/")&&(e=e.slice(0,-1)),e}exports.applyBasePath=function(e,t){return a(t+e)},exports.formatPathname=function(t,n,o){let r=t;return n&&(r=e.prefixPathname(n,r)),o&&(r+=o),r},exports.formatPathnameTemplate=o,exports.formatTemplatePathname=function(e,t,r,s){let c="";return c+=o(r,n(t,e)),c=a(c),c},exports.getBestMatchingDomain=function(e,t,n){let o;return e&&r(t,e)&&(o=e),o||(o=n.find((e=>e.defaultLocale===t))),o||(o=n.find((e=>null!=e.locales&&e.locales.includes(t)))),o||null!=(null==e?void 0:e.locales)||(o=e),o||(o=n.find((e=>!e.locales))),o},exports.getHost=function(e){var t,n;return null!==(t=null!==(n=e.get("x-forwarded-host"))&&void 0!==n?n:e.get("host"))&&void 0!==t?t:void 0},exports.getInternalTemplate=function(t,n,o){const r=e.getSortedPathnames(Object.keys(t));for(const a of r){const r=t[a];if("string"==typeof r){const t=r;if(e.matchesPathname(t,n))return[void 0,a]}else{const t=Object.entries(r),s=t.findIndex((e=>{let[t]=e;return t===o}));s>0&&t.unshift(t.splice(s,1)[0]);for(const[o,r]of t)if(e.matchesPathname(r,n))return[o,a]}}for(const o of Object.keys(t))if(e.matchesPathname(o,n))return[void 0,o];return[void 0,void 0]},exports.getLocaleAsPrefix=function(e){return"/".concat(e)},exports.getLocalePrefixes=t,exports.getNormalizedPathname=function(e,n,o){e.endsWith("/")||(e+="/");const r=t(n,o),s=new RegExp("^(".concat(r.map((e=>{let[,t]=e;return t.replaceAll("/","\\/")})).join("|"),")/(.*)"),"i"),c=e.match(s);let l=c?"/"+c[2]:e;return"/"!==l&&(l=a(l)),l},exports.getPathnameMatch=function(e,n,o){const r=t(n,o);for(const[t,n]of r){let o,r;if(e===n||e.startsWith(n+"/"))o=r=!0;else{const t=e.toLowerCase(),a=n.toLowerCase();(t===a||t.startsWith(a+"/"))&&(o=!1,r=!0)}if(r)return{locale:t,prefix:n,matchedPrefix:e.slice(0,n.length),exact:o}}},exports.getRouteParams=n,exports.isLocaleSupportedOnDomain=r,exports.normalizeTrailingSlash=a;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),a=require("../../react-client/useLocale.js"),t=require("../shared/config.js"),l=require("../shared/utils.js"),n=require("./ClientLink.js"),o=require("./redirects.js"),c=require("./useBasePathname.js"),i=require("./useBaseRouter.js");function u(e){return e&&e.__esModule?e:{default:e}}var s=u(r);exports.default=function(u){const f=t.receiveLocalizedNavigationRoutingConfig(u);function h(){const e=a.default();if(!f.locales.includes(e))throw new Error(void 0);return e}function d(r,a){let{href:t,locale:o,...c}=r;const i=h(),u=o||i;return s.default.createElement(n.default,e.extends({ref:a,href:l.compileLocalizedPathname({locale:u,pathname:t,params:"object"==typeof t?t.params:void 0,pathnames:f.pathnames}),locale:o,localePrefix:f.localePrefix},c))}const p=r.forwardRef(d);function m(e){let{href:r,locale:a}=e;return l.compileLocalizedPathname({...l.normalizeNameOrNameWithParams(r),locale:a,pathnames:f.pathnames})}return p.displayName="Link",{Link:p,redirect:function(e){const r=m({href:e,locale:h()});for(var a=arguments.length,t=new Array(a>1?a-1:0),l=1;l<a;l++)t[l-1]=arguments[l];return o.clientRedirect({pathname:r,localePrefix:f.localePrefix},...t)},permanentRedirect:function(e){const r=m({href:e,locale:h()});for(var a=arguments.length,t=new Array(a>1?a-1:0),l=1;l<a;l++)t[l-1]=arguments[l];return o.clientPermanentRedirect({pathname:r,localePrefix:f.localePrefix},...t)},usePathname:function(){const e=c.default(f.localePrefix),r=h();return e?l.getRoute(
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),a=require("../../react-client/useLocale.js"),t=require("../shared/config.js"),l=require("../shared/utils.js"),n=require("./ClientLink.js"),o=require("./redirects.js"),c=require("./useBasePathname.js"),i=require("./useBaseRouter.js");function u(e){return e&&e.__esModule?e:{default:e}}var s=u(r);exports.default=function(u){const f=t.receiveLocalizedNavigationRoutingConfig(u);function h(){const e=a.default();if(!f.locales.includes(e))throw new Error(void 0);return e}function d(r,a){let{href:t,locale:o,...c}=r;const i=h(),u=o||i;return s.default.createElement(n.default,e.extends({ref:a,href:l.compileLocalizedPathname({locale:u,pathname:t,params:"object"==typeof t?t.params:void 0,pathnames:f.pathnames}),locale:o,localePrefix:f.localePrefix},c))}const p=r.forwardRef(d);function m(e){let{href:r,locale:a}=e;return l.compileLocalizedPathname({...l.normalizeNameOrNameWithParams(r),locale:a,pathnames:f.pathnames})}return p.displayName="Link",{Link:p,redirect:function(e){const r=m({href:e,locale:h()});for(var a=arguments.length,t=new Array(a>1?a-1:0),l=1;l<a;l++)t[l-1]=arguments[l];return o.clientRedirect({pathname:r,localePrefix:f.localePrefix},...t)},permanentRedirect:function(e){const r=m({href:e,locale:h()});for(var a=arguments.length,t=new Array(a>1?a-1:0),l=1;l<a;l++)t[l-1]=arguments[l];return o.clientPermanentRedirect({pathname:r,localePrefix:f.localePrefix},...t)},usePathname:function(){const e=c.default(f.localePrefix),r=h();return e?l.getRoute(r,e,f.pathnames):e},useRouter:function(){const e=i.default(f.localePrefix),r=h();return{...e,push(a){for(var t,l=arguments.length,n=new Array(l>1?l-1:0),o=1;o<l;o++)n[o-1]=arguments[o];const c=m({href:a,locale:(null===(t=n[0])||void 0===t?void 0:t.locale)||r});return e.push(c,...n)},replace(a){for(var t,l=arguments.length,n=new Array(l>1?l-1:0),o=1;o<l;o++)n[o-1]=arguments[o];const c=m({href:a,locale:(null===(t=n[0])||void 0===t?void 0:t.locale)||r});return e.replace(c,...n)},prefetch(a){for(var t,l=arguments.length,n=new Array(l>1?l-1:0),o=1;o<l;o++)n[o-1]=arguments[o];const c=m({href:a,locale:(null===(t=n[0])||void 0===t?void 0:t.locale)||r});return e.prefetch(c,...n)}}},getPathname:m}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../shared/utils.js");function t(e){function t(e){return String(e)}const r=new URLSearchParams;for(const[n,a]of Object.entries(e))Array.isArray(a)?a.forEach((e=>{r.append(n,t(e))})):r.set(n,t(a));return"?"+r.toString()}exports.compileLocalizedPathname=function(e){let{pathname:r,locale:n,params:a,pathnames:o,query:
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../shared/utils.js");function t(e){function t(e){return String(e)}const r=new URLSearchParams;for(const[n,a]of Object.entries(e))Array.isArray(a)?a.forEach((e=>{r.append(n,t(e))})):r.set(n,t(a));return"?"+r.toString()}exports.compileLocalizedPathname=function(e){let{pathname:r,locale:n,params:a,pathnames:o,query:s}=e;function c(e){let t=o[e];return t||(t=e),t}function i(e){let r="string"==typeof e?e:e[n];return a&&Object.entries(a).forEach((e=>{let[t,n]=e;r=Array.isArray(n)?r.replace(new RegExp("(\\[)?\\[...".concat(t,"\\](\\])?"),"g"),n.map((e=>String(e))).join("/")):r.replace("[".concat(t,"]"),String(n))})),s&&(r+=t(s)),r}if("string"==typeof r){return i(c(r))}{const{pathname:e,...t}=r;return{...t,pathname:i(c(e))}}},exports.getBasePath=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:window.location.pathname;return"/"===e?t:t.replace(e,"")},exports.getRoute=function(t,r,n){const a=e.getSortedPathnames(Object.keys(n)),o=decodeURI(r);for(const r of a){const a=n[r];if("string"==typeof a){const t=a;if(e.matchesPathname(t,o))return r}else if(e.matchesPathname(a[t],o))return r}return r},exports.normalizeNameOrNameWithParams=function(e){return"string"==typeof e?{pathname:e}:e},exports.serializeSearchParams=t;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function e(e){const t="object"==typeof e?e.pathname:e;return null!=t&&!t.startsWith("/")}function t(e){if("object"==typeof e)return null==e.host&&null==e.hostname;return!/^[a-z]+:/i.test(e)}function n(n){return t(n)&&!e(n)}function r(e,t){let n;return"string"==typeof e?n=o(t,e):(n={...e},e.pathname&&(n.pathname=o(t,e.pathname))),n}function o(e,t){let n=e;return/^\/(\?.*)?$/.test(t)&&(t=t.slice(1)),n+=t,n}function
|
|
1
|
+
"use strict";function e(e){const t="object"==typeof e?e.pathname:e;return null!=t&&!t.startsWith("/")}function t(e){if("object"==typeof e)return null==e.host&&null==e.hostname;return!/^[a-z]+:/i.test(e)}function n(n){return t(n)&&!e(n)}function r(e,t){let n;return"string"==typeof e?n=o(t,e):(n={...e},e.pathname&&(n.pathname=o(t,e.pathname))),n}function o(e,t){let n=e;return/^\/(\?.*)?$/.test(t)&&(t=t.slice(1)),n+=t,n}function i(e,t){return t===e||t.startsWith("".concat(e,"/"))}function u(e){const t=e.replace(/\[\[(\.\.\.[^\]]+)\]\]/g,"?(.*)").replace(/\[(\.\.\.[^\]]+)\]/g,"(.+)").replace(/\[([^\]]+)\]/g,"([^/]+)");return new RegExp("^".concat(t,"$"))}function s(e){return e.includes("[[...")}function c(e){return e.includes("[...")}function a(e){return e.includes("[")}function f(e,t){const n=e.split("/"),r=t.split("/"),o=Math.max(n.length,r.length);for(let e=0;e<o;e++){const t=n[e],o=r[e];if(!t&&o)return-1;if(t&&!o)return 1;if(!a(t)&&a(o))return-1;if(a(t)&&!a(o))return 1;if(!c(t)&&c(o))return-1;if(c(t)&&!c(o))return 1;if(!s(t)&&s(o))return-1;if(s(t)&&!s(o))return 1}return 0}Object.defineProperty(exports,"__esModule",{value:!0}),exports.getLocalePrefix=function(e,t){var n;return"never"!==t.mode&&(null===(n=t.prefixes)||void 0===n?void 0:n[e])||"/"+e},exports.getSortedPathnames=function(e){return e.sort(f)},exports.hasPathnamePrefixed=i,exports.isLocalHref=t,exports.isLocalizableHref=n,exports.isRelativeHref=e,exports.localizeHref=function(e,t){let o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,u=arguments.length>3?arguments[3]:void 0,s=arguments.length>4?arguments[4]:void 0;if(!n(e))return e;const c=t!==o,a=i(s,u);return(c||a)&&null!=s?r(e,s):e},exports.matchesPathname=function(e,t){return u(e).test(t)},exports.prefixHref=r,exports.prefixPathname=o,exports.templateToRegex=u,exports.unprefixPathname=function(e,t){return e.replace(new RegExp("^".concat(t)),"")||"/"};
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { Locales, LocalePrefixConfigVerbose, DomainConfig, Pathnames } from '../routing/types';
|
|
2
2
|
export declare function getFirstPathnameSegment(pathname: string): string;
|
|
3
|
-
export declare function comparePathnamePairs(a: string, b: string): number;
|
|
4
|
-
export declare function getSortedPathnames(pathnames: Array<string>): string[];
|
|
5
3
|
export declare function getInternalTemplate<AppLocales extends Locales, AppPathnames extends Pathnames<AppLocales>>(pathnames: AppPathnames, pathname: string, locale: AppLocales[number]): [AppLocales[number] | undefined, keyof AppPathnames | undefined];
|
|
6
4
|
export declare function formatTemplatePathname(sourcePathname: string, sourceTemplate: string, targetTemplate: string, prefix?: string): string;
|
|
7
5
|
/**
|
|
@@ -43,10 +43,6 @@ export declare function compileLocalizedPathname<AppLocales extends Locales, Pat
|
|
|
43
43
|
pathnames: Pathnames<AppLocales>;
|
|
44
44
|
query?: Record<string, SearchParamValue>;
|
|
45
45
|
}): UrlObject;
|
|
46
|
-
export declare function getRoute<AppLocales extends Locales>(
|
|
47
|
-
locale: AppLocales[number];
|
|
48
|
-
pathname: string;
|
|
49
|
-
pathnames: Pathnames<AppLocales>;
|
|
50
|
-
}): string;
|
|
46
|
+
export declare function getRoute<AppLocales extends Locales>(locale: AppLocales[number], pathname: string, pathnames: Pathnames<AppLocales>): keyof Pathnames<AppLocales>;
|
|
51
47
|
export declare function getBasePath(pathname: string, windowPathname?: string): string;
|
|
52
48
|
export {};
|
|
@@ -21,4 +21,5 @@ template: string,
|
|
|
21
21
|
pathname: string): boolean;
|
|
22
22
|
export declare function getLocalePrefix<AppLocales extends Locales>(locale: AppLocales[number], localePrefix: LocalePrefixConfigVerbose<AppLocales>): string;
|
|
23
23
|
export declare function templateToRegex(template: string): RegExp;
|
|
24
|
+
export declare function getSortedPathnames(pathnames: Array<string>): string[];
|
|
24
25
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-intl",
|
|
3
|
-
"version": "3.15.3
|
|
3
|
+
"version": "3.15.3",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"author": "Jan Amann <jan@amann.work>",
|
|
6
6
|
"funding": [
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"dependencies": {
|
|
88
88
|
"@formatjs/intl-localematcher": "^0.2.32",
|
|
89
89
|
"negotiator": "^0.6.3",
|
|
90
|
-
"use-intl": "^3.15.3
|
|
90
|
+
"use-intl": "^3.15.3"
|
|
91
91
|
},
|
|
92
92
|
"peerDependencies": {
|
|
93
93
|
"next": "^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0",
|
|
@@ -104,11 +104,11 @@
|
|
|
104
104
|
},
|
|
105
105
|
{
|
|
106
106
|
"path": "dist/production/navigation.react-client.js",
|
|
107
|
-
"limit": "3.
|
|
107
|
+
"limit": "3.355 KB"
|
|
108
108
|
},
|
|
109
109
|
{
|
|
110
110
|
"path": "dist/production/navigation.react-server.js",
|
|
111
|
-
"limit": "17.
|
|
111
|
+
"limit": "17.975 KB"
|
|
112
112
|
},
|
|
113
113
|
{
|
|
114
114
|
"path": "dist/production/server.react-client.js",
|
|
@@ -127,5 +127,5 @@
|
|
|
127
127
|
"limit": "0 KB"
|
|
128
128
|
}
|
|
129
129
|
],
|
|
130
|
-
"gitHead": "
|
|
130
|
+
"gitHead": "5596ae873df9b558a564f7b73da64105da7fb2bb"
|
|
131
131
|
}
|