Last active
March 8, 2022 14:58
-
-
Save JamesGelok/4f3b72c35d72c6c3dd62dd382f08dcd2 to your computer and use it in GitHub Desktop.
Creates a function to get path from the current collection
This file contains hidden or 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
| import _ from "lodash"; | |
| /** | |
| * Creates a function to get path from the current collection. | |
| * | |
| * @example | |
| * ```ts | |
| * const getEnglishTitle = getterOf("title.en") | |
| * const en = getEnglishTitle({ title: { en: "Hi", es: "Hola" } }) | |
| * // en === "Hi" | |
| * ``` | |
| * | |
| * @param {string} path - The path to child of the current collection. | |
| * @returns {function} A function that returns member specified by the path. | |
| */ | |
| export const getterOf = _.curryRight(_.get, 2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment