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
Show hidden characters
{ | |
// Text Editor | |
"editor.bracketPairColorization.enabled": false, | |
"editor.guides.bracketPairs": "active", | |
"editor.rulers": [100], | |
"editor.semanticHighlighting.enabled": true, | |
"editor.stickyScroll.enabled": true, | |
// Text Editor -> Cursor | |
"editor.cursorBlinking": "smooth", |
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
const stringToColor = (str: string) => { | |
let hash = 0 | |
for (let i = 0; i < str.length; i++) { | |
hash = str.charCodeAt(i) + ((hash << 5) - hash) | |
} | |
let color = '#' | |
for (let i = 0; i < 3; i++) { | |
const value = (hash >> (i * 8)) & 0xff | |
color += `00${value.toString(16)}`.slice(-2) | |
} |
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
interface StateRefObject<T> { | |
readonly current: T | |
} | |
export const useStateWithRef = <T>( | |
initialValue: T | (() => T) | |
): [T, React.Dispatch<React.SetStateAction<T>>, StateRefObject<T>] => { | |
const [state, __setState] = useState(initialValue) | |
const stateRef = useRef(state) |
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
export const tap = | |
<T>(fn: (arg: T) => void) => | |
(arg: T): T => { | |
fn(arg) | |
return arg | |
} |
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
export const unary = | |
<T, R>(fn: (arg1: T, ...args: unknown[]) => R) => | |
(arg1: T): R => | |
fn(arg1) |
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
export const range = (n: number): number[] => Array.from({ length: n }, (_, i) => i) |
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
// https://stackoverflow.com/a/63790089/13346012 | |
export type Head<T extends unknown[]> = T extends [...infer Head, unknown] ? Head : unknown[] |
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 PartiallyRequired<T, K extends keyof T> = Omit<T, K> & Pick<Required<T>, K> |
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
export const isModuleAvailable = (path: string): boolean => { | |
try { | |
require.resolve(path) | |
return true | |
} catch { | |
return false | |
} | |
} |
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
export const unwrap = <T>( | |
value: T | undefined | null, | |
errorMessage?: string | |
): T | never => { | |
if (value === null || value === undefined) { | |
throw new Error(errorMessage ?? 'Missing value') | |
} | |
return value | |
} |
NewerOlder