silverwolf-x/project / packages /next /src /shared /lib /router /utils /remove-trailing-slash.ts
silverwolf-x's picture
download
raw
451 Bytes
/**
* 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).
*/
export function removeTrailingSlash(route: string) {
return route.charCodeAt(route.length - 1) === 47 && route.length > 1
? route.slice(0, -1)
: route
}

Xet Storage Details

Size:
451 Bytes
·
Xet hash:
a285a4cfd79bcb0762f869f11dd1ebba4e79263053facd2257dded39cdf5a060

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.