[ABANDONED] React/Redux front end for the Flexor social network.
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.

36 lines
1.4 KiB

5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. import themes from '../themes'
  2. import { Form, FormValue, ClassDictionary } from '../types'
  3. export const objectToQuerystring = (obj: object) => Object.entries(obj).filter(([_, value]) => value !== undefined).map(([name, value]) => `${name}=${value}`).join('&')
  4. export function setTitle(title: string, decorate: boolean = true) {
  5. if (decorate) {
  6. document.title = `${title} / Flexor`
  7. } else {
  8. document.title = title
  9. }
  10. }
  11. export function valueFromForm<T extends FormValue>(form: Form, name: string): T | undefined
  12. export function valueFromForm<T extends FormValue>(form: Form, name: string, defaultValue: T): T
  13. export function valueFromForm<T extends FormValue>(form: Form, name: string, defaultValue?: T): T | undefined
  14. export function valueFromForm<T extends FormValue>(form: Form, name: string, defaultValue?: T): T | undefined {
  15. const field = form[name]
  16. if (!field) return defaultValue
  17. if (field.value === undefined) return defaultValue
  18. return field.value as T
  19. }
  20. export function getOrigin(url: string) {
  21. const parser = document.createElement('a')
  22. parser.href = url
  23. return parser.origin
  24. }
  25. export const classNames = (dictionary: ClassDictionary) => Object.entries(dictionary).filter(([_, value]) => !!value).map(([key, _]) => key).join(' ')
  26. export const getDefaultThemeName = () => Object.keys(themes)[0]
  27. export const pathJoin = (...paths: string[]) => paths.map(path => path.trim().replace(/(^\/|\/$)/, '')).join('/')