-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lodash: Remove from blocks package (#51703)
- Loading branch information
Showing
5 changed files
with
33 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Helper util to return a value from a certain path of the object. | ||
* Path is specified as either: | ||
* - a string of properties, separated by dots, for example: "x.y". | ||
* - an array of properties, for example `[ 'x', 'y' ]`. | ||
* You can also specify a default value in case the result is nullish. | ||
* | ||
* @param {Object} object Input object. | ||
* @param {string|Array} path Path to the object property. | ||
* @param {*} defaultValue Default value if the value at the specified path is nullish. | ||
* @return {*} Value of the object property at the specified path. | ||
*/ | ||
export const getValueFromObjectPath = ( object, path, defaultValue ) => { | ||
const normalizedPath = Array.isArray( path ) ? path : path.split( '.' ); | ||
let value = object; | ||
normalizedPath.forEach( ( fieldName ) => { | ||
value = value?.[ fieldName ]; | ||
} ); | ||
return value ?? defaultValue; | ||
}; |