Socket
Socket
Sign inDemoInstall

micromark-util-chunked

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

micromark-util-chunked - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

20

dev/index.d.ts

@@ -11,7 +11,13 @@ /**

* @template {unknown} T
* @param {T[]} list
* Item type.
* @param {Array<T>} list
* List to operate on.
* @param {number} start
* Index to remove/insert at (can be negative).
* @param {number} remove
* @param {T[]} items
* Number of items to remove.
* @param {Array<T>} items
* Items to inject into `list`.
* @returns {void}
* Nothing.
*/

@@ -32,6 +38,10 @@ export function splice<T extends unknown>(

* @template {unknown} T
* @param {T[]} list
* @param {T[]} items
* @returns {T[]}
* Item type.
* @param {Array<T>} list
* List to operate on.
* @param {Array<T>} items
* Items to add to `list`.
* @returns {Array<T>}
* Either `list` or `items`.
*/
export function push<T extends unknown>(list: T[], items: T[]): T[]

@@ -13,7 +13,13 @@ import {constants} from 'micromark-util-symbol/constants.js'

* @template {unknown} T
* @param {T[]} list
* Item type.
* @param {Array<T>} list
* List to operate on.
* @param {number} start
* Index to remove/insert at (can be negative).
* @param {number} remove
* @param {T[]} items
* Number of items to remove.
* @param {Array<T>} items
* Items to inject into `list`.
* @returns {void}
* Nothing.
*/

@@ -23,3 +29,3 @@ export function splice(list, start, remove, items) {

let chunkStart = 0
/** @type {unknown[]} */
/** @type {Array<unknown>} */
let parameters

@@ -41,6 +47,6 @@

// @ts-expect-error Hush, it’s fine.
;[].splice.apply(list, parameters)
list.splice(...parameters)
} else {
// Delete `remove` items starting from `start`
if (remove) [].splice.apply(list, [start, remove])
if (remove) list.splice(start, remove)

@@ -55,3 +61,3 @@ // Insert the items in chunks to not cause stack overflows.

// @ts-expect-error Hush, it’s fine.
;[].splice.apply(list, parameters)
list.splice(...parameters)

@@ -72,5 +78,9 @@ chunkStart += constants.v8MaxSafeChunkSize

* @template {unknown} T
* @param {T[]} list
* @param {T[]} items
* @returns {T[]}
* Item type.
* @param {Array<T>} list
* List to operate on.
* @param {Array<T>} items
* Items to add to `list`.
* @returns {Array<T>}
* Either `list` or `items`.
*/

@@ -77,0 +87,0 @@ export function push(list, items) {

@@ -11,7 +11,13 @@ /**

* @template {unknown} T
* @param {T[]} list
* Item type.
* @param {Array<T>} list
* List to operate on.
* @param {number} start
* Index to remove/insert at (can be negative).
* @param {number} remove
* @param {T[]} items
* Number of items to remove.
* @param {Array<T>} items
* Items to inject into `list`.
* @returns {void}
* Nothing.
*/

@@ -32,6 +38,10 @@ export function splice<T extends unknown>(

* @template {unknown} T
* @param {T[]} list
* @param {T[]} items
* @returns {T[]}
* Item type.
* @param {Array<T>} list
* List to operate on.
* @param {Array<T>} items
* Items to add to `list`.
* @returns {Array<T>}
* Either `list` or `items`.
*/
export function push<T extends unknown>(list: T[], items: T[]): T[]

@@ -11,7 +11,13 @@ /**

* @template {unknown} T
* @param {T[]} list
* Item type.
* @param {Array<T>} list
* List to operate on.
* @param {number} start
* Index to remove/insert at (can be negative).
* @param {number} remove
* @param {T[]} items
* Number of items to remove.
* @param {Array<T>} items
* Items to inject into `list`.
* @returns {void}
* Nothing.
*/

@@ -21,6 +27,6 @@ export function splice(list, start, remove, items) {

let chunkStart = 0
/** @type {unknown[]} */
/** @type {Array<unknown>} */
let parameters
let parameters // Make start between zero and `end` (included).
// Make start between zero and `end` (included).
if (start < 0) {

@@ -31,17 +37,20 @@ start = -start > end ? 0 : end + start

}
remove = remove > 0 ? remove : 0
remove = remove > 0 ? remove : 0 // No need to chunk the items if there’s only a couple (10k) items.
// No need to chunk the items if there’s only a couple (10k) items.
if (items.length < 10000) {
parameters = Array.from(items)
parameters.unshift(start, remove) // @ts-expect-error Hush, it’s fine.
;[].splice.apply(list, parameters)
parameters.unshift(start, remove)
// @ts-expect-error Hush, it’s fine.
list.splice(...parameters)
} else {
// Delete `remove` items starting from `start`
if (remove) [].splice.apply(list, [start, remove]) // Insert the items in chunks to not cause stack overflows.
if (remove) list.splice(start, remove)
// Insert the items in chunks to not cause stack overflows.
while (chunkStart < items.length) {
parameters = items.slice(chunkStart, chunkStart + 10000)
parameters.unshift(start, 0) // @ts-expect-error Hush, it’s fine.
;[].splice.apply(list, parameters)
parameters.unshift(start, 0)
// @ts-expect-error Hush, it’s fine.
list.splice(...parameters)
chunkStart += 10000

@@ -52,2 +61,3 @@ start += 10000

}
/**

@@ -61,7 +71,10 @@ * Append `items` (an array) at the end of `list` (another array).

* @template {unknown} T
* @param {T[]} list
* @param {T[]} items
* @returns {T[]}
* Item type.
* @param {Array<T>} list
* List to operate on.
* @param {Array<T>} items
* Items to add to `list`.
* @returns {Array<T>}
* Either `list` or `items`.
*/
export function push(list, items) {

@@ -72,4 +85,3 @@ if (list.length > 0) {

}
return items
}
{
"name": "micromark-util-chunked",
"version": "1.0.0",
"version": "1.1.0",
"description": "micromark utility to splice and push with giant arrays",

@@ -40,2 +40,3 @@ "license": "MIT",

"exports": {
"types": "./dev/index.d.ts",
"development": "./dev/index.js",

@@ -48,3 +49,3 @@ "default": "./index.js"

"scripts": {
"build": "rimraf \"*.d.ts\" \"{dev/,lib/}**/*.d.ts\" && tsc && micromark-build && type-coverage"
"build": "micromark-build"
},

@@ -51,0 +52,0 @@ "xo": false,

@@ -11,6 +11,8 @@ # micromark-util-chunked

micromark utility to splice and push with giant arrays.
[micromark][] utility to splice and push with giant arrays.
## Contents
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)

@@ -21,2 +23,4 @@ * [Use](#use)

* [`splice(list, start, remove, items)`](#splicelist-start-remove-items)
* [Types](#types)
* [Compatibility](#compatibility)
* [Security](#security)

@@ -26,5 +30,15 @@ * [Contribute](#contribute)

## What is this?
This package exposes an algorithm to splice for giant arrays, which V8 bugs
out on.
## When should I use this?
This package might be useful when you are making your own micromark extensions.
## Install
[npm][]:
This package is [ESM only][esm].
In Node.js (version 16+), install with [npm][]:

@@ -35,2 +49,16 @@ ```sh

In Deno with [`esm.sh`][esmsh]:
```js
import {push, splice} from 'https://esm.sh/micromark-util-chunked@1'
```
In browsers with [`esm.sh`][esmsh]:
```html
<script type="module">
import {push, splice} from 'https://esm.sh/micromark-util-chunked@1?bundle'
</script>
```
## Use

@@ -57,3 +85,4 @@

This module exports the following identifiers: `push`, `splice`.
This module exports the identifiers [`push`][api-push]
and [`splice`][api-splice].
There is no default export.

@@ -71,8 +100,10 @@

* `list` (`unknown[]`) — List to operate on
* `items` (`unknown[]`) — Items to add to `list`
* `list` (`Array<unknown>`)
— list to operate on
* `items` (`Array<unknown>`)
— items to add to `list`
###### Returns
`list` or `items`
Either `list` or `items` (`Array<unknown>`).

@@ -91,13 +122,32 @@ ### `splice(list, start, remove, items)`

* `list` (`unknown[]`) — List to operate on
* `start` (`number`) — Index to remove/insert at (can be negative)
* `remove` (`number`) — Number of items to remove
* `items` (`unknown[]`) — Items to inject into `list`
* `list` (`Array<unknown>`)
— list to operate on
* `start` (`number`)
— index to remove/insert at (can be negative)
* `remove` (`number`)
— number of items to remove
* `items` (`Array<unknown>`)
— items to inject into `list`
###### Returns
`void`
Nothing (`void`).
## Types
This package is fully typed with [TypeScript][].
It exports no additional types.
## Compatibility
Projects maintained by the unified collective are compatible with all maintained
versions of Node.js.
As of now, that is Node.js 16+.
Our projects sometimes work with older versions, but this is not guaranteed.
This package works with `micromark` version 3+.
## Security
This package is safe.
See [`security.md`][securitymd] in [`micromark/.github`][health] for how to

@@ -134,5 +184,5 @@ submit a security report.

[bundle-size-badge]: https://img.shields.io/bundlephobia/minzip/micromark-util-chunked.svg
[bundle-size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=micromark-util-chunked
[bundle-size]: https://bundlephobia.com/result?p=micromark-util-chunked
[bundle-size]: https://bundlejs.com/?q=micromark-util-chunked

@@ -147,2 +197,6 @@ [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg

[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[esmsh]: https://esm.sh
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg

@@ -158,8 +212,16 @@

[securitymd]: https://github.com/micromark/.github/blob/HEAD/security.md
[securitymd]: https://github.com/micromark/.github/blob/main/security.md
[contributing]: https://github.com/micromark/.github/blob/HEAD/contributing.md
[contributing]: https://github.com/micromark/.github/blob/main/contributing.md
[support]: https://github.com/micromark/.github/blob/HEAD/support.md
[support]: https://github.com/micromark/.github/blob/main/support.md
[coc]: https://github.com/micromark/.github/blob/HEAD/code-of-conduct.md
[coc]: https://github.com/micromark/.github/blob/main/code-of-conduct.md
[typescript]: https://www.typescriptlang.org
[micromark]: https://github.com/micromark/micromark
[api-push]: #pushlist-items
[api-splice]: #splicelist-start-remove-items
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc