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
export class SensitiveParameter<T> {
private readonly value: T
private readonly masked: string
constructor (value: T, masked: string = '***') {
this.value = value
this.masked = masked
}
/**
const waitDOMContentLoaded = async () => {
await new Promise((resolve) => {
window.addEventListener('DOMContentLoaded', () => {
resolve()
})
})
}
const waitLoaded = async () => {
await new Promise((resolve) => {
window.addEventListener('load', () => {
resolve()
})
})
}
const sleep = async (ms) => {
return await new Promise(resolve => setTimeout(resolve, ms))
}
const sleep = async (ms)=> {
return await new Promise(resolve => setTimeout(resolve, ms))
}
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])
}
((function () {
const backup = localStorage.getItem('backup')
const { data } = JSON.parse(backup)
const searchParams = new URLSearchParams(data)
const params = Object.fromEntries(searchParams)
console.log(params)
})()
@munierujp
munierujp / sleep.ts
Last active September 25, 2022 14:04
const sleep = async (ms: number): Promise<void> => {
return await new Promise(resolve => setTimeout(resolve, ms))
}
function getRandomNumber (
min: number,
max: number
): number {
min = Math.ceil(min)
max = Math.floor(max)
return Math.floor(Math.random() * (max - min)) + min
}
const KATAKANA_PATTERN = /[\u30A1-\u30FA]/g
function convertKatakanaToHiragana (katakana: string): string {
return katakana.replace(KATAKANA_PATTERN, toHiragana)
}
function toHiragana (katakana: string): string {
const code = katakana.charCodeAt(0) - 0x60
return String.fromCharCode(code)
}