Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Replace section of nodes in Unist parent using selections for start/end

NotificationsYou must be signed in to change notification settings

playfulprogramming/unist-util-replace-all-between

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

unist utility to modify an existing child list to replace all elements between allinstances of two nodes

Install

npm:

npm install unist-util-replace-all-between

Usage

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'},]

API

replaceAllBetween(parent, start, end, func)

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

Parameters
  • parent (Parent)— Parent to walk through children of
  • start (Test) —is-compatible test (such as atype) to find the start of each section
  • end (Test) —is-compatible test (such as atype) to find the end of each section
  • func ((nodes:Node[])=>Node[]) — Functionused to change nodes. Return value is then set to the parent.children value
Returns

Node[] — List of children fromparent post-mutation

About

Replace section of nodes in Unist parent using selections for start/end

Resources

Stars

Watchers

Forks

Sponsor this project

    Packages

    No packages published

    [8]ページ先頭

    ©2009-2025 Movatter.jp