diff options
author | bobzel <zzzman@gmail.com> | 2024-05-14 23:15:24 -0400 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2024-05-14 23:15:24 -0400 |
commit | 3534aaf88a3c30a474b3b5a5b7f04adfe6f15fac (patch) | |
tree | 47fb7a8671b209bd4d76e0f755a5b035c6936607 /src/fields/URLField.ts | |
parent | 87bca251d87b5a95da06b2212400ce9427152193 (diff) | |
parent | 5cb7ad90e120123ca572e8ef5b1aa6ca41581134 (diff) |
Merge branch 'restoringEslint' into sarah-ai-visualization
Diffstat (limited to 'src/fields/URLField.ts')
-rw-r--r-- | src/fields/URLField.ts | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/src/fields/URLField.ts b/src/fields/URLField.ts index 87334ad16..3a83e7ca0 100644 --- a/src/fields/URLField.ts +++ b/src/fields/URLField.ts @@ -1,18 +1,14 @@ +import { custom, serializable } from 'serializr'; +import { ClientUtils } from '../ClientUtils'; +import { scriptingGlobal } from '../client/util/ScriptingGlobals'; import { Deserializable } from '../client/util/SerializationHelper'; -import { serializable, custom } from 'serializr'; +import { Copy, ToJavascriptString, ToScriptString, ToString } from './FieldSymbols'; import { ObjectField } from './ObjectField'; -import { ToScriptString, ToString, Copy, ToJavascriptString } from './FieldSymbols'; -import { scriptingGlobal } from '../client/util/ScriptingGlobals'; -import { Utils } from '../Utils'; function url() { return custom( - function (value: URL) { - return value?.origin === window.location.origin ? value.pathname : value?.href; - }, - function (jsonValue: string) { - return new URL(jsonValue, window.location.origin); - } + (value: URL) => (value?.origin === window.location.origin ? value.pathname : value?.href), + (jsonValue: string) => new URL(jsonValue, window.location.origin) ); } @@ -20,30 +16,34 @@ export abstract class URLField extends ObjectField { @serializable(url()) readonly url: URL; - constructor(url: string); - constructor(url: URL); - constructor(url: URL | string) { + constructor(urlVal: string); + // eslint-disable-next-line @typescript-eslint/no-shadow + constructor(urlVal: URL); + // eslint-disable-next-line @typescript-eslint/no-shadow + constructor(urlVal: URL | string) { super(); - if (typeof url === 'string') { - url = url.startsWith('http') ? new URL(url) : new URL(url, window.location.origin); - } - this.url = url; + this.url = + typeof urlVal !== 'string' + ? urlVal // it's an URL + : urlVal.startsWith('http') + ? new URL(urlVal) + : new URL(urlVal, window.location.origin); } [ToScriptString]() { - if (Utils.prepend(this.url?.pathname) === this.url?.href) { + if (ClientUtils.prepend(this.url?.pathname) === this.url?.href) { return `new ${this.constructor.name}("${this.url.pathname}")`; } return `new ${this.constructor.name}("${this.url?.href}")`; } [ToJavascriptString]() { - if (Utils.prepend(this.url?.pathname) === this.url?.href) { + if (ClientUtils.prepend(this.url?.pathname) === this.url?.href) { return `new ${this.constructor.name}("${this.url.pathname}")`; } return `new ${this.constructor.name}("${this.url?.href}")`; } [ToString]() { - if (Utils.prepend(this.url?.pathname) === this.url?.href) { + if (ClientUtils.prepend(this.url?.pathname) === this.url?.href) { return this.url.pathname; } return this.url?.href; |