All files / src/location querystring.js

27.78% Statements 5/18
0% Branches 0/6
0% Functions 0/4
18.75% Lines 3/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 27 28 29 301x   1x                         1x                            
import * as R from 'ramda';
 
export const parse = (str) => {
  if(!str) {
    return {};
  }
  const result = R.pipe(
    R.replace('?', ''),
    R.split('&'),
    R.map((item) => R.split('=', item)),
    R.fromPairs,
  )(str);
  return result
}
 
export const stringify = (query) => {
  if(R.isEmpty(query)){
    return ''
  }
  const keys = Object.keys(query);
  let result = ''
  keys.map((key) => {
    result += `&${key}=${query[key]}`
  });
  const params = new URLSearchParams(result)
  return params.toString() || '';
}