@flex-development/mark-util-chunked
v1.0.0
Published
mark utility to splice and push into giant arrays
Downloads
157
Maintainers
Readme
mark-util-chunked
mark utility to splice and push into giant arrays.
Contents
What is this?
This package exposes algorithms for splicing and pushing into giant arrays.
When should I use this?
This package is useful when creating your own your own mark extensions and utilities.
Install
This package is ESM only.
In Node.js with yarn:
yarn add @flex-development/mark-util-chunkedIn Deno with esm.sh:
import { push, splice } from 'https://esm.sh/@flex-development/mark-util-chunked'In browsers with esm.sh:
<script type="module">
import { push, splice } from 'https://esm.sh/@flex-development/mark-util-chunked'
</script>Use
import { push, splice } from '@flex-development/mark-util-chunked'
import { ev } from '@flex-development/mark-util-symbol'
import type { Token } from '@flex-development/mark'
// ...
const token: Token = events[open][1]
// ...
next = push(next, [[ev.enter, token, context], [ev.exit, token, context]])
// ...
splice(events, open - 1, index - open + 3, next)
// ...API
This package exports the identifiers push and splice.
There is no default export.
push<T>(list, items)
Append items to the end of list.
Items are added in batches to prevent V8 from hanging.
When list is empty, items is returned to prevent a potentially expensive operation.
Type Parameters
T(any) — The list item type
Parameters
list(T[]) — the list to operate onitems(T[]) — the items to inject intolist
Returns
(T[]) items when list is empty, list with appended items otherwise
splice<T>(list, start, remove[, items])
Like Array#splice, but smarter.
Remove items from list and, if necessary, insert new items in their place, returning the deleted elements.
👉 Note:
Array#splicetakes all items to be inserted as individual arguments which causes a stack overflow in V8 when trying to insert a large number of items (i.e. 100k).
Type Parameters
T(any) — The list item type
Parameters
list(T[]) — the list to operate onstart(Numeric|number) — the index inlistto remove and/or insert items at (can be negative)remove(Numeric|number) — the number of items to removeitems(List<T>|null|undefined, optional) — the items to inject intolist
Returns
(T[]) The list of removed items
Types
This package is fully typed with TypeScript. It exports no additional types.
Project
Version
mark-util-chunked adheres to semver.
Contribute
See CONTRIBUTING.md.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.
Sponsor
Small primitives power larger systems. Support long-term stability by sponsoring Flex Development.
Related
@flex-development/mark— the specification@flex-development/mark-compiler— finite state machine event compiler@flex-development/mark-parser— finite state machine parser
