next
Version:
The React Framework
22 lines (21 loc) • 708 B
JavaScript
/**
* Removes the trailing slash for a given route or page path. Examples:
* - `/foo/bar/` -> `/foo/bar`
* - `/foo/bar` -> `/foo/bar`
*
* Uses charCodeAt (47 === '/') instead of regex to avoid the overhead of
* compiling and executing a RegExp on every call (~3-5x faster).
*/ "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "removeTrailingSlash", {
enumerable: true,
get: function() {
return removeTrailingSlash;
}
});
function removeTrailingSlash(route) {
return route.charCodeAt(route.length - 1) === 47 && route.length > 1 ? route.slice(0, -1) : route;
}
//# sourceMappingURL=remove-trailing-slash.js.map