We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent bdda512 commit 857f645Copy full SHA for 857f645
index.js
@@ -1,13 +1,17 @@
1
'use strict'
2
3
-var url = require('url')
+const { URL } = require('url')
4
5
-module.exports = function (str) {
6
- if (typeof str !== 'string') {
7
- throw new TypeError('Expected a string, not ' + typeof str)
+module.exports = str => {
+ if (typeof str !== 'string' || !str) {
+ return false
8
}
9
10
- var urlObj = url.parse(str)
+ try {
11
+ const { href, protocol } = new URL(str)
12
- return Boolean(urlObj.protocol) && Boolean(urlObj.slashes) === false
13
+ return href.indexOf(`${protocol}//`) !== 0
14
+ } catch (e) {
15
16
+ }
17
0 commit comments