tickethead-sdk
Version:
SDK for the Tickethead API
30 lines • 1.32 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildQuery = buildQuery;
exports.getStringifiedQuery = getStringifiedQuery;
const query_string_1 = __importDefault(require("query-string"));
function buildQuery(query) {
// Filter out simple boolean props
const topAttributes = Object.keys(query).filter((keyName) => query[keyName] === true);
// Filter out props with sub-objects which need to be serialized
const objectProps = Object.keys(query).filter((prop) => isObject(query[prop]));
const subAttributesSerialized = objectProps.map((prop) => {
return `${prop}.${buildQuery(query[prop])}`;
});
const result = [...topAttributes, ...subAttributesSerialized].join();
return `[${result}]`;
}
function isObject(obj) {
return typeof obj === 'object' && !Array.isArray(obj) && obj !== null;
}
function getStringifiedQuery(query) {
return query_string_1.default.stringify(Object.assign(Object.assign({}, query), { with: !query.with ? undefined : buildQuery(query.with) }), {
arrayFormat: 'comma',
skipNull: true,
skipEmptyString: true,
});
}
//# sourceMappingURL=query.js.map