Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork0
playfulprogramming/unist-util-replace-all-between
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
unist utility to modify an existing child list to replace all elements between allinstances of two nodes
npm:
npm install unist-util-replace-all-between
importufrom'unist-builder'importreplaceAllBetweenfrom'unist-util-replace-all-between'consttree=u('root',[u('start','1'),u('node',[u('leaf','2'),u('node',[u('leaf','3')])]),u('end','4'),u('middle','1'),u('start','1'),u('node','2'),u('end','4'),])constnewChildren=replaceAllBetween(tree,{type:'start'},{type:'end'},()=>[u('replaced','1')])console.dir(newChildren,{depth:null})
Yields:
[{type:'replaced',value:'1'},{type:'middle',value:'2'},{type:'replaced',value:'1'},]
Mutate an existing parent's children to reflect function return
Parent's children are only search. None of their children (or further down) are searched
parent(Parent)— Parent to walk through children ofstart(Test) —is-compatible test (such as atype) to find the start of each sectionend(Test) —is-compatible test (such as atype) to find the end of each sectionfunc((nodes:Node[])=>Node[]) — Functionused to change nodes. Return value is then set to the parent.children value
Node[] — List of children fromparent post-mutation
About
Replace section of nodes in Unist parent using selections for start/end
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.