1.1.2 • Published 2 years ago

uinix-fp-props v1.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

uinix-fp-props

Build Coverage Downloads Size

uinix-fp object props utility.


Install

This package is ESM-only and requires Node 12+.

npm install uinix-fp-props

Use

props is a curried function returning the value of the specified object property path.

import {prop} from 'uinix-fp-props';

const x = {
  a: {
    b: {
      c: 'C',
      d: 'D',
    }
  },
  'a.b': 'AB',
};

props('a.b.c')(x); // 'C'
props('a.b.d')(x); // 'D'
props('a')(x); // x.a
props('a.b')(x); // 'AB' (direct property path takes precendence)
props('x.y.z')(x); // undefined

const propsABC = props('a.b.c'); // curried
propsABC(x); // 'C'

API

This package exports the following identifiers: props. There is no default export.

props(k, options)(x) => y

Parameters (curried)
k (string)

An object property path. Supports accessing nested object properties through the convenient "dot" notation.

X (object)

The provided object.

Returns
v (any)

The object value for the specified property.

License

MIT © Chris Zhou