Skip to content

Instantly share code, notes, and snippets.

@JamesGelok
Last active March 8, 2022 14:58
Show Gist options
  • Select an option

  • Save JamesGelok/4f3b72c35d72c6c3dd62dd382f08dcd2 to your computer and use it in GitHub Desktop.

Select an option

Save JamesGelok/4f3b72c35d72c6c3dd62dd382f08dcd2 to your computer and use it in GitHub Desktop.
Creates a function to get path from the current collection
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