UNPKG

@speckle/shared

Version:

Shared code between various Speckle JS packages

52 lines 1.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RelativeURL = void 0; /** * Similar to URL, except without the requirement of having a valid origin/baseUrl */ 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()); } } exports.RelativeURL = RelativeURL; //# sourceMappingURL=url.js.map