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
| const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); | |
| class BarberShop { | |
| constructor( | |
| chairsAvailable | |
| ) { | |
| this.chairsAvailable = chairsAvailable; | |
| this.queue = []; | |
| this.barberAttending = false; | |
| } |
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
| const cards = { | |
| visa : /^4[0-9]{12}(?:[0-9]{3})/, | |
| mastercard : /^5[1-5][0-9]{14}/, | |
| diners : /^3(?:0[0-5]|[68][0-9])[0-9]{11}/, | |
| amex : /^3[47][0-9]{13}/, | |
| discover : /^6(?:011|5[0-9]{2})[0-9]{12}/, | |
| hipercard : /^(606282\d{10}(\d{3})?)|(3841\d{15})/, | |
| elo : /^((((636368)|(438935)|(504175)|(451416)|(636297))\d{0,10})|((5067)|(4576)|(4011))\d{0,12})/, | |
| jcb : /^(?:2131|1800|35\d{3})\d{11}/, | |
| aura : /^(5078\d{2})(\d{2})(\d{11})$/ |
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"; | |
| export function useDebounce<T>( | |
| initialValue: T, | |
| time: number | |
| ): [T, T, React.Dispatch<T>] { | |
| const [value, setValue] = useState<T>(initialValue); | |
| const [debouncedValue, setDebouncedValue] = useState<T>(initialValue); | |
| useEffect(() => { |
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
| const usePDF = (conteudo: string, arquivo: string) => { | |
| const linkVisualizacao = `data:application/pdf;base64,${conteudo}`; | |
| const pdfBytes = Uint8Array.from(atob(conteudo), (c) => c.charCodeAt(0)); | |
| const blob = new Blob([pdfBytes], { type: 'application/pdf' }); | |
| const onDownloadPDF = () => { | |
| const url = URL.createObjectURL(blob); | |
| const element = document.createElement('a'); | |
| element.href = url; | |
| element.download = arquivo; |
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'; | |
| export function usePreventClickJacking() { | |
| useEffect(() => { | |
| const script = document.createElement('script'); | |
| script.async = true; | |
| script.innerHTML = ` | |
| if (top != window) { | |
| top.location = window.location; |
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
| /** | |
| * classGroupe('px-2 py-1 bg-red hover:bg-dark-red', 'p-3 bg-[#B91C1C]') // → 'hover:bg-dark-red p-3 bg-[#B91C1C]' | |
| */ | |
| export function classGroupe (...args: any[]) { | |
| return args.join(' ') | |
| } |
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
| /** | |
| * getEmojisFromString('This 😃 is an Emoji exemple ❤️') // ['😃', '❤️'] | |
| */ | |
| function getEmojisFromString (str: string) { | |
| return str.match(/\p{Emoji}+/gu) | |
| } |
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 slugify = (...args: (string | number)[]): string => { | |
| const value = args.join(' ') | |
| return value | |
| .normalize('NFD') // split an accented letter in the base letter and the acent | |
| .replace(/[\u0300-\u036f]/g, '') // remove all previously split accents | |
| .toLowerCase() | |
| .trim() | |
| .replace(/[^a-z0-9 ]/g, '') // remove all chars not letters, numbers and spaces (to be replaced) | |
| .replace(/\s+/g, '-') // separator |
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' | |
| export function useLocalStorage<T> ( | |
| key: string, | |
| initialValue: T | |
| ): [T, (value: T | ((val: T) => T)) => void] { | |
| // State to store our value | |
| // Pass initial state function to useState so logic is only executed once | |
| const [storedValue, setStoredValue] = useState<T>(() => { | |
| try { |
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 { CSSProperties, memo, ReactNode } from 'react' | |
| type ViewStyle = Pick<CSSProperties, | |
| 'alignItems' | |
| | 'alignSelf' | |
| | 'alignContent' | |
| | 'justifyContent' | |
| | 'flex' | |
| | 'marginBottom' | |
| | 'marginRight' |
NewerOlder