Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mdast-zone

Package Overview
Dependencies
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mdast-zone - npm Package Compare versions

Comparing version 5.1.1 to 6.0.0

4

index.d.ts
export {zone} from './lib/index.js'
export type Handler = import('./lib/index.js').Handler
export type Info = import('./lib/index.js').Info
/**
* Deprecated: use `Info`.
*/
export type ZoneInfo = Info

@@ -6,8 +6,2 @@ /**

/**
* @typedef {Info} ZoneInfo
* Deprecated: use `Info`.
*/
// To do: next major: remove `ZoneInfo.
export {zone} from './lib/index.js'

29

lib/index.d.ts

@@ -5,3 +5,3 @@ /**

*
* @param {Node} node
* @param {Nodes} node
* Tree to search.

@@ -12,11 +12,8 @@ * @param {string} name

* Handle a section.
* @returns {void}
* @returns {undefined}
* Nothing.
*/
export function zone(node: Node, name: string, handler: Handler): void
export type MdastParent = import('mdast').Parent
export type Content = import('mdast').Content
export type Root = import('mdast').Root
export type Node = Root | Content
export type Parent = Extract<Node, MdastParent>
export function zone(node: Nodes, name: string, handler: Handler): undefined
export type Nodes = import('mdast').Nodes
export type Parents = import('mdast').Parents
/**

@@ -27,11 +24,11 @@ * Extra info.

/**
* Parent of the section.
* Parent of the section.
*/
parent: Parent
parent: Parents
/**
* Index of `start` in `parent`.
* Index of `start` in `parent`.
*/
start: number
/**
* Index of `end` in `parent`.
* Index of `end` in `parent`.
*/

@@ -44,6 +41,6 @@ end: number

export type Handler = (
start: Node,
between: Array<Node>,
end: Node,
start: Nodes,
between: Array<Nodes>,
end: Nodes,
info: Info
) => Array<Node | null | undefined> | null | undefined | void
) => Array<Nodes | null | undefined> | null | undefined | void
/**
* @typedef {import('mdast').Parent} MdastParent
* @typedef {import('mdast').Content} Content
* @typedef {import('mdast').Root} Root
* @typedef {import('mdast').Nodes} Nodes
* @typedef {import('mdast').Parents} Parents
*/
/**
* @typedef {Root | Content} Node
* @typedef {Extract<Node, MdastParent>} Parent
*
* @typedef Info
* Extra info.
* @property {Parent} parent
* @property {Parents} parent
* Parent of the section.

@@ -22,11 +18,11 @@ * @property {number} start

* Callback called when a section is found.
* @param {Node} start
* @param {Nodes} start
* Start of section.
* @param {Array<Node>} between
* @param {Array<Nodes>} between
* Nodes between `start` and `end`.
* @param {Node} end
* @param {Nodes} end
* End of section.
* @param {Info} info
* Extra info.
* @returns {Array<Node | null | undefined> | null | undefined | void}
* @returns {Array<Nodes | null | undefined> | null | undefined | void}
* Results.

@@ -46,3 +42,3 @@ *

*
* @param {Node} node
* @param {Nodes} node
* Tree to search.

@@ -53,3 +49,3 @@ * @param {string} name

* Handle a section.
* @returns {void}
* @returns {undefined}
* Nothing.

@@ -60,14 +56,16 @@ */

