UNPKG

tipi-cloudbeds

Version:

Node.js library to connect to cloudbeds REST API

23 lines (21 loc) 631 B
const _ = require('lodash') const { Oops } = require('@gokiteam/oops') module.exports = (query) => { if(!_.isObject(query)) throw Oops.invalidArgument('query should be an object') let queryParams = [] _.each(query, (value, key) => { if (_.isArray(value)) { queryParams.push(`${key}=${value.join(',')}`) } else if (_.isObject(value)) { _.each (value, (subValue, subKey) => { queryParams.push(`${key}[${subKey}]=${subValue}`) }) } else if (value !== undefined) { queryParams.push(`${key}=${value}`) } }) return `${queryParams.join('&')}` }