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 Split<S extends string, D extends string> = S extends `${infer T}${D}${infer U}` ? [T, ...Split<U, D>] : [S]; | |
type TakeLast<V> = V extends [] ? never : V extends [string] ? V[0] : V extends [string, ...infer R] ? TakeLast<R> : never; | |
type TrimLeft<V extends string> = V extends ` ${infer R}` ? TrimLeft<R> : V; | |
type TrimRight<V extends string> = V extends `${infer R} ` ? TrimRight<R> : V; | |
type Trim<V extends string> = TrimLeft<TrimRight<V>>; | |
type StripModifier<V extends string, M extends string> = V extends `${infer L}${M}${infer A}` ? L : V; | |
type StripModifiers<V extends string> = StripModifier<StripModifier<StripModifier<StripModifier<V, '.'>, '#'>, '['>, ':'>; | |
type TakeLastAfterToken<V extends string, T extends string> = StripModifiers<TakeLast<Split<Trim<V>, T>>>; | |
type GetLastElementName<V extends string> = TakeLastAfterToken<TakeLastAfterToken<V, ' '>, '>'>; | |
type GetEachElementName<V, L extends string[] = []> = |
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 { | |
useMemo, | |
useRef, | |
type MutableRefObject, | |
type Ref, | |
type RefCallback, | |
} from 'react'; | |
const useLifecycleRef = <T extends Element>({ | |
onAttach, |
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 { useLayoutEffect, useRef } from "react"; | |
type AnyFunction = (...args: any[]) => any; | |
const useLayoutEffectRef = typeof window !== "undefined" ? useLayoutEffect : () => {}; | |
export function useCallbackRef<TCallback extends AnyFunction>(callback: TCallback): TCallback { | |
const latestRef = useRef<TCallback>(useCallbackRef_shouldNotBeInvokedBeforeMount as any); | |
useLayoutEffectRef(() => { | |
latestRef.current = callback; | |
}, [callback]); |
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 _defaultOptions = { | |
fileName: `${new Date().toLocaleString('tr-TR')}- screen record`, | |
recording: { | |
video: true, | |
audio: true, | |
}, | |
callbackRecording: (s: boolean) => {}, | |
}; | |
const secure = location.protocol === 'https:' || location.hostname === 'localhost', |
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 { useReducer, useMemo, useDebugValue } from 'react' | |
import produce, { Draft } from 'immer' | |
export type PayloadAction<P> = { | |
type: string | |
payload: P | |
} | |
export type PayloadActionDispatch<P = void> = void extends P |
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 BubbleSort< | |
A extends any[], | |
Curr extends number = A["length"] | |
> = Curr extends 1 | |
? A | |
: A extends [infer F, infer S, ...infer Rest] | |
? BubbleSort< | |
[ | |
...(Math.Comparator<Math.Num<F>, Math.Num<S>> extends true | |
? [S, ...BubbleSort<[F, ...Rest], Math.Sub<Curr, 1>>] |
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 default function circularStringify(object, { indentation } = {}) { | |
if (Array.isArray(object)) { | |
object = object.map((element) => | |
JSON.parse(JSON.stringify(element, replacer())), | |
) | |
} | |
return JSON.stringify(object, replacer(), indentation) | |
} | |
const replacer = () => { |
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 EventType = string | symbol | |
type Handler<T = unknown> = (event: T) => void | |
type OtherHandler<T = Record<string, unknown>> = ( | |
type: keyof T, | |
event: T[keyof T], | |
) => void | |
type EventHandlerList<T = unknown> = Array<Handler<T>> | |
type OtherHandlerList<T = Record<string, unknown>> = Array<OtherHandler<T>> | |
type EventHandlerMap<Events extends Record<EventType, unknown>> = Map< | |
keyof Events | '*', |
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 { useReducer, Reducer, Dispatch, useMemo } from "react"; | |
type Action<T, P> = { | |
type: T; | |
payload: P; | |
}; | |
type ActionMap<A> = { | |
[K in keyof A]: (payload?: A[K]) => void; | |
}; |
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
function httpRequest(url, method, data) { | |
const init = { method } | |
switch (method) { | |
case 'GET': | |
if (data) url = `${url}?${new URLSearchParams(data)}` | |
break | |
case 'POST': | |
case 'PUT': | |
case 'PATCH': | |
init.body = JSON.stringify(data) |
NewerOlder