normalize-trailing-slash.js 1.4 KB

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.normalizePathTrailingSlash = void 0;
  6. var _removeTrailingSlash = require("../shared/lib/router/utils/remove-trailing-slash");
  7. var _parsePath = require("../shared/lib/router/utils/parse-path");
  8. const normalizePathTrailingSlash = (path)=>{
  9. if (!path.startsWith('/') || process.env.__NEXT_MANUAL_TRAILING_SLASH) {
  10. return path;
  11. }
  12. const { pathname , query , hash } = (0, _parsePath).parsePath(path);
  13. if (process.env.__NEXT_TRAILING_SLASH) {
  14. if (/\.[^/]+\/?$/.test(pathname)) {
  15. return `${(0, _removeTrailingSlash).removeTrailingSlash(pathname)}${query}${hash}`;
  16. } else if (pathname.endsWith('/')) {
  17. return `${pathname}${query}${hash}`;
  18. } else {
  19. return `${pathname}/${query}${hash}`;
  20. }
  21. }
  22. return `${(0, _removeTrailingSlash).removeTrailingSlash(pathname)}${query}${hash}`;
  23. };
  24. exports.normalizePathTrailingSlash = normalizePathTrailingSlash;
  25. if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
  26. Object.defineProperty(exports.default, '__esModule', { value: true });
  27. Object.assign(exports.default, exports);
  28. module.exports = exports.default;
  29. }
  30. //# sourceMappingURL=normalize-trailing-slash.js.map