All files utils.js

88.89% Statements 8/9
100% Branches 4/4
75% Functions 3/4
88.89% Lines 8/9

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 30 31 32 33 34 35 36 37 38 39 40 41                                3x 4x 6x   6x   6x 1x   6x                       3x      
/*
 * Next Avenues
 *
 * (c) Samuel Joos
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
*/
 
/**
 * @description
 * Create a url query string from an object
 *
 * @function toQuerystring
 * @param {Object.<string, string>} obj
 */
export const toQuerystring = obj =>
    '?' + Object.keys(obj)
        .filter(key => obj[key] !== null && obj[key] !== undefined)
        .map(key => {
            let value = obj[key];
 
            if (Array.isArray(value)) {
                value = value.join('/');
            }
            return [encodeURIComponent(key), encodeURIComponent(value)].join('=');
        })
        .join('&');
 
/**
 * @description
 * Format error Message
 *
 * @param {string} message
 * @param {*} subject
 * @returns {string}
 */
export const errorMessage = (message, subject) => {
    return `${message} for ${subject}`;
};