Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Added unit tests; Co-authored-by: Jay <jasonsaayman@gmail.com>
- Loading branch information
1 parent
76432c1
commit b9e9fb4
Showing
3 changed files
with
32 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use strict'; | ||
|
||
module.exports = function parseProtocol(url) { | ||
var match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url); | ||
return match && match[1] || ''; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
var assert = require('assert'); | ||
var utils = require('../../../lib/utils'); | ||
var parseProtocol = require('../../../lib/helpers/parseProtocol'); | ||
|
||
describe('helpers::parseProtocol', function () { | ||
it('should parse protocol part if it exists', function () { | ||
utils.forEach({ | ||
'http://username:password@example.com/': 'http', | ||
'ftp:google.com': 'ftp', | ||
'sms:+15105550101?body=hello%20there': 'sms', | ||
'tel:0123456789' : 'tel', | ||
'//google.com': '', | ||
'google.com': '', | ||
'admin://etc/default/grub' : 'admin', | ||
'stratum+tcp://server:port': 'stratum+tcp', | ||
'/api/resource:customVerb': '', | ||
'https://stackoverflow.com/questions/': 'https', | ||
'mailto:jsmith@example.com' : 'mailto', | ||
'chrome-extension://1234/<pageName>.html' : 'chrome-extension' | ||
}, (expectedProtocol, url) => { | ||
assert.strictEqual(parseProtocol(url), expectedProtocol); | ||
}); | ||
}); | ||
}); |