diff --git a/lib/decode_url.js b/lib/decode_url.js index dcb57948..5793352a 100644 --- a/lib/decode_url.js +++ b/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 { @@ -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); } diff --git a/lib/encode_url.js b/lib/encode_url.js index caa3711f..3579e140 100644 --- a/lib/encode_url.js +++ b/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 { @@ -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)); diff --git a/package.json b/package.json index c7bcc77c..3bb63385 100644 --- a/package.json +++ b/package.json @@ -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" },