Skip to content

Commit

Permalink
replace endsWith with regex match
Browse files Browse the repository at this point in the history
  • Loading branch information
Wilson Lemos authored and Wilson Lemos committed Apr 20, 2022
1 parent 7a8fdc8 commit 63c6b49
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
2 changes: 1 addition & 1 deletion index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export shouldOpenInNewWindow = (url) ->
# add trailing slash
export addTrailingSlash = (to) ->
url = new URL to
url.pathname += if url.pathname.endsWith "/" then "" else "/"
url.pathname += if url.pathname.match(/\/$/) then "" else "/"
url.toString()

# Directive definition with settings method for overriding the default settings.
Expand Down
4 changes: 1 addition & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,11 @@ var shouldOpenInNewWindow = exports.shouldOpenInNewWindow = function shouldOpenI
var addTrailingSlash = exports.addTrailingSlash = function addTrailingSlash(to) {
var url;
url = new _urlParse2.default(to);
url.pathname += url.pathname.endsWith("/") ? "" : "/";
url.pathname += url.pathname.match(/\/$/) ? "" : "/";
return url.toString();
};

exports.default = {
// if to.match /\/$/ then to else to + '/'

// Directive definition with settings method for overriding the default settings.
// I'm relying on Browser garbage collection to cleanup listeners.
bind: bind,
Expand Down

0 comments on commit 63c6b49

Please sign in to comment.