@unction/computedprop
TypeScript icon, indicating that this package has built-in type declarations

13.15.0 • Public • Published

@unction/computedProp

Tests Stability Dependencies

MapperFunctionType<A, B> => KeyChainType => Array | Set | RecordType<C | B, A> | string => Array | Set | RecordType<C | B, A> | string

Given an object this function will return that object but with a new property, where the value is computed. The computation is given the object you'll be copying.

const computer = ({id, attributes: {username}}) => `${username}#${id}`
const key = "tag"
const payload = {
  id: "1",
  attributes: {
    username: "krainboltgreene"
  }
}

computedProp(computer)(key)(payload)

Would return:

{
  id: "1",
  tag: "krainboltgreene#1",
  attributes: {
    username: "krainboltgreene"
  }
}
const multiKey = ["attributes", "tag"]

computedProp(computer)(key)(payload)

Would return:

{
  id: "1",
  attributes: {
    tag: "krainboltgreene#1",
    username: "krainboltgreene"
  }
}

Readme

Keywords

Package Sidebar

Install

npm i @unction/computedprop

Weekly Downloads

5

Version

13.15.0

License

SEE LICENSE IN LICENSE

Unpacked Size

18.3 kB

Total Files

7

Last publish

Collaborators

  • krainboltgreene