2022-11-02 17:12:04 +01:00
|
|
|
import { website } from '../config.mjs'
|
2022-10-29 22:21:24 +02:00
|
|
|
|
2023-05-07 12:00:43 +02:00
|
|
|
/*
|
|
|
|
* Capitalizes a string
|
|
|
|
*/
|
|
|
|
export const capitalize = (string) => string.charAt(0).toUpperCase() + string.slice(1)
|
|
|
|
|
2022-10-31 17:54:49 +01:00
|
|
|
/*
|
|
|
|
* Cleans a string (typically email) for hashing
|
|
|
|
*/
|
|
|
|
export const clean = (string) => {
|
2022-11-02 12:47:13 +01:00
|
|
|
if (typeof string === 'number') string = string.toString()
|
|
|
|
if (typeof string !== 'string') throw 'clean() only takes a string or number as input'
|
2022-10-29 22:21:24 +02:00
|
|
|
|
2022-10-31 17:54:49 +01:00
|
|
|
return string.toLowerCase().trim()
|
|
|
|
}
|
2022-10-29 22:21:24 +02:00
|
|
|
|
2022-10-31 17:54:49 +01:00
|
|
|
/*
|
|
|
|
* I find JSON.stringify to long to type, and prone to errors
|
|
|
|
* So I make an alias here: asJson
|
|
|
|
*/
|
|
|
|
export const asJson = JSON.stringify
|
2022-11-01 18:00:25 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Builds a url using the correct scheme, language and domain
|
|
|
|
*/
|
|
|
|
export const i18nUrl = (lang, path) => {
|
2022-11-02 17:12:04 +01:00
|
|
|
let url = `${website.scheme}://${website.domain}`
|
2022-11-01 18:00:25 +01:00
|
|
|
if (lang !== 'en') url += `/${lang}`
|
|
|
|
|
|
|
|
return url + path
|
|
|
|
}
|