I am getting warnings in VS Code that url.format from the NodeJS URL module is deprecated.
const nodeUrl = require('url')
const url = nodeUrl.format({
protocol: 'https',
host: 'example.com',
pathname: 'somepath'
})
What shall I use instead? Is it fully safe to just replace the above by
const buildUrl = (url) => url.protocol + '://' + url.host + '/' + url.pathname
Are these two functions equivalent, that is, for any object input with that structure, it results in the same output? Doesn't url.format have any magic that I may miss? For example pathname with or without leading /.
My project is huge with a lot of calls to url.format and I want to be sure that nothing breaks.
edit: Apparently we should use WHATWG URL standard
Is then this the correct replacement?
const buildUrl = (url) => new URL(url.pathname, url.protocol + '://' + url.host)

URLnot a vanilla object.WHATWG URL API?url.format(urlObject)using the WHATWG API? Justnew URL(urlObject.pathname, urlObject.protocol + '://' + urlObject.host)?