"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.chunkArray = exports.isEmpty = exports.deepMerge = exports.prefixKeys = exports.removeEmptyValues = void 0;
function removeEmptyValues(obj) {
    return Object.fromEntries(Object.entries(obj).filter(([, v]) => v != null));
}
exports.removeEmptyValues = removeEmptyValues;
function prefixKeys(obj, prefix, removeEmpty) {
    if (prefix == null || prefix === '') {
        return removeEmpty ? removeEmptyValues(obj) : obj;
    }
    const entries = Object.entries(obj);
    return Object.fromEntries((removeEmpty ? entries.filter(([, v]) => v != null) : entries).map(([k, v]) => [prefix + k, v]));
}
exports.prefixKeys = prefixKeys;
/**
 * Recursively (deeply) merges 2 object of the same type. It only merges plain object, not arrays.
 * It does not mutate the original object but may return references to (parts of the) original object.
 */
function deepMerge(a, b) {
    return Object.fromEntries([
        ...Object.entries(a).map(([k, v]) => {
            var _a, _b;
            if (typeof v === 'object' && !Array.isArray(v)) {
                return [k, b[k] == null ? v : deepMerge(v, (_a = b[k]) !== null && _a !== void 0 ? _a : {})];
            }
            return [k, (_b = b[k]) !== null && _b !== void 0 ? _b : v];
        }),
        ...Object.entries(b).filter(([k]) => !(k in a))
    ]);
}
exports.deepMerge = deepMerge;
function isEmpty(obj) {
    return obj == null || Object.values(obj).filter(v => v != null).length === 0;
}
exports.isEmpty = isEmpty;
function chunkArray(data, chunkSize) {
    const chunkCount = Math.ceil(data.length / chunkSize);
    const chunks = [];
    for (let i = 0; i < chunkCount; i++) {
        const chunk = data.splice(0, chunkSize);
        chunks.push(chunk);
    }
    return chunks;
}
exports.chunkArray = chunkArray;
