UNPKG

@speckle/shared

Version:

Shared code between various Speckle JS packages

48 lines 1.37 kB
/** * Similar to URL, except without the requirement of having a valid origin/baseUrl */ export class RelativeURL extends URL { static #fakeOrigin = 'http://fakeorigin.com'; constructor(url) { super(url, RelativeURL.#fakeOrigin); } get host() { throw new Error('host is not supported in a relative URL'); } get hostname() { throw new Error('hostname is not supported in a relative URL'); } get href() { return this.pathname + this.search + this.hash; } get origin() { throw new Error('origin is not supported in a relative URL'); } get password() { throw new Error('password is not supported in a relative URL'); } get protocol() { throw new Error('protocol is not supported in a relative URL'); } get port() { throw new Error('port is not supported in a relative URL'); } get username() { throw new Error('username is not supported in a relative URL'); } toJSON() { return this.href; } toString() { return this.href; } static canParse(url) { return URL.canParse(url, RelativeURL.#fakeOrigin); } static parse(url) { if (!RelativeURL.canParse(url)) return null; return new RelativeURL(url.toString()); } } //# sourceMappingURL=url.js.map