normalize-locale-path.js 759 B

12345678910111213141516171819202122232425
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.normalizeLocalePath = normalizeLocalePath;
  6. function normalizeLocalePath(pathname, locales) {
  7. let detectedLocale;
  8. // first item will be empty string from splitting at first char
  9. const pathnameParts = pathname.split('/');
  10. (locales || []).some((locale)=>{
  11. if (pathnameParts[1] && pathnameParts[1].toLowerCase() === locale.toLowerCase()) {
  12. detectedLocale = locale;
  13. pathnameParts.splice(1, 1);
  14. pathname = pathnameParts.join('/') || '/';
  15. return true;
  16. }
  17. return false;
  18. });
  19. return {
  20. pathname,
  21. detectedLocale
  22. };
  23. }
  24. //# sourceMappingURL=normalize-locale-path.js.map