https://github.com/jamen/pull-prop
Select a property and replace inside an object
https://github.com/jamen/pull-prop
Last synced: about 1 year ago
JSON representation
Select a property and replace inside an object
- Host: GitHub
- URL: https://github.com/jamen/pull-prop
- Owner: jamen
- License: mit
- Created: 2017-05-08T13:20:08.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-05-08T14:06:33.000Z (about 9 years ago)
- Last Synced: 2025-03-09T19:35:53.036Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# pull-prop
> Map an object's property with a stream
```js
pull(
values([
{ foo: { bar: 123 } },
{ foo: { bar: 321 } },
{ foo: { bar: 333 } }
]),
prop('foo.bar', () => pull(
map(bar => bar * 3)
))
drain(obj => {
// ...
})
)
```
## Install
```sh
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`](https://www.npmjs.com/package/object-path))
- `transform`: A function that returns a through stream, which maps the property
An psuedo example with [`pull-files`](https://npmjs.com/pull-files):
```js
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](https://git.io/jamen) (See on [Twitter](https://twitter.com/jamenmarz) and [GitHub](https://github.com/jamen) for questions & updates)