Make generator config more robust

This commit is contained in:
Misode
2021-07-02 02:36:01 +02:00
parent cabd97cb39
commit f43cb03cc3
20 changed files with 158 additions and 172 deletions

View File

@@ -1,3 +1,5 @@
import config from '../config.json'
export function isPromise(obj: any): obj is Promise<any> {
return typeof (obj as any)?.then === 'function'
}
@@ -26,6 +28,11 @@ export function cleanUrl(url: string) {
return `/${url}/`.replaceAll('//', '/')
}
export function getGenerator(url: string) {
const trimmedUrl = url.replace(/^\//, '').replace(/\/$/, '')
return config.generators.find(g => g.url === trimmedUrl)
}
export function stringToColor(str: string): [number, number, number] {
const h = Math.abs(hashString(str))
return [h % 256, (h >> 8) % 256, (h >> 16) % 256]