This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function importScript(src: string) { | |
const script = document.createElement('script'); | |
script.src = src; | |
document.body.appendChild(script); | |
return new Promise((res, rej) => { | |
script.onload = () => res(); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type FlattenKeys<T extends Record<string, any>, prefix extends string = ''> = { | |
[key in keyof T]: key extends string | |
? T[key] extends object | |
? `${prefix}${key}` | FlattenKeys<T[key], `${prefix}${key}.`> | |
: `${prefix}${key}` | |
: never; | |
}[keyof T]; | |
// and to use it: | |
type Data = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { FormEventHandler } from 'svelte/elements'; | |
import { writable } from 'svelte/store'; | |
type Message = { | |
type: 'error' | 'success'; | |
text: string; | |
}; | |
type FormStoreValues = { | |
loading: boolean; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { MutableRefObject } from "react"; | |
import { | |
FieldPath, | |
FieldValues, | |
RegisterOptions, | |
UseFormRegister, | |
} from "react-hook-form"; | |
/** attach your ref to the register function from react-hook-form */ | |
export const registerWithRef = <T extends FieldValues = FieldValues>( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Thank you SO | |
// https://stackoverflow.com/questions/13382516/getting-scroll-bar-width-using-javascript | |
export function getScrollbarWidth() { | |
// Creating invisible container | |
const outer = document.createElement("div"); | |
outer.style.visibility = "hidden"; | |
outer.style.overflow = "scroll"; // forcing scrollbar to appear | |
document.body.appendChild(outer); | |
// Creating inner element and placing it in the container |