Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Simple implementation of lodash.get | |
// Handles arrays, objects, and any nested combination of the two. | |
// Also handles undefined as a valid value - see test case for details. | |
// Based on: https://gist.github.com/harish2704/d0ee530e6ee75bad6fd30c98e5ad9dab | |
export function deepGet(obj, query, defaultVal) { | |
query = Array.isArray(query) ? query : query.replace(/(\[(\d)\])/g, '.$2').replace(/^\./, '').split('.'); | |
if (!(query[0] in obj)) { | |
return defaultVal; | |
} | |
obj = obj[query[0]]; |