aboutsummaryrefslogblamecommitdiffhomepage
path: root/client/src/root-helpers/url.ts
blob: b2f0c8b85c42483d3f88cab1849e8ee93434b829 (plain) (tree)
























                                                                                         
function getParamToggle (params: URLSearchParams, name: string, defaultValue?: boolean) {
  return params.has(name)
    ? (params.get(name) === '1' || params.get(name) === 'true')
    : defaultValue
}

function getParamString (params: URLSearchParams, name: string, defaultValue?: string) {
  return params.has(name)
    ? params.get(name)
    : defaultValue
}

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

  return str.join('&')
}

export {
  getParamToggle,
  getParamString,
  objectToUrlEncoded
}