cobinhood-rx
Version:
CobinhoodRx is a rxjs node wrapper for the CobinhoodRx Api.
55 lines • 1.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
class Utilities {
static removeUndefined(obj) {
const res = (Object).assign({}, obj);
for (const key of Object.keys(res)) {
if (res[key] === undefined) {
delete res[key];
}
}
return res;
}
static generateQuerySting(queryObject) {
const keys = Object.keys(queryObject);
if (keys.length === 0) {
return '';
}
const builder = [];
for (const key of keys) {
if (queryObject.hasOwnProperty(key) && !Utilities.isObjectEmpty(queryObject[key])) {
builder.push(`${key}=${queryObject[key]}`);
}
}
const qString = `?${encodeURI(builder.join('&'))}`;
return (qString.length <= 1) ? '' : qString;
}
static isObjectEmpty(obj) {
if (obj === undefined ||
obj === null ||
obj === '' ||
(!this.typeOf(obj, 'number') && Object.keys(obj).length === 0)) {
return true;
}
return false;
}
static extend(target, source) {
if (this.typeOf(target, 'object') && this.typeOf(source, 'object')) {
const clonedTarget = Object.create(target);
const sourceKeys = Object.keys(Utilities.removeUndefined(source));
for (const key of sourceKeys) {
if (key in clonedTarget) {
clonedTarget[key] = source[key];
}
}
return clonedTarget;
}
return target;
}
static typeOf(obj, sType) {
obj = Object.prototype.toString.call(obj).match(/\s([a-z|A-Z]+)/)[1].toLowerCase();
return sType.toLowerCase() === obj;
}
}
exports.Utilities = Utilities;
//# sourceMappingURL=Utilities.js.map