This file contains hidden or 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 LocaleFunc, type TDate, format, register } from 'timeago.js' | |
const localeFunc: LocaleFunc = (_: number, idx: number, __?: number) => { | |
// number: the timeago / timein number; | |
// index: the index of array below; | |
// totalSec: total seconds between date to be formatted and today's date; | |
return [ | |
['justo ahora', 'justo ahora'], | |
['hace %s segundos', 'en %s segundos'], | |
['hace 1 minuto', 'en 1 minuto'], |
This file contains hidden or 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 { useCallback, useState } from 'react' | |
export type UseDisclosureReturn = { | |
open: boolean | |
onOpen: () => void | |
onClose: () => void | |
onToggle: () => void | |
onOpenChange: (v: boolean) => void | |
} |
This file contains hidden or 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 fs from 'fs/promises' | |
import path from 'path' | |
const ignoredFiles = [ | |
'.git', | |
'.vscode', | |
'node_modules', | |
'public' | |
] | |
function ignoreFile(filename) { |
This file contains hidden or 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 { useRef } from 'react' | |
// eslint-disable-next-line @typescript-eslint/no-explicit-any | |
export function useDebounce<T extends (...params: any[]) => void>( | |
fn: T, | |
delay = 1000 | |
) { | |
const debounceRef = useRef<ReturnType<typeof setTimeout>>() | |
// eslint-disable-next-line @typescript-eslint/no-explicit-any |
This file contains hidden or 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 { useState } from 'react' | |
type FilterFunction<T> = (item: T) => boolean | |
export function useArray<T>() { | |
const [data, setData] = useState<Array<T>>([]) | |
function push(value: T): void { | |
setData((prev) => [...prev, value]) | |
} |
This file contains hidden or 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
// tsconfig.json | |
"references": [{ "path": "./tsconfig.node.json" }], | |
"extends": "./tsconfig.paths.json" | |
// create: tsconfig.paths.json | |
{ | |
"compilerOptions": { | |
"baseUrl": ".", |
This file contains hidden or 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
// Definition | |
type ComponentProps<Generic1, Generic2> = { | |
prop1: Generic1 | |
prop2: Generic2 | |
} | |
export const Component = <T, T1>(props: ComponentProps<T, T1>) => { | |
const { prop1, prop2 } = props | |
return <></> | |
} |
This file contains hidden or 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 debounce = (func) => { | |
let timer; | |
return function(...args) { | |
const context = this; | |
if(timer) clearTimeout(timer); | |
timer = setTimeout(() => { | |
timer = null; | |
func.apply(context, args); |