Function property

  • Creates a function that returns the value at path of a given object.

    Type Parameters

    • Property extends PropertyKey
    • Fallback = undefined

    Parameters

    • path: Property

      The path of the property to get.

    • Optional fallback: Fallback

      The fallback value in case of not finding the value of the desired property.

    Returns PropertyAccessorT<Property, Fallback>

    The new accessor function.

    Since

    1.0.0

    Example

    const fn = property("foo"); // => (value) => get(value, "foo");

    fn({ foo: "bar" }); // => "bar"

    Example

    const fn = property("foo.bar", 0); // => (value) => get(value, "foo.bar", 0);

    fn({ foo: "bar" }); // => 0