Skip to content

Commit 857f645

Browse files
committed
Rewrite using new WHATWG URL API
1 parent bdda512 commit 857f645

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

index.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
'use strict'
22

3-
var url = require('url')
3+
const { URL } = require('url')
44

5-
module.exports = function (str) {
6-
if (typeof str !== 'string') {
7-
throw new TypeError('Expected a string, not ' + typeof str)
5+
module.exports = str => {
6+
if (typeof str !== 'string' || !str) {
7+
return false
88
}
99

10-
var urlObj = url.parse(str)
10+
try {
11+
const { href, protocol } = new URL(str)
1112

12-
return Boolean(urlObj.protocol) && Boolean(urlObj.slashes) === false
13+
return href.indexOf(`${protocol}//`) !== 0
14+
} catch (e) {
15+
return false
16+
}
1317
}

0 commit comments

Comments
 (0)