Repository: sindresorhus/normalize-url (js)

Issue:
Throwing error on given `view-source:` url string
```js
const normalize = require('normalize-url');
const n = normalize('view-source:https://github.com/sindresorhus/normalize-url/blob/master/index.js')
```
throws the error:
```
Thrown:
TypeError [ERR_INVALID_URL]: Invalid URL: http:view-source:https://github.com/sindresorhus/normalize-url/blob/master/index.js
    at onParseError (internal/url.js:243:9)
    at new URL (internal/url.js:319:5)
    at normalizeUrl
    [....]
 {
  input: 'http:view-source:https://github.com/sindresorhus/normalize-url/blob/master/index.js',
  code: 'ERR_INVALID_URL'
}
```
Is this intentionally an error? Seems unintentional to me because it first prepends `http` to the input, turning it into `'http:view-source:https://...` and then leaving it to the `URL` function to handle it, if I'm correct.

It would be awesome if we could have `view-source` urls handled by this module itself. Either define a normalisation result for `view-source` like how it's done for data urls, or return a clear error message.

Pull request description:
Throw a friendly error on `view-source:` input
Fixes #118 

Patch:
diff --git a/index.js b/index.js
index e370d25..a746086 100644
--- a/index.js
+++ b/index.js
@@ -83,6 +83,10 @@ const normalizeUrl = (urlString, options) => {
 		return normalizeDataURL(urlString, options);
 	}
 
+	if (/^view-source:/i.test(urlString)) {
+		throw new Error('`view-source:` is not supported as it is a non-standard protocol');
+	}
+
 	const hasRelativeProtocol = urlString.startsWith('//');
 	const isRelativeUrl = !hasRelativeProtocol && /^\.*\//.test(urlString);
 


Test patch:
diff --git a/test.js b/test.js
index df1b392..5f2e54b 100644
--- a/test.js
+++ b/test.js
@@ -314,3 +314,9 @@ test('prevents homograph attack', t => {
 	// The input string uses Unicode to make it look like a valid `ebay.com` URL.
 	t.is(normalizeUrl('https://ebаy.com'), 'https://xn--eby-7cd.com');
 });
+
+test('view-source URL', t => {
+	t.throws(() => {
+		normalizeUrl('view-source:https://www.sindresorhus.com');
+	}, '`view-source:` is not supported as it is a non-standard protocol');
+});