I have a little builder class that does url manipulation from a URL object, using the legacy node require('url') however now i am trying to migrate it to use the new WHATWG URL class.
In my builder class i had a method called removeProtocol() which does nothing more than removing the protocol so we can have convert to string urls like test.com/path/go/somewhere as opposed to https://test.com/path/go/somewhere
While the new class works much better than the legacy one. It does not accept the protocol to be an empty string, keeping it with previous value.
I tried things like:
delete this.url.protocol => this was ignored
delete this.url.__proto__.protocol => also results in the url being printed with the protocol.
removing the protocol from the href property also causes an error.
TypeError: Invalid URL: test.com/path/go/somewhere
Is there a way to do with this class. or does it mean I will have to convert the object to a string a remove it the protocol from the string?
URLinstance represents a resolved, absolute URL. See also github.com/whatwg/url/issues/421URLobjects are implemented as getters and setters on the class prototype, rather than as data properties on the object itself. Thus, unlike legacyurlObjects, using thedeletekeyword on any properties of URL objects (e.g.delete myURL.protocol,delete myURL.pathname, etc) has no effect but will still return true."