Skip to content

Instantly share code, notes, and snippets.

View munierujp's full-sized avatar
👨‍💻
Contribute to the world

Munieru munierujp

👨‍💻
Contribute to the world
View GitHub Profile
import { useMemo } from 'react'
import { useLocation } from 'react-router-dom'
/**
* @see https://v5.reactrouter.com/web/example/query-parameters
*/
export const useQueryParams = (): URLSearchParams => {
const { search } = useLocation()
return useMemo(() => new URLSearchParams(search), [search])
}
const sleep = async (ms) => {
return await new Promise(resolve => setTimeout(resolve, ms))
}
const waitLoaded = async () => {
await new Promise((resolve) => {
window.addEventListener('load', () => {
resolve()
})
})
}
const waitDOMContentLoaded = async () => {
await new Promise((resolve) => {
window.addEventListener('DOMContentLoaded', () => {
resolve()
})
})
}
export class SensitiveParameter<T> {
private readonly value: T
private readonly masked: string
constructor (value: T, masked: string = '***') {
this.value = value
this.masked = masked
}
/**
const array1: number[] = [1, 2, 3]
const array2: boolean[] = [false, true]
const array3 = array1.flatMap(a => array2.map(b => [a, b] as const))
/*
type: (readonly [number, boolean])[]
value:
[
[ 1, false ],
[ 1, true ],
[ 2, false ],