Skip to content

Instantly share code, notes, and snippets.

View MrRedu's full-sized avatar
:electron:
help, I don't understand

Eduardo MrRedu

:electron:
help, I don't understand
View GitHub Profile
@MrRedu
MrRedu / Utils.js
Created January 27, 2025 15:57 — forked from ch1nux/Utils.js
Javascript Utilities for several things
/**
* 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}
*/
@MrRedu
MrRedu / venezuela.js
Last active November 30, 2024 23:20
🇻🇪 Organización territorial de Venezuela
🇻🇪 Venezuela
const Venezuela = [
{
"iso_31662": "VE-X",
"estado": "Amazonas",
"capital": "Puerto Ayacucho",
@MrRedu
MrRedu / useTextSelection.ts
Created February 22, 2024 17:11 — forked from KristofferEriksson/useTextSelection.ts
A React Typescript hook that tracks user text selections & their screen positions
import { useEffect, useState } from "react";
type UseTextSelectionReturn = {
text: string;
rects: DOMRect[];
ranges: Range[];
selection: Selection | null;
};
const getRangesFromSelection = (selection: Selection): Range[] => {
@MrRedu
MrRedu / useLocation.ts
Created February 22, 2024 17:10 — forked from KristofferEriksson/useLocation.ts
A React Typescript hook that provides real-time geolocation data, complete with heading and speed metrics
import { useEffect, useState } from "react";
interface LocationOptions {
enableHighAccuracy?: boolean;
timeout?: number;
maximumAge?: number;
}
interface LocationState {
coords: {
@MrRedu
MrRedu / useGesture.ts
Created February 22, 2024 17:10 — forked from KristofferEriksson/useGesture.ts
A custom React Typescript hook for advanced touch gestures in UI
import { useEffect, useRef } from "react";
type GestureType =
| "swipeUp"
| "swipeDown"
| "swipeLeft"
| "swipeRight"
| "tap"
| "pinch"
| "zoom";
@MrRedu
MrRedu / useFetch.ts
Created February 22, 2024 17:09 — forked from KristofferEriksson/useFetch.ts
A generic React fetch hook for API calls with caching, error handling, and refetch capability
import { useCallback, useEffect, useState } from "react";
type FetchState<T> = {
data: T | null;
isLoading: boolean;
error: Error | null;
isCached: boolean;
refetch: () => void;
};
@MrRedu
MrRedu / useCookie.ts
Created February 22, 2024 17:08 — forked from KristofferEriksson/useCookie.ts
A hook to easily read and update browser cookies. Plus, it auto-updates your component when cookie values change
import { useEffect, useState } from "react";
type UseCookieReturnType = {
cookie: string | undefined;
setCookie: (value: string, days?: number) => void;
};
const useCookie = (cookieName: string): UseCookieReturnType => {
const getCookie = (name: string): string | undefined => {
const value = `; ${document.cookie}`;
@MrRedu
MrRedu / useLocalStorage.ts
Created February 22, 2024 17:07 — forked from KristofferEriksson/useLocalStorage.ts
An easy-to-use API for storing and retrieving data from Local Storage in React, with built-in real-time synchronization
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));