const camelToUnderscore = (key) => key.replace(/([A-Z])/g, "_$1").toLowerCase();
const underscoredKey = (target, key, value) => ({
    ...target,
    [camelToUnderscore(key)]: value,
});
export const objectTransformator = (data, { func, action }) => {
    if (Array.isArray(data)) {
        return data.map(func);
    }
    if (typeof data === "object" && data) {
        return Object.keys(data).reduce((d, key) => {
            const value = func(data[key]);
            return action(d, key, value);
        }, {});
    }
    return data;
};
export const underscoredKeys = (data) => objectTransformator(data, {
    func: underscoredKeys,
    action: underscoredKey,
});
//# sourceMappingURL=object-transform.js.map