let level
/** @type {Node | undefined} */
/** @type {Nodes | undefined} */
let marker
/** @type {Parent | undefined} */
/** @type {Parents | undefined} */
let scope
visit(node, (node, index, parent) => {
visit(node, function (node, index, parent) {
const info = commentMarker(node)
const match =
info && info.name === name ? info.attributes.match(/(start|end)\b/) : null
info && info.name === name
? info.attributes.match(/(start|end)\b/)
: undefined
const type = match ? match[0] : undefined
if (parent && index !== null && type) {
if (parent && index !== undefined && type) {
if (!scope && type === 'start') {

@@ -100,3 +98,3 @@ level = 0

// This could be the case if `end` is in `nodes` but no `end` node exists.
/** @type {Array<Node>} */
/** @type {Array<Nodes>} */
const result = []

@@ -110,4 +108,8 @@ let offset = -1

// @ts-expect-error: Assume the correct children are passed.
scope.children.splice(start, index - start + 1, ...result)
scope.children.splice(
start,
index - start + 1,
// @ts-expect-error: Assume the correct children are passed.
...result
)
}

@@ -114,0 +116,0 @@

{
"name": "mdast-zone",
"version": "5.1.1",
"version": "6.0.0",
"description": "mdast utility to treat HTML comments as ranges or markers",

@@ -31,4 +31,3 @@ "license": "MIT",

"type": "module",
"main": "index.js",
"types": "index.d.ts",
"exports": "./index.js",
"files": [

@@ -40,10 +39,10 @@ "lib/",

"dependencies": {
"@types/mdast": "^3.0.0",
"@types/unist": "^2.0.0",
"@types/mdast": "^4.0.0",
"@types/unist": "^3.0.0",
"mdast-comment-marker": "^2.0.0",
"unist-util-visit": "^4.0.0"
"unist-util-visit": "^5.0.0"
},
"devDependencies": {
"@types/node": "^18.0.0",
"c8": "^7.0.0",
"@types/node": "^20.0.0",
"c8": "^8.0.0",
"is-hidden": "^2.0.0",

@@ -56,4 +55,4 @@ "mdast-util-from-markdown": "^1.0.0",

"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"xo": "^0.53.0"
"typescript": "^5.0.0",
"xo": "^0.54.0"
},

@@ -65,28 +64,13 @@ "scripts": {

"test-api": "node --conditions development test/index.js",
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
"test-coverage": "c8 --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run format && npm run test-coverage"
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false
},
"xo": {
"prettier": true,
"rules": {
"max-depth": "off",
"capitalized-comments": "off"
},
"overrides": [
{
"files": "test/**/*.js",
"rules": {
"no-await-in-loop": 0
}
}
]
},
"remarkConfig": {

@@ -100,4 +84,20 @@ "plugins": [

"detail": true,
"ignoreCatch": true,
"strict": true
},
"xo": {
"overrides": [
{
"files": "test/**/*.js",
"rules": {
"no-await-in-loop": 0
}
}
],
"prettier": true,
"rules": {
"max-depth": "off",
"capitalized-comments": "off"
}
}
}

@@ -50,3 +50,3 @@ # mdast-zone

This package is [ESM only][esm].
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
In Node.js (version 16+), install with [npm][]:

@@ -60,3 +60,3 @@ ```sh

```js
import {zone} from 'https://esm.sh/mdast-zone@5'
import {zone} from 'https://esm.sh/mdast-zone@6'
```

@@ -68,3 +68,3 @@

<script type="module">
import {zone} from 'https://esm.sh/mdast-zone@5?bundle'
import {zone} from 'https://esm.sh/mdast-zone@6?bundle'
</script>

@@ -88,5 +88,5 @@ ```

```js
import {zone} from 'mdast-zone'
import {remark} from 'remark'
import {read} from 'to-vfile'
import {remark} from 'remark'
import {zone} from 'mdast-zone'

@@ -101,8 +101,10 @@ const file = await remark()

function myPluginThatReplacesFoo() {
return (tree) => {
zone(tree, 'foo', (start, nodes, end) => [
start,
{type: 'paragraph', children: [{type: 'text', value: 'Bar.'}]},
end
])
return function (tree) {
zone(tree, 'foo', function (start, nodes, end) {
return [
start,
{type: 'paragraph', children: [{type: 'text', value: 'Bar.'}]},
end
]
})
}

@@ -143,3 +145,3 @@ }

Nothing (`void`).
Nothing (`undefined`).

@@ -179,3 +181,3 @@ ### `Handler`

— index of `start` in `parent`
* `end` (`number` or `null`)
* `end` (`number`)
— index of `end` in `parent`

@@ -191,7 +193,10 @@

Projects maintained by the unified collective are compatible with all maintained
Projects maintained by the unified collective are compatible with maintained
versions of Node.js.
As of now, that is Node.js 14.14+ and 16.0+.
Our projects sometimes work with older versions, but this is not guaranteed.
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, `mdast-zone@^6`,
compatible with Node.js 16.
## Security

@@ -256,5 +261,5 @@

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

@@ -261,0 +266,0 @@ [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg

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