Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/angus-c/obj-transform
Generates transform functions to apply to each property of an object
https://github.com/angus-c/obj-transform
Last synced: about 1 month ago
JSON representation
Generates transform functions to apply to each property of an object
- Host: GitHub
- URL: https://github.com/angus-c/obj-transform
- Owner: angus-c
- License: mit
- Created: 2015-11-16T23:00:57.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2015-11-16T23:17:39.000Z (almost 9 years ago)
- Last Synced: 2024-10-02T14:05:47.497Z (about 1 month ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## obj-transform
Generates transform functions to apply to each property of an object
### Usage
```js
// commonJS...
var transform = require('obj-transform');
// ...or es2015
import transform from 'obj-transform';// an incrementing transformer
const increment = transform(x => x + 1);
// enlarge a rectangle
increment({height: 4, width: 3}); // {height: 5, width: 4}
// move south-east
increment({x: 0, y: 0}); // {x: 1, y: 1}
// looping transform
while (inbounds(ball)) {
increment(ball);
}// ad-hoc transform
transform(x => x * x)({a: 1, b: 2, c: 3}); // {a: 1, b: 4, c: 9}// a mixin transformer
var mixin = transform(function(value, key) {return this[key] || value});
mixin({a: 3, b: 9, c: 12}, {a: 1, c: 3}); // { a: 1, b: 9, c: 3 }
```### Install
```
npm install obj-transform
```### API
__Creating a transform function__
```js
transform(_callback_);
```_callback_ is a function that can accept up to three arguments:
**value**
The value for each property in _baseObj_
**key** (optional)
The key for each property in _baseObj_
**baseObj** (optional)
The _baseObj___Using a transform function__
```js
transformFunction(_object_[, _thisValue_]);
```### Tests
```
npm test
```