$ npm install micromark-util-edit-map
micromark utility to batch changes to lists of events.
This package exposes an algorithm to batch changes to lists of events, needed when authoring complex resolvers, such as for tables or lists.
This package is only useful when you are making your own micromark extensions that need to change many places in lists of events, such as injecting the result of parsing subcontent, or cleaning up how a construct is represented.
This package is ESM only. In Node.js (version 16+), install with npm:
npm install micromark-util-edit-map
In Deno with esm.sh:
import {EditMap} from 'https://esm.sh/micromark-util-edit-map@1'
In browsers with esm.sh:
<script type="module">
import {EditMap} from 'https://esm.sh/micromark-util-edit-map@1?bundle'
</script>
/**
* @import {Event} from 'micromark-util-types'
*/
import {EditMap} from 'micromark-util-edit-map'
/** @type {Array<Event>} */
const events = [] // Assume this is filled.
const editMap = new EditMap()
editMap.add(1, 0, [['enter', events[2][1], events[2][2]]])
editMap.add(2, 1, [])
editMap.consume(events)
This module exports the identifier EditMap.
There is no default export.
EditMap()Create a new edit map.
New instance (EditMap).
EditMap#add(index, remove, add)Create an edit: a remove and/or add at a certain place.
index (number)
— index at which to apply the editremove (number)
— count of items to remove at the indexadd (Array<Event>)
— items to add at the indexNothing (undefined).
EditMap#addBefore(index, remove, add)Create an edit: but insert add before existing additions at index,
instead of after them.
index (number)
— index at which to apply the editremove (number)
— count of items to remove at the indexadd (Array<Event>)
— items to add at the indexNothing (undefined).
EditMap#consume(events)Done, change the events.
events (Array<Event>)
— list of events to apply the edits toNothing (undefined).
This package is fully typed with TypeScript. It exports no additional types.
Projects maintained by the unified collective are compatible with maintained versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line,
micromark-util-edit-map@1, compatible with Node.js 16.
This package works with micromark@4.
This package is safe.
See security.md in micromark/.github for how to
submit a security report.
See contributing.md in micromark/.github for ways
to get started.
See support.md for ways to get help.
This project has a code of conduct. By interacting with this repository, organisation, or community you agree to abide by its terms.
© 2010 - cnpmjs.org x YWFE | Home | YWFE