Skip to content

Commit

Permalink
Load URL from where it is appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
Marios Antonoudiou committed May 30, 2018
1 parent dedaf59 commit f47d676
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* eslint-env node, browser */

'use strict';
const {URL: UrlParser} = require('url');
const {URL} = typeof window === 'undefined' ? require('url') : window;

function testParameter(name, filters) {
return filters.some(filter => filter instanceof RegExp ? filter.test(name) : filter === name);
Expand Down Expand Up @@ -27,7 +29,7 @@ module.exports = (urlString, opts) => {
urlString = urlString.replace(/^(?!(?:\w+:)?\/\/)|^\/\//, 'http://');
}

const urlObj = new UrlParser(urlString);
const urlObj = new URL(urlString);

if (opts.normalizeHttps && urlObj.protocol === 'https:') {
urlObj.protocol = 'http:';
Expand Down

0 comments on commit f47d676

Please sign in to comment.