summaryrefslogtreecommitdiff
path: root/src/lib/url.js
blob: 7e294cf85f66e1d28b0c0f2bc447fc9f7011d7f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// import { window } from 'browser-monads'

export const parseQuery = () => ''
// window.location.search && parseQueryString(window.location.search)

export const parseQueryString = query =>
  query
    .split('?')[1]
    .split('&')
    .reduce((acc, pair) => {
      const [key, val] = pair.split('=')
      return {
        ...acc,
        [key]: val
      }
    }, {})

export const objectToQuery = query =>
  Object.entries(query).reduce(
    (acc, [key, val], i) => acc + `${i !== 0 ? '&' : ''}${key}=${val}`,
    '?'
  )

export const writeQuery = queryObj => {
  // window.history.pushState({}, '', objectToQuery(queryObj))
}