micromark-util-edit-map
v1.0.0
Published
micromark utility to batch changes to lists of events
Maintainers
Readme
micromark-util-edit-map
micromark utility to batch changes to lists of events.
Contents
What is this?
This package exposes an algorithm to batch changes to lists of events, needed when authoring complex resolvers, such as for tables or lists.
When should I use this?
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.
Install
This package is ESM only. In Node.js (version 16+), install with npm:
npm install micromark-util-edit-mapIn 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>Use
/**
* @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)API
This module exports the identifier EditMap.
There is no default export.
EditMap()
Create a new edit map.
Returns
New instance (EditMap).
EditMap#add(index, remove, add)
Create an edit: a remove and/or add at a certain place.
Parameters
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 index
Returns
Nothing (undefined).
EditMap#addBefore(index, remove, add)
Create an edit: but insert add before existing additions at index,
instead of after them.
Parameters
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 index
Returns
Nothing (undefined).
EditMap#consume(events)
Done, change the events.
Parameters
events(Array<Event>) — list of events to apply the edits to
Returns
Nothing (undefined).
Types
This package is fully typed with TypeScript. It exports no additional types.
Compatibility
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.
Security
This package is safe.
See security.md in micromark/.github for how to
submit a security report.
Contribute
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.
