Files
memecoin-botV2/.pnpm-store/v10/files/34/e14952482a7cd4968c8333449423c5ce003d49d8870b8ed90eb4c5791ffdf41b68cb360525aa4634107c3176c05e7ff54327beef70f196ca26b7c84e1678da

31 lines
841 B
Plaintext

'use strict'
module.exports = getPropertyValue
const splitPropertyKey = require('./split-property-key')
/**
* Gets a specified property from an object if it exists.
*
* @param {object} obj The object to be searched.
* @param {string|string[]} property A string, or an array of strings, identifying
* the property to be retrieved from the object.
* Accepts nested properties delimited by a `.`.
* Delimiter can be escaped to preserve property names that contain the delimiter.
* e.g. `'prop1.prop2'` or `'prop2\.domain\.corp.prop2'`.
*
* @returns {*}
*/
function getPropertyValue (obj, property) {
const props = Array.isArray(property) ? property : splitPropertyKey(property)
for (const prop of props) {
if (!Object.prototype.hasOwnProperty.call(obj, prop)) {
return
}
obj = obj[prop]
}
return obj
}