aboutsummaryrefslogblamecommitdiffhomepage
path: root/client/src/root-helpers/utils.ts
blob: 00bd92411247aedfb890ea38fac7e3bd4acca28d (plain) (tree)
1
2
3
4
5
6
7
8
9







                                                                          










                                               
                            
                                   


                               
        
                  
                     
 
function objectToUrlEncoded (obj: any) {
  const str: string[] = []
  for (const key of Object.keys(obj)) {
    str.push(encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]))
  }

  return str.join('&')
}

function copyToClipboard (text: string) {
  const el = document.createElement('textarea')
  el.value = text
  el.setAttribute('readonly', '')
  el.style.position = 'absolute'
  el.style.left = '-9999px'
  document.body.appendChild(el)
  el.select()
  document.execCommand('copy')
  document.body.removeChild(el)
}

function wait (ms: number) {
  return new Promise<void>(res => {
    setTimeout(() => res(), ms)
  })
}

export {
  copyToClipboard,
  objectToUrlEncoded,
  wait
}