You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.6 KiB
42 lines
1.6 KiB
import getConfig from 'src/config'
|
|
import themes from 'src/themes'
|
|
import { Form, FormValue, Config, ClassDictionary } from 'src/types'
|
|
|
|
export const objectToQuerystring = (obj: object) => Object.entries(obj).filter(([_, value]) => value !== undefined).map(([name, value]) => `${name}=${value}`).join('&')
|
|
|
|
export function setTitle(title: string, decorate: boolean = true) {
|
|
if (decorate) {
|
|
document.title = `${title} \\ Flexor`
|
|
} else {
|
|
document.title = title
|
|
}
|
|
}
|
|
|
|
export function valueFromForm<T extends FormValue>(form: Form, name: string): T | undefined
|
|
export function valueFromForm<T extends FormValue>(form: Form, name: string, defaultValue: T): T
|
|
export function valueFromForm<T extends FormValue>(form: Form, name: string, defaultValue?: T): T | undefined
|
|
export function valueFromForm<T extends FormValue>(form: Form, name: string, defaultValue?: T): T | undefined {
|
|
const field = form[name]
|
|
|
|
if (!field) return defaultValue
|
|
if (field.value === undefined) return defaultValue
|
|
|
|
return field.value as T
|
|
}
|
|
|
|
export const urlForBlob = (config: Config, name: string) => `${config.blobUrl}${name}`
|
|
|
|
export async function urlForBlobAsync(name: string) {
|
|
const config = await getConfig()
|
|
return urlForBlob(config, name)
|
|
}
|
|
|
|
export function getOrigin(url: string) {
|
|
const parser = document.createElement('a')
|
|
parser.href = url
|
|
return parser.origin
|
|
}
|
|
|
|
export const classNames = (dictionary: ClassDictionary) => Object.entries(dictionary).filter(([_, value]) => !!value).map(([key, _]) => key).join(' ')
|
|
|
|
export const getDefaultThemeName = () => Object.keys(themes)[0]
|