mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-04-13 22:44:11 +08:00
* [database] recreate database branch based off of #2185 * [database] cleanup linting issues * [database] enable tests * [database] add to tests deps
28 lines
632 B
JavaScript
28 lines
632 B
JavaScript
import { isObject } from './validate';
|
|
|
|
/**
|
|
* Deep get a value from an object.
|
|
* @website https://github.com/Salakar/deeps
|
|
* @param object
|
|
* @param path
|
|
* @param joiner
|
|
* @returns {*}
|
|
*/
|
|
// eslint-disable-next-line import/prefer-default-export
|
|
export function deepGet(object, path, joiner = '/') {
|
|
if (!isObject(object) && !Array.isArray(object)) return undefined;
|
|
const keys = path.split(joiner);
|
|
|
|
let i = 0;
|
|
let tmp = object;
|
|
const len = keys.length;
|
|
|
|
while (i < len) {
|
|
const key = keys[i++];
|
|
if (!tmp || !Object.hasOwnProperty.call(tmp, key)) return undefined;
|
|
tmp = tmp[key];
|
|
}
|
|
|
|
return tmp;
|
|
}
|