Chore: formatting

This commit is contained in:
Pieter Vander Vennet 2023-09-16 18:52:42 +02:00
parent 8249f565e5
commit 42c7bbe1c9
234 changed files with 5815 additions and 2596 deletions

View file

@ -18,7 +18,7 @@ import ColorValidator from "./Validators/ColorValidator"
import BaseUIElement from "../BaseUIElement"
import Combine from "../Base/Combine"
import Title from "../Base/Title"
import FediverseValidator from "./Validators/FediverseValidator";
import FediverseValidator from "./Validators/FediverseValidator"
export type ValidatorType = (typeof Validators.availableTypes)[number]
@ -40,7 +40,7 @@ export default class Validators {
"phone",
"opening_hours",
"color",
"fediverse"
"fediverse",
] as const
public static readonly AllValidators: ReadonlyArray<Validator> = [
@ -60,7 +60,7 @@ export default class Validators {
new PhoneValidator(),
new OpeningHoursValidator(),
new ColorValidator(),
new FediverseValidator()
new FediverseValidator(),
]
private static _byType = Validators._byTypeConstructor()

View file

@ -1,13 +1,15 @@
import {Validator} from "../Validator"
import {Translation} from "../../i18n/Translation";
import Translations from "../../i18n/Translations";
import { Validator } from "../Validator"
import { Translation } from "../../i18n/Translation"
import Translations from "../../i18n/Translations"
export default class FediverseValidator extends Validator {
public static readonly usernameAtServer: RegExp = /^@?(\w+)@((\w|\.)+)$/
constructor() {
super("fediverse", "Validates fediverse addresses and normalizes them into `@username@server`-format");
super(
"fediverse",
"Validates fediverse addresses and normalizes them into `@username@server`-format"
)
}
/**
@ -15,8 +17,8 @@ export default class FediverseValidator extends Validator {
* @param s
*/
reformat(s: string): string {
if(!s.startsWith("@")){
s = "@"+s
if (!s.startsWith("@")) {
s = "@" + s
}
if (s.match(FediverseValidator.usernameAtServer)) {
return s
@ -25,39 +27,38 @@ export default class FediverseValidator extends Validator {
const url = new URL(s)
const path = url.pathname
if (path.match(/^\/\w+$/)) {
return `@${path.substring(1)}@${url.hostname}`;
return `@${path.substring(1)}@${url.hostname}`
}
} catch (e) {
// Nothing to do here
}
return undefined
}
getFeedback(s: string): Translation | undefined {
const match = s.match(FediverseValidator.usernameAtServer)
console.log("Match:", match)
if (match) {
const host = match[2]
getFeedback(s: string): Translation | undefined {
const match = s.match(FediverseValidator.usernameAtServer)
console.log("Match:", match)
if (match) {
const host = match[2]
try {
const url = new URL("https://" + host)
return undefined
} catch (e) {
return Translations.t.validation.fediverse.invalidHost.Subs({ host })
}
}
try {
const url = new URL("https://" + host)
return undefined
const url = new URL(s)
const path = url.pathname
if (path.match(/^\/\w+$/)) {
return undefined
}
} catch (e) {
return Translations.t.validation.fediverse.invalidHost.Subs({host})
// Nothing to do here
}
return Translations.t.validation.fediverse.feedback
}
try {
const url = new URL(s)
const path = url.pathname
if (path.match(/^\/\w+$/)) {
return undefined
}
} catch (e) {
// Nothing to do here
}
return Translations.t.validation.fediverse.feedback
}
isValid(s): boolean {
return this.getFeedback(s) === undefined
return this.getFeedback(s) === undefined
}
}