tcomb-update-path

1.0.0 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i tcomb-update-path

Weekly Downloads

3

Version

1.0.0

License

MIT

Last publish

Collaborators

  • andytjoslin