"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseResponse = void 0;
function parseRecursive(obj) {
    const parsed = Array.isArray(obj)
        ? obj.map((o) => {
            try {
                return parseRecursive(o);
            }
            catch {
                return o;
            }
        })
        : JSON.parse(obj);
    /**
     * Parsing very large numbers can result in MAX_SAFE_INTEGER
     * overflow. In that case we return the number as string instead.
     */
    if (typeof parsed === "number" && parsed.toString() != obj) {
        return obj;
    }
    return parsed;
}
function parseResponse(result) {
    try {
        /**
         * Try to parse the response if possible
         */
        return parseRecursive(result);
    }
    catch {
        return result;
    }
}
exports.parseResponse = parseResponse;
