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
| /** | |
| * Detect words in a paragraph. | |
| * @type {RegExp} ['word', 'word', ...] | |
| */ | |
| export const WORDS = /[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g | |
| /** | |
| * Detect a valid Venezuelan phone number (area code included) | |
| * @type {RegExp} | |
| */ |
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 { useEffect, useState } from "react"; | |
| type UseTextSelectionReturn = { | |
| text: string; | |
| rects: DOMRect[]; | |
| ranges: Range[]; | |
| selection: Selection | null; | |
| }; | |
| const getRangesFromSelection = (selection: Selection): Range[] => { |
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 { useEffect, useState } from "react"; | |
| interface LocationOptions { | |
| enableHighAccuracy?: boolean; | |
| timeout?: number; | |
| maximumAge?: number; | |
| } | |
| interface LocationState { | |
| coords: { |
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 { useEffect, useRef } from "react"; | |
| type GestureType = | |
| | "swipeUp" | |
| | "swipeDown" | |
| | "swipeLeft" | |
| | "swipeRight" | |
| | "tap" | |
| | "pinch" | |
| | "zoom"; |
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, useEffect, useState } from "react"; | |
| type FetchState<T> = { | |
| data: T | null; | |
| isLoading: boolean; | |
| error: Error | null; | |
| isCached: boolean; | |
| refetch: () => 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 { useEffect, useState } from "react"; | |
| function useLocalStorage() { | |
| const [loadingStates, setLoadingStates] = useState<Map<string, boolean>>( | |
| new Map() | |
| ); | |
| const setStorageValue = <T>(key: string, value: T) => { | |
| try { | |
| window.localStorage.setItem(key, JSON.stringify(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
| import { useCallback, useEffect, useRef, useState } from "react"; | |
| /** | |
| * Custom React hook for double-click confirmation for critical actions. | |
| * | |
| * @param action - The action to be executed on the second click. | |
| * @param timeout - Time in milliseconds to reset the unlocked state. | |
| * @returns The current unlocked state and the trigger function. | |
| */ | |
| const useConfirmation = (action: () => void, timeout: number = 5000) => { |
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 { useEffect } from "react"; | |
| const Keys = { | |
| Backspace: "Backspace", | |
| Tab: "Tab", | |
| Enter: "Enter", | |
| Shift: "Shift", | |
| Control: "Control", | |
| Alt: "Alt", | |
| Pause: "Pause", |
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"; | |
| // Custom hook to copy text to clipboard | |
| const useCopyToClipboard = (timeoutDuration: number = 1000) => { | |
| const [copied, setCopied] = useState(false); | |
| const [error, setError] = useState<Error | null>(null); | |
| const copyToClipboard = useCallback( | |
| async (text: string) => { | |
| try { |
NewerOlder