next-intl 3.17.2 → 3.17.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.
@@ -50,13 +50,21 @@ function compileLocalizedPathname(_ref) {
50
50
  if (params) {
51
51
  Object.entries(params).forEach(_ref2 => {
52
52
  let [key, value] = _ref2;
53
+ let regexp, replacer;
53
54
  if (Array.isArray(value)) {
54
- compiled = compiled.replace(new RegExp("(\\[)?\\[...".concat(key, "\\](\\])?"), 'g'), value.map(v => String(v)).join('/'));
55
+ regexp = "(\\[)?\\[...".concat(key, "\\](\\])?");
56
+ replacer = value.map(v => String(v)).join('/');
55
57
  } else {
56
- compiled = compiled.replace("[".concat(key, "]"), String(value));
58
+ regexp = "\\[".concat(key, "\\]");
59
+ replacer = String(value);
57
60
  }
61
+ compiled = compiled.replace(new RegExp(regexp, 'g'), replacer);
58
62
  });
59
63
  }
64
+
65
+ // Clean up optional catch-all segments that were not replaced
66
+ compiled = compiled.replace(/\[\[\.\.\..+\]\]/g, '');
67
+ compiled = utils.normalizeTrailingSlash(compiled);
60
68
  if (compiled.includes('[')) {
61
69
  // Next.js throws anyway, therefore better provide a more helpful error message
62
70
  throw new Error("Insufficient params provided for localized pathname.\nTemplate: ".concat(template, "\nParams: ").concat(JSON.stringify(params)));
@@ -1 +1 @@
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};
1
+ import{getSortedPathnames as t,matchesPathname as n,normalizeTrailingSlash as r}from"../../shared/utils.js";function e(t){return"string"==typeof t?{pathname:t}:t}function o(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 a(t){let{pathname:n,locale:e,params:a,pathnames:c,query:i}=t;function s(t){let n=c[t];return n||(n=t),n}function f(t){const n="string"==typeof t?t:t[e];let c=n;if(a&&Object.entries(a).forEach((t=>{let n,r,[e,o]=t;Array.isArray(o)?(n="(\\[)?\\[...".concat(e,"\\](\\])?"),r=o.map((t=>String(t))).join("/")):(n="\\[".concat(e,"\\]"),r=String(o)),c=c.replace(new RegExp(n,"g"),r)})),c=c.replace(/\[\[\.\.\..+\]\]/g,""),c=r(c),c.includes("["))throw new Error("Insufficient params provided for localized pathname.\nTemplate: ".concat(n,"\nParams: ").concat(JSON.stringify(a)));return i&&(c+=o(i)),c}if("string"==typeof n){return f(s(n))}{const{pathname:t,...r}=n;return{...r,pathname:f(s(t))}}}function c(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 i(t){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:window.location.pathname;return"/"===t?n:n.replace(t,"")}export{a as compileLocalizedPathname,i as getBasePath,c as getRoute,e as normalizeNameOrNameWithParams,o as serializeSearchParams};
@@ -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: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
+ "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(r){let{pathname:n,locale:a,params:o,pathnames:i,query:s}=r;function c(e){let t=i[e];return t||(t=e),t}function p(r){let n="string"==typeof r?r:r[a];return o&&Object.entries(o).forEach((e=>{let t,r,[a,o]=e;Array.isArray(o)?(t="(\\[)?\\[...".concat(a,"\\](\\])?"),r=o.map((e=>String(e))).join("/")):(t="\\[".concat(a,"\\]"),r=String(o)),n=n.replace(new RegExp(t,"g"),r)})),n=n.replace(/\[\[\.\.\..+\]\]/g,""),n=e.normalizeTrailingSlash(n),s&&(n+=t(s)),n}if("string"==typeof n){return p(c(n))}{const{pathname:e,...t}=n;return{...t,pathname:p(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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-intl",
3
- "version": "3.17.2",
3
+ "version": "3.17.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.17.2"
90
+ "use-intl": "^3.17.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.475 KB"
107
+ "limit": "3.55 KB"
108
108
  },
109
109
  {
110
110
  "path": "dist/production/navigation.react-server.js",
111
- "limit": "18.325 KB"
111
+ "limit": "18.355 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": "b2117e10bab62c4b26cbd712551816a22a71e63f"
130
+ "gitHead": "ed4681fa70b8f67a97e1364deaabf58df302d80c"
131
131
  }