next-intl 3.11.3 → 3.12.0
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.
|
@@ -7,9 +7,58 @@ var utils = require('../shared/utils.js');
|
|
|
7
7
|
function getFirstPathnameSegment(pathname) {
|
|
8
8
|
return pathname.split('/')[1];
|
|
9
9
|
}
|
|
10
|
+
function isOptionalCatchAllSegment(pathname) {
|
|
11
|
+
return pathname.includes('[[...');
|
|
12
|
+
}
|
|
13
|
+
function isCatchAllSegment(pathname) {
|
|
14
|
+
return pathname.includes('[...');
|
|
15
|
+
}
|
|
16
|
+
function isDynamicSegment(pathname) {
|
|
17
|
+
return pathname.includes('[');
|
|
18
|
+
}
|
|
19
|
+
function comparePathnamePairs(a, b) {
|
|
20
|
+
const pathA = a.split('/');
|
|
21
|
+
const pathB = b.split('/');
|
|
22
|
+
const maxLength = Math.max(pathA.length, pathB.length);
|
|
23
|
+
for (let i = 0; i < maxLength; i++) {
|
|
24
|
+
const segmentA = pathA[i];
|
|
25
|
+
const segmentB = pathB[i];
|
|
26
|
+
|
|
27
|
+
// If one of the paths ends, prioritize the shorter path
|
|
28
|
+
if (!segmentA && segmentB) return -1;
|
|
29
|
+
if (segmentA && !segmentB) return 1;
|
|
30
|
+
|
|
31
|
+
// Prioritize static segments over dynamic segments
|
|
32
|
+
if (!isDynamicSegment(segmentA) && isDynamicSegment(segmentB)) return -1;
|
|
33
|
+
if (isDynamicSegment(segmentA) && !isDynamicSegment(segmentB)) return 1;
|
|
34
|
+
|
|
35
|
+
// Prioritize non-catch-all segments over catch-all segments
|
|
36
|
+
if (!isCatchAllSegment(segmentA) && isCatchAllSegment(segmentB)) return -1;
|
|
37
|
+
if (isCatchAllSegment(segmentA) && !isCatchAllSegment(segmentB)) return 1;
|
|
38
|
+
|
|
39
|
+
// Prioritize non-optional catch-all segments over optional catch-all segments
|
|
40
|
+
if (!isOptionalCatchAllSegment(segmentA) && isOptionalCatchAllSegment(segmentB)) {
|
|
41
|
+
return -1;
|
|
42
|
+
}
|
|
43
|
+
if (isOptionalCatchAllSegment(segmentA) && !isOptionalCatchAllSegment(segmentB)) {
|
|
44
|
+
return 1;
|
|
45
|
+
}
|
|
46
|
+
if (segmentA === segmentB) continue;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Both pathnames are completely static
|
|
50
|
+
return 0;
|
|
51
|
+
}
|
|
52
|
+
function getSortedPathnames(pathnames) {
|
|
53
|
+
const sortedPathnames = pathnames.sort(comparePathnamePairs);
|
|
54
|
+
return sortedPathnames;
|
|
55
|
+
}
|
|
10
56
|
function getInternalTemplate(pathnames, pathname, locale) {
|
|
57
|
+
const sortedPathnames = getSortedPathnames(Object.keys(pathnames));
|
|
58
|
+
|
|
11
59
|
// Try to find a localized pathname that matches
|
|
12
|
-
for (const
|
|
60
|
+
for (const internalPathname of sortedPathnames) {
|
|
61
|
+
const localizedPathnamesOrPathname = pathnames[internalPathname];
|
|
13
62
|
if (typeof localizedPathnamesOrPathname === 'string') {
|
|
14
63
|
const localizedPathname = localizedPathnamesOrPathname;
|
|
15
64
|
if (utils.matchesPathname(localizedPathname, pathname)) {
|
|
@@ -159,6 +208,7 @@ function normalizeTrailingSlash(pathname) {
|
|
|
159
208
|
}
|
|
160
209
|
|
|
161
210
|
exports.applyBasePath = applyBasePath;
|
|
211
|
+
exports.comparePathnamePairs = comparePathnamePairs;
|
|
162
212
|
exports.findCaseInsensitiveLocale = findCaseInsensitiveLocale;
|
|
163
213
|
exports.formatPathname = formatPathname;
|
|
164
214
|
exports.formatTemplatePathname = formatTemplatePathname;
|
|
@@ -170,4 +220,5 @@ exports.getNormalizedPathname = getNormalizedPathname;
|
|
|
170
220
|
exports.getPathWithSearch = getPathWithSearch;
|
|
171
221
|
exports.getPathnameLocale = getPathnameLocale;
|
|
172
222
|
exports.getRouteParams = getRouteParams;
|
|
223
|
+
exports.getSortedPathnames = getSortedPathnames;
|
|
173
224
|
exports.isLocaleSupportedOnDomain = isLocaleSupportedOnDomain;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{matchesPathname as n,templateToRegex as t}from"../shared/utils.js";function e(n){return n.split("/")[1]}function o(t,e,
|
|
1
|
+
import{matchesPathname as n,templateToRegex as t}from"../shared/utils.js";function e(n){return n.split("/")[1]}function r(n){return n.includes("[[...")}function o(n){return n.includes("[...")}function i(n){return n.includes("[")}function u(n,t){const e=n.split("/"),u=t.split("/"),c=Math.max(e.length,u.length);for(let n=0;n<c;n++){const t=e[n],c=u[n];if(!t&&c)return-1;if(t&&!c)return 1;if(!i(t)&&i(c))return-1;if(i(t)&&!i(c))return 1;if(!o(t)&&o(c))return-1;if(o(t)&&!o(c))return 1;if(!r(t)&&r(c))return-1;if(r(t)&&!r(c))return 1}return 0}function c(n){return n.sort(u)}function l(t,e,r){const o=c(Object.keys(t));for(const i of o){const o=t[i];if("string"==typeof o){if(n(o,e))return[void 0,i]}else{const t=Object.entries(o),u=t.findIndex((n=>{let[t]=n;return t===r}));u>0&&t.unshift(t.splice(u,1)[0]);for(const[r,o]of t)if(n(o,e))return[r,i]}}for(const r of Object.keys(t))if(n(r,e))return[void 0,r];return[void 0,void 0]}function f(n,t,e,r){const o=h(t,n);let i="";return r&&(i="/".concat(r)),i+=v(e,o),i=b(i),i}function s(n,t){n.endsWith("/")||(n+="/");const e=n.match(new RegExp("^/(".concat(t.join("|"),")/(.*)"),"i"));let r=e?"/"+e[2]:n;return"/"!==r&&(r=b(r)),r}function d(n,t){return t.find((t=>t.toLowerCase()===n.toLowerCase()))}function a(n,t){const r=e(n);return d(r,t)?r:void 0}function h(n,e){const r=t(n).exec(e);if(!r)return;const o={};for(let t=1;t<r.length;t++){var i;const e=null===(i=n.match(/\[([^\]]+)\]/g))||void 0===i?void 0:i[t-1].replace(/[[\]]/g,"");e&&(o[e]=r[t])}return o}function v(n,t){if(!t)return n;let e=n=n.replace(/\[\[/g,"[").replace(/\]\]/g,"]");return Object.entries(t).forEach((n=>{let[t,r]=n;e=e.replace("[".concat(t,"]"),r)})),e}function p(n,t){let e=n;return t&&(e+=t),e}function g(n){var t,e;return null!==(t=null!==(e=n.get("x-forwarded-host"))&&void 0!==e?e:n.get("host"))&&void 0!==t?t:void 0}function j(n,t){return t.defaultLocale===n||!t.locales||t.locales.includes(n)}function x(n,t,e){let r;return n&&j(t,n)&&(r=n),r||(r=e.find((n=>n.defaultLocale===t))),r||(r=e.find((n=>null!=n.locales&&n.locales.includes(t)))),r||null!=(null==n?void 0:n.locales)||(r=n),r||(r=e.find((n=>!n.locales))),r}function m(n,t){return b(t+n)}function b(n){return n.endsWith("/")&&(n=n.slice(0,-1)),n}export{m as applyBasePath,u as comparePathnamePairs,d as findCaseInsensitiveLocale,v as formatPathname,f as formatTemplatePathname,x as getBestMatchingDomain,e as getFirstPathnameSegment,g as getHost,l as getInternalTemplate,s as getNormalizedPathname,p as getPathWithSearch,a as getPathnameLocale,h as getRouteParams,c as getSortedPathnames,j as isLocaleSupportedOnDomain};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../shared/utils.js");function t(e){return e.split("/")[1]}function n(e,t){return t.find((t=>t.toLowerCase()===e.toLowerCase()))}function
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../shared/utils.js");function t(e){return e.split("/")[1]}function n(e){return e.includes("[[...")}function r(e){return e.includes("[...")}function o(e){return e.includes("[")}function i(e,t){const i=e.split("/"),s=t.split("/"),c=Math.max(i.length,s.length);for(let e=0;e<c;e++){const t=i[e],c=s[e];if(!t&&c)return-1;if(t&&!c)return 1;if(!o(t)&&o(c))return-1;if(o(t)&&!o(c))return 1;if(!r(t)&&r(c))return-1;if(r(t)&&!r(c))return 1;if(!n(t)&&n(c))return-1;if(n(t)&&!n(c))return 1}return 0}function s(e){return e.sort(i)}function c(e,t){return t.find((t=>t.toLowerCase()===e.toLowerCase()))}function a(t,n){const r=e.templateToRegex(t).exec(n);if(!r)return;const o={};for(let e=1;e<r.length;e++){var i;const n=null===(i=t.match(/\[([^\]]+)\]/g))||void 0===i?void 0:i[e-1].replace(/[[\]]/g,"");n&&(o[n]=r[e])}return o}function u(e,t){if(!t)return e;let n=e=e.replace(/\[\[/g,"[").replace(/\]\]/g,"]");return Object.entries(t).forEach((e=>{let[t,r]=e;n=n.replace("[".concat(t,"]"),r)})),n}function l(e,t){return t.defaultLocale===e||!t.locales||t.locales.includes(e)}function f(e){return e.endsWith("/")&&(e=e.slice(0,-1)),e}exports.applyBasePath=function(e,t){return f(t+e)},exports.comparePathnamePairs=i,exports.findCaseInsensitiveLocale=c,exports.formatPathname=u,exports.formatTemplatePathname=function(e,t,n,r){const o=a(t,e);let i="";return r&&(i="/".concat(r)),i+=u(n,o),i=f(i),i},exports.getBestMatchingDomain=function(e,t,n){let r;return e&&l(t,e)&&(r=e),r||(r=n.find((e=>e.defaultLocale===t))),r||(r=n.find((e=>null!=e.locales&&e.locales.includes(t)))),r||null!=(null==e?void 0:e.locales)||(r=e),r||(r=n.find((e=>!e.locales))),r},exports.getFirstPathnameSegment=t,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,r){const o=s(Object.keys(t));for(const i of o){const o=t[i];if("string"==typeof o){const t=o;if(e.matchesPathname(t,n))return[void 0,i]}else{const t=Object.entries(o),s=t.findIndex((e=>{let[t]=e;return t===r}));s>0&&t.unshift(t.splice(s,1)[0]);for(const[r,o]of t)if(e.matchesPathname(o,n))return[r,i]}}for(const r of Object.keys(t))if(e.matchesPathname(r,n))return[void 0,r];return[void 0,void 0]},exports.getNormalizedPathname=function(e,t){e.endsWith("/")||(e+="/");const n=e.match(new RegExp("^/(".concat(t.join("|"),")/(.*)"),"i"));let r=n?"/"+n[2]:e;return"/"!==r&&(r=f(r)),r},exports.getPathWithSearch=function(e,t){let n=e;return t&&(n+=t),n},exports.getPathnameLocale=function(e,n){const r=t(e);return c(r,n)?r:void 0},exports.getRouteParams=a,exports.getSortedPathnames=s,exports.isLocaleSupportedOnDomain=l;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { AllLocales } from '../shared/types';
|
|
2
2
|
import { DomainConfig, MiddlewareConfigWithDefaults } from './NextIntlMiddlewareConfig';
|
|
3
3
|
export declare function getFirstPathnameSegment(pathname: string): string;
|
|
4
|
+
export declare function comparePathnamePairs(a: string, b: string): number;
|
|
5
|
+
export declare function getSortedPathnames(pathnames: Array<string>): string[];
|
|
4
6
|
export declare function getInternalTemplate<Locales extends AllLocales, Pathnames extends NonNullable<MiddlewareConfigWithDefaults<Locales>['pathnames']>>(pathnames: Pathnames, pathname: string, locale: Locales[number]): [Locales[number] | undefined, keyof Pathnames | undefined];
|
|
5
7
|
export declare function formatTemplatePathname(sourcePathname: string, sourceTemplate: string, targetTemplate: string, localePrefix?: string): string;
|
|
6
8
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-intl",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.12.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"author": "Jan Amann <jan@amann.work>",
|
|
6
6
|
"funding": [
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"dependencies": {
|
|
83
83
|
"@formatjs/intl-localematcher": "^0.2.32",
|
|
84
84
|
"negotiator": "^0.6.3",
|
|
85
|
-
"use-intl": "^3.
|
|
85
|
+
"use-intl": "^3.12.0"
|
|
86
86
|
},
|
|
87
87
|
"peerDependencies": {
|
|
88
88
|
"next": "^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0",
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
"eslint": "^8.54.0",
|
|
101
101
|
"eslint-config-molindo": "^7.0.0",
|
|
102
102
|
"eslint-plugin-deprecation": "^1.4.1",
|
|
103
|
-
"next": "^14.1
|
|
103
|
+
"next": "^14.2.1",
|
|
104
104
|
"path-to-regexp": "^6.2.1",
|
|
105
105
|
"publint": "^0.2.7",
|
|
106
106
|
"react": "^18.2.0",
|
|
@@ -138,8 +138,8 @@
|
|
|
138
138
|
},
|
|
139
139
|
{
|
|
140
140
|
"path": "dist/production/middleware.js",
|
|
141
|
-
"limit": "6 KB"
|
|
141
|
+
"limit": "6.19 KB"
|
|
142
142
|
}
|
|
143
143
|
],
|
|
144
|
-
"gitHead": "
|
|
144
|
+
"gitHead": "0bb5827ae29f3644100d1685ce9b10beeeb4acd5"
|
|
145
145
|
}
|