Skip to content

flex-development/mark-util-chunked

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mark-util-chunked

github release npm npm downloads install size minified bundle size tree shaking suppport codecov module type: esm license conventional commits typescript vitest yarn

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-chunked
See Git - Protocols | Yarn  for details regarding installing from Git.

In 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 on
  • items (T[]) — the items to inject into list

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#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 | number) — the index in list to remove and/or insert items at (can be negative)
  • remove (Numeric | number) — the number of items to remove
  • items (List<T> | 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.

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

About

mark utility to splice and push into giant arrays

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Sponsor this project

 

Packages

 
 
 

Contributors