Commit ba30d1ab authored by Clément's avatar Clément

update: stripSlash with regexp

parent 14c2a38b
Pipeline #2645 passed with stage
in 27 seconds
......@@ -28,7 +28,7 @@ export default class SIBRouter extends HTMLElement {
if(url.startsWith(this.prefix)) {
url = url.slice(this.prefix.length);
}
return stripSlash(url);
return stripSlashes(url);
}
get currentRouteName() {
return this.currentURL.split('/')[0] || this.defaultRoute;
......@@ -78,12 +78,6 @@ export default class SIBRouter extends HTMLElement {
}
customElements.define('sib-router', SIBRouter);
function stripSlash(str) {
if(str.startsWith('/')) {
str = str.slice(1);
}
if(str.endsWith('/')) {
str = str.slice(0, str.length - 1);
}
return str;
function stripSlashes(str) {
return str.replace(/^\/+|\/+$/g, '');
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment