Skip to content

Select a property and replace inside an object

License

Notifications You must be signed in to change notification settings

jamen/pull-prop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pull-prop

Map an object's property with a stream

pull(
  values([
    { foo: { bar: 123 } },
    { foo: { bar: 321 } },
    { foo: { bar: 333 } }
  ]),
  prop('foo.bar', () => pull(
    map(bar => bar * 3)
  ))
  drain(obj => {
    // ...
  })
)

Install

npm install --save pull-property

# with yarn
yarn add pull-property

Usage

prop(name, transform)

A through stream that takes and gives objects, replacing a certain property on them.

  • name: The property you are mapping (resolved by object-path)
  • transform: A function that returns a through stream, which maps the property

An psuedo example with pull-files:

pull(
  read('lib/**/*.js'),
  // Map `data` with buf -> buf streams:
  prop('data', () => pull(
    map(babel.transformSync),
    map(uglify.compileSync),
    // ...
  )),
  write('out', err => {
    if (err) throw err
  })
)

Maintained by Jamen Marz (See on Twitter and GitHub for questions & updates)

About

Select a property and replace inside an object

Resources

License

Stars

Watchers

Forks

Packages

No packages published