Skip to content

Commit

Permalink
remove http or https protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
williambelle committed Feb 23, 2017
1 parent 13ab40b commit b473035
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ module.exports = function(url, length) {
return url;
}

// Remove http:// or https://
url = url.replace(/^https?:\/\//, '');

// Replace /foo/bar/foo/ with /…/…/…/
var urlLength = url.length;
while (urlLength > length) {
Expand Down
8 changes: 4 additions & 4 deletions test/test-crop-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ describe('cropUrl', function(){

it('should crop url', function(){
cropUrl('http://www.foobar.com/abc/def/ghi/index.html', 26).should.equal(
'http://www.foobar.com/…/index.html'
'www.foobar.com/…/index.html'
);
cropUrl('http://www.foobar.com/abc/def/ghi/jkl/', 26).should.equal(
'http://www.foobar.com/…/jkl/'
cropUrl('https://www.foobar.com/abc/def/ghi/jkl/', 26).should.equal(
'www.foobar.com/…/jkl/'
);
cropUrl('http://www.foobar.com/abc/def/ghi/jkl/', 1).should.equal(
'http://www.foobar.com/…/jkl/'
'www.foobar.com/…/jkl/'
);
});
});

0 comments on commit b473035

Please sign in to comment.