1.0.0 • Published 7 years ago

tcomb-update-path v1.0.0

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

tcomb-update-path Build Status

Update a tcomb object at a path

For updating bigger objects, it's more convenient to provide a path and an update payload.

The normal tcomb.update signature forces you to provide a deep update object.

This module takes a path array and an update payload and combines them into a tcomb-compatible update.

Install

$ npm install --save tcomb-update-path

Usage

var updatePath = require('tcomb-update-path')
var tcomb = require('tcomb')

var Struct = tcomb.struct({
  foo: tcomb.struct({
    bar: tcomb.String
  })
})

var struct = Struct({
  foo: {bar: 'str'}
})

updatePath(struct, ['foo', 'bar'], {
  $set: 'new str'
})
//=> {foo: {bar: 'new str'}}

API

tcombUpdatePath(tcombInstance, path, action) -> updatedInstance

tcombInstance

An instantiated tcomb type (usually a struct or list).

path

The path to the object being updated. Can be an array or a string dot-path.

action

A valid tcomb update action, which will be done at the given path.

License

MIT © Andrew Joslin