"use strict";
/*
 * Copyright (c) 2021-2022.
 * Author Peter Placzek (tada5hi)
 * For the full copyright and license information,
 * view the LICENSE file that was distributed with this source code.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.flattenNestedObject = exports.hasOwnProperty = void 0;
function hasOwnProperty(obj, prop) {
    return Object.prototype.hasOwnProperty.call(obj, prop);
}
exports.hasOwnProperty = hasOwnProperty;
function flattenNestedObject(data, options, prefixParts) {
    options = options || {};
    prefixParts = prefixParts || [];
    let output = {};
    if (options.transformer) {
        const result = options.transformer(data, output, prefixParts.join('.'));
        if (typeof result !== 'undefined' && !!result) {
            return output;
        }
    }
    const keys = Object.keys(data);
    for (let i = 0; i < keys.length; i++) {
        const key = keys[i];
        if (options.transformer) {
            const result = options.transformer(data[key], output, [...prefixParts, key].join('.'));
            if (typeof result !== 'undefined' && !!result) {
                continue;
            }
        }
        if (typeof data[key] === 'object' &&
            data[key]) {
            output = Object.assign(Object.assign({}, output), flattenNestedObject(data[key], options, [...prefixParts, key]));
            continue;
        }
        const destinationKey = [...prefixParts, key].join('.');
        if (typeof data[key] === 'boolean' ||
            typeof data[key] === 'string' ||
            typeof data[key] === 'number' ||
            typeof data[key] === 'undefined' ||
            data[key] === null ||
            Array.isArray(data[key])) {
            output[destinationKey] = data[key];
        }
    }
    return output;
}
exports.flattenNestedObject = flattenNestedObject;
//# sourceMappingURL=object.js.map