bubble-gum-goto
Goes to property in nested object and execute a callback
bubble-gum-goto
is part of bubble-gum-tools, check this here
Install
You can install bubble-gum-goto using npm.
npm install --save bubble-gum-goto
API Reference
Modules
Typedefs
-
actionCallback ⇒
*
-
Callback at the end of the loop
bubble-gum-goto
function
⏏
module.exports(path, fn) ⇒ It receives a input path and a callback(actionCallback), It returns the function _goto, the _goto function receives a target object or target array, when the _goto is called, this navigates the target object or target array using the input path, when it reaches the end of the path, _goto executs the callback and returns the result
Kind: Exported function
Param | Type | Description |
---|---|---|
path | Array |
Path to property |
fn | actionCallback |
Callback with the action that will be called at the end of the path |
Example
const goto = require('bubble-gum-goto');
const target = {
root: {
foo: 'bar',
},
};
goto(['root', 'foo'], (result) => {
const {
indexPath,
previous,
target,
current,
key,
} = result;
console.log(indexPath); // => 1
console.log(previous); // => { foo: 'bar' }
console.log(target); // => { root: { foo: 'bar' }, arr: [ [ [Object] ] ] }
console.log(current); // => bar
console.log(key); // => foo
})(target);
const result = goto(['root', 'foo'], ({current, key}) => (current + '-' + key))(target);
console.log(result); // => bar-foo
*
actionCallback ⇒ Callback at the end of the loop
Kind: global typedef
Param | Type | Description |
---|---|---|
options | Object |
Values in the end of the path |
options.indexPath | Number |
Current index in the array path |
options.target |
Object | Array
|
Target object or target array |
[options.current] | * |
Current value in target object |
[options.key] | * |
Current value in the path |
[options.previous] | * |
Previous value in target object |
License
MIT @ Nicolas Quiceno