Skip to content

Commit

Permalink
refactor: utilize url#from
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Apr 25, 2020
1 parent 48788a7 commit 6780cb4
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 13 deletions.
6 changes: 2 additions & 4 deletions lib/decode_url.js
@@ -1,7 +1,6 @@
'use strict';

const { parse, URL } = require('url');
const { toUnicode } = require('punycode.js');
const { parse, format } = require('url');

const safeDecodeURI = str => {
try {
Expand All @@ -18,8 +17,7 @@ const decodeURL = str => {
// Exit if input is a data url
if (parsed.origin === 'null') return str;

// TODO: refactor to `url.format()` once Node 8 is dropped
const url = parsed.toString().replace(parsed.hostname, toUnicode(parsed.hostname));
const url = format(parsed, { unicode: true });
return safeDecodeURI(url);
}

Expand Down
6 changes: 2 additions & 4 deletions lib/encode_url.js
@@ -1,7 +1,6 @@
'use strict';

const { toUnicode } = require('punycode.js');
const { parse, URL } = require('url');
const { parse, format } = require('url');

const safeDecodeURI = str => {
try {
Expand All @@ -20,8 +19,7 @@ const encodeURL = str => {

parsed.search = encodeURI(safeDecodeURI(parsed.search));
// preserve IDN
// TODO: refactor to url.format() once Node 8 EOL
return parsed.toString().replace(parsed.hostname, toUnicode(parsed.hostname));
return format(parsed, { unicode: true });
}

return encodeURI(safeDecodeURI(str));
Expand Down
2 changes: 1 addition & 1 deletion lib/full_url_for.js
@@ -1,6 +1,6 @@
'use strict';

const { parse, URL } = require('url');
const { parse } = require('url');
const encodeURL = require('./encode_url');
const prettyUrls = require('./pretty_urls');

Expand Down
2 changes: 1 addition & 1 deletion lib/is_external_link.js
@@ -1,6 +1,6 @@
'use strict';

const { parse, URL } = require('url');
const { parse } = require('url');

const Cache = require('./cache');
const cache = new Cache();
Expand Down
2 changes: 1 addition & 1 deletion lib/url_for.js
@@ -1,6 +1,6 @@
'use strict';

const { parse, URL } = require('url');
const { parse } = require('url');
const encodeURL = require('./encode_url');
const relative_url = require('./relative_url');
const prettyUrls = require('./pretty_urls');
Expand Down
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -50,11 +50,10 @@
"highlight.js": "^9.13.1",
"htmlparser2": "^4.0.0",
"prismjs": "^1.17.1",
"punycode.js": "^2.1.0",
"strip-indent": "^3.0.0",
"striptags": "^3.1.1"
},
"engines": {
"node": ">=8.6.0"
"node": ">=10.18.1"
}
}

0 comments on commit 6780cb4

Please sign in to comment.