https://github.com/flex-development/mark-util-chunked
mark utility to splice and push into giant arrays
https://github.com/flex-development/mark-util-chunked
chunk push splice
Last synced: 5 days ago
JSON representation
mark utility to splice and push into giant arrays
- Host: GitHub
- URL: https://github.com/flex-development/mark-util-chunked
- Owner: flex-development
- License: bsd-3-clause
- Created: 2026-07-02T21:18:29.000Z (27 days ago)
- Default Branch: main
- Last Pushed: 2026-07-15T02:28:17.000Z (14 days ago)
- Last Synced: 2026-07-19T10:19:34.687Z (10 days ago)
- Topics: chunk, push, splice
- Language: TypeScript
- Homepage: https://github.com/flex-development/mark-util-chunked
- Size: 2.52 MB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/funding.yml
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# mark-util-chunked
[](https://github.com/flex-development/mark-util-chunked/releases/latest)
[](https://npmjs.com/package/@flex-development/mark-util-chunked)
[](https://www.npmcharts.com/compare/@flex-development/mark-util-chunked?interval=30)
[](https://packagephobia.now.sh/result?p=@flex-development/mark-util-chunked)
[](https://bundlephobia.com/package/@flex-development/mark-util-chunked)
[](https://bundlephobia.com/package/@flex-development/mark-util-chunked)
[](https://codecov.io/gh/flex-development/mark-util-chunked)
[](https://github.com/voxpelli/badges-cjs-esm)
[](LICENSE.md)
[](https://conventionalcommits.org)
[](https://typescriptlang.org)
[](https://vitest.dev)
[](https://yarnpkg.com)
[`mark`][mark] utility to splice and push into giant arrays.
## Contents
- [What is this?](#what-is-this)
- [When should I use this?](#when-should-i-use-this)
- [Install](#install)
- [Use](#use)
- [API](#api)
- [`push(list, items)`][api-push]
- [`splice(list, start, remove[, items])`][api-splice]
- [Types](#types)
- [Project](#project)
- [Version](#version)
- [Contribute](#contribute)
- [Sponsor](#sponsor)
- [Related](#related)
## 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][esm].
In Node.js with [yarn][]:
```sh
yarn add @flex-development/mark-util-chunked
```
See Git - Protocols | Yarn
Β for details regarding installing from Git.
In Deno with [`esm.sh`][esmsh]:
```ts
import { push, splice } from 'https://esm.sh/@flex-development/mark-util-chunked'
```
In browsers with [`esm.sh`][esmsh]:
```html
import { push, splice } from 'https://esm.sh/@flex-development/mark-util-chunked'
```
## Use
```ts
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`][api-push] and [`splice`][api-splice].\
There is no default export.
### `push(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 on
- `items` (`T[]`)
β the items to inject into `list`
#### Returns
(`T[]`) `items` when `list` is empty, `list` with appended items otherwise
### `splice(list, start, remove[, items])`
Like [`Array#splice`][array-splice], but smarter.
Remove items from `list` and, if necessary, insert new `items` in their place, returning the deleted elements.
> π **Note**: `Array#splice` takes 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 on
- `start` ([`Numeric`][numeric] | `number`)
β the index in `list` to remove and/or insert items at (can be negative)
- `remove` ([`Numeric`][numeric] | `number`)
β the number of items to remove
- `items` ([`List`][list] | `null` | `undefined`, optional)
β the items to inject into `list`
#### 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`](CONTRIBUTING.md).
This project has a [code of conduct](CODE_OF_CONDUCT.md).
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`][mark] β the specification
- [`@flex-development/mark-compiler`][mark-compiler] β finite state machine event compiler
- [`@flex-development/mark-parser`][mark-parser] β finite state machine parser
[api-push]: #pushtlist-items
[api-splice]: #splicetlist-start-remove-items
[array-splice]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/splice
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[esmsh]: https://esm.sh
[list]: https://github.com/flex-development/mark/blob/main/src/core/types/list.mts
[mark-compiler]: https://github.com/flex-development/mark-compiler
[mark-parser]: https://github.com/flex-development/mark-tokenizer
[mark]: https://github.com/flex-development/mark
[numeric]: https://github.com/flex-development/mark/blob/main/src/core/types/numeric.mts
[semver]: https://semver.org
[typescript]: https://www.typescriptlang.org
[yarn]: https://yarnpkg.com