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
| function stringToNumber(str: string) { | |
| str = str.trim() | |
| if (/[^\d]/.test(str)) { | |
| throw new Error('Deve conter apenas numeros') | |
| } | |
| return Array.from(str).reverse().reduce((acc, cur, idx) => { | |
| let val = (cur.charCodeAt(0) - 48) | |
| return acc + (val * 10 ** idx) |
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, useEffect } from 'react'; | |
| export default function useSearchParams() { | |
| const getSearchParams = () => { | |
| const queryString = window.location.search; | |
| return new URLSearchParams(queryString); | |
| }; | |
| const [searchParams, setSearchParams] = useState(getSearchParams); |
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
| type GetArrayIndexValue<A extends [], K extends number | string> = K extends `.${infer I}` ? GetArrayIndexValue<A, I> : K extends number ? A[K] : never | |
| type GetObjectPathValue<O extends object, P extends string> = P extends `${infer A}.${infer B}` ? A extends keyof O ? O[A] extends object ? GetObjectPathValue<O[A], B> : O[A] : never : P extends keyof O ? O[P] extends [] ? GetArrayIndexValue<O[P], P> : O[P] : never | |
| const obj = { | |
| a: { | |
| b: 1, | |
| c: [1, 2], | |
| d: [ | |
| [12], |
OlderNewer