Licence
MIT
Version
0.1.1
Deps
1
Size
41 kB
Vulns
0
Weekly
0
workthru
Recursively walks the input in a depth-first search manner and transforms value as needed.
How to use
import { workthru } from 'workthru';
const result = workthru(
{
first: [1, 2],
second: 3
},
value => (typeof value === 'number' ? value * 2 : value)
);
// Transformer will be called 5 times:
// - { first: [1, 2], second: 3 }
// - [1, 2]
// - 1
// - 2
// - 3
// Result will be `{ first: [2, 4], second: 6 }`.
API
function workthru(target: any, transformer: (value: any) => any): any;
Behaviors
Does it support recursive objects?
Yes, all recursive values will only be traversed once. If the value is being transformed during traversal, all instances will also be transformed to the same value.
Contributions
Like us? Star us.
Want to make it better? File us an issue.
Don't like something you see? Submit a pull request.