'use strict';

exports.__esModule = true;

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

var re = new RegExp(/[\w\-]+|\[[^\]]*\]+/g);

var get = function get(object, path, defaultValue) {
    if (!object || (typeof object === 'undefined' ? 'undefined' : _typeof(object)) !== 'object') {
        return defaultValue;
    }

    // Ensure string
    path = '' + path;

    var keys = path.match(re);
    if (!keys) {
        return defaultValue;
    }

    for (var i = 0; i < keys.length; i++) {
        var key = keys[i].trim();
        if (['\'', '"', '[', ']'].indexOf(key.charAt(0)) >= 0) {
            key = key.slice(1, -1);
        }
        if (object === undefined || object === null || (typeof object === 'undefined' ? 'undefined' : _typeof(object)) !== 'object') {
            break;
        }
        object = object[key];
        if (object === undefined) {
            break;
        }
    }

    return object !== undefined ? object : defaultValue;
};

exports['default'] = get;