Skip to content

Commit

Permalink
refactor: use url.from() as Node.js 8 is dropped
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Apr 21, 2020
1 parent c102bba commit d9f8054
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
6 changes: 2 additions & 4 deletions lib/decode_url.js
@@ -1,7 +1,6 @@
'use strict';

const { parse } = 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 } = 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
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -50,7 +50,6 @@
"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"
},
Expand Down

0 comments on commit d9f8054

Please sign in to comment.