All files / src/utility uriParser.js

100% Statements 12/12
75% Branches 3/4
100% Functions 5/5
100% Lines 11/11

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        2x   2x 5x 1x 2x   4x 4x       2x       7x     8x   7x      
import { each, isArray, isUndefined } from 'lodash';
 
export default {
  encode(params) {
    const queryParams = new URLSearchParams();
 
    each(params, (paramValue, key) => {
      if (isArray(paramValue)) { // multi-value query parameter
        each(paramValue, (paramMultiValue) => {
          queryParams.append(key, paramMultiValue);
        });
      } else Eif (!isUndefined(paramValue)) {
        queryParams.append(key, paramValue);
      }
    });
 
    return queryParams.toString();
  },
  joinUrl(baseUrl, ...urlParts) {
    // Remove ending slash in base url
    const parsedBase = baseUrl.replace(/[/]+$/, '');
 
    // Strip start and end slashes for each url part
    const parsedParts = urlParts.map(part => part.replace(/^\/|\/$/g, ''));
 
    return `${parsedBase}/${parsedParts.join('/')}`;
  },
};