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

mdast-util-mdxjs-esm

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mdast-util-mdxjs-esm - npm Package Compare versions

Comparing version 1.3.1 to 2.0.0

55

index.d.ts
import type {Program} from 'estree-jsx'
import type {Literal as HastLiteral} from 'hast'
import type {Literal as MdastLiteral} from 'mdast'
import type {Data as HastData, Literal as HastLiteral} from 'hast'
import type {Data as MdastData, Literal as MdastLiteral} from 'mdast'

@@ -10,3 +10,2 @@ export {mdxjsEsmFromMarkdown, mdxjsEsmToMarkdown} from './lib/index.js'

*/
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface MdxjsEsm extends MdastLiteral {

@@ -19,18 +18,16 @@ /**

/**
* Data.
* Data associated with mdast MDX.js ESM.
*/
data?: {
/**
* Program node from estree.
*/
// eslint-disable-next-line @typescript-eslint/ban-types
estree?: Program | null | undefined
}
data?: MdxjsEsmData | undefined
}
/**
* Deprecated: use the `MdxjsEsm` type instead.
* Info associated with mdast MDX.js ESM nodes by the ecosystem.
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
export type MDXJSEsm = MdxjsEsm
export interface MdxjsEsmData extends MdastData {
/**
* Program node from estree.
*/
estree?: Program | null | undefined
}

@@ -40,3 +37,2 @@ /**

*/
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface MdxjsEsmHast extends HastLiteral {

@@ -49,16 +45,19 @@ /**

/**
* Data.
* Data associated with hast MDX.js ESM.
*/
data?: {
/**
* Program node from estree.
*/
// eslint-disable-next-line @typescript-eslint/ban-types
estree?: Program | null | undefined
}
data?: MdxjsEsmHastData | undefined
}
/**
* Info associated with hast MDX.js ESM nodes by the ecosystem.
*/
export interface MdxjsEsmHastData extends MdastData {
/**
* Program node from estree.
*/
estree?: Program | null | undefined
}
// Add nodes to mdast content.
declare module 'mdast' {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface FrontmatterContentMap {

@@ -70,2 +69,9 @@ /**

}
interface RootContentMap {
/**
* MDX ESM.
*/
mdxjsEsm: MdxjsEsm
}
}

@@ -75,3 +81,2 @@

declare module 'hast' {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface RootContentMap {

@@ -78,0 +83,0 @@ /**

/**
* @typedef {import('mdast-util-from-markdown').CompileContext} CompileContext
* @typedef {import('mdast-util-from-markdown').Extension} FromMarkdownExtension
* @typedef {import('mdast-util-from-markdown').Handle} FromMarkdownHandle
* Create an extension for `mdast-util-from-markdown` to enable MDX.js ESM in
* markdown.
*
* @typedef {import('mdast-util-to-markdown').Handle} ToMarkdownHandle
* @typedef {import('mdast-util-to-markdown').Options} ToMarkdownExtension
* When using the micromark syntax extension with `addResult`, nodes will have
* a `data.estree` field set to an ESTree [`Program`][program] node.
*
* @typedef {import('estree-jsx').Program} Program
*
* @typedef {import('../index.js').MdxjsEsm} MdxjsEsm
* @returns {FromMarkdownExtension}
* Extension for `mdast-util-from-markdown` to enable MDX.js ESM.
*/
export function mdxjsEsmFromMarkdown(): FromMarkdownExtension
/**
* Extension for `mdast-util-from-markdown` to enable MDX ESM.
* Create an extension for `mdast-util-to-markdown` to enable MDX.js ESM in
* markdown.
*
* When using the syntax extension with `addResult`, nodes will have a
* `data.estree` field set to an ESTree `Program` node.
*
* @type {FromMarkdownExtension}
* @returns {ToMarkdownExtension}
* Extension for `mdast-util-to-markdown` to enable MDX.js ESM.
*/
export const mdxjsEsmFromMarkdown: FromMarkdownExtension
/**
* Extension for `mdast-util-to-markdown` to enable MDX ESM.
*
* @type {ToMarkdownExtension}
*/
export const mdxjsEsmToMarkdown: ToMarkdownExtension
export function mdxjsEsmToMarkdown(): ToMarkdownExtension
export type CompileContext = import('mdast-util-from-markdown').CompileContext

@@ -33,3 +25,2 @@ export type FromMarkdownExtension = import('mdast-util-from-markdown').Extension

export type ToMarkdownExtension = import('mdast-util-to-markdown').Options
export type Program = import('estree-jsx').Program
export type MdxjsEsm = import('../index.js').MdxjsEsm

@@ -9,4 +9,2 @@ /**

*
* @typedef {import('estree-jsx').Program} Program
*
* @typedef {import('../index.js').MdxjsEsm} MdxjsEsm

@@ -16,22 +14,31 @@ */

// To do: next major: expose functions.
import {ok as assert} from 'devlop'
/**
* Extension for `mdast-util-from-markdown` to enable MDX ESM.
* Create an extension for `mdast-util-from-markdown` to enable MDX.js ESM in
* markdown.
*
* When using the syntax extension with `addResult`, nodes will have a
* `data.estree` field set to an ESTree `Program` node.
* When using the micromark syntax extension with `addResult`, nodes will have
* a `data.estree` field set to an ESTree [`Program`][program] node.
*
* @type {FromMarkdownExtension}
* @returns {FromMarkdownExtension}
* Extension for `mdast-util-from-markdown` to enable MDX.js ESM.
*/
export const mdxjsEsmFromMarkdown = {
enter: {mdxjsEsm: enterMdxjsEsm},
exit: {mdxjsEsm: exitMdxjsEsm, mdxjsEsmData: exitMdxjsEsmData}
export function mdxjsEsmFromMarkdown() {
return {
enter: {mdxjsEsm: enterMdxjsEsm},
exit: {mdxjsEsm: exitMdxjsEsm, mdxjsEsmData: exitMdxjsEsmData}
}
}
/**
* Extension for `mdast-util-to-markdown` to enable MDX ESM.
* Create an extension for `mdast-util-to-markdown` to enable MDX.js ESM in
* markdown.
*
* @type {ToMarkdownExtension}
* @returns {ToMarkdownExtension}
* Extension for `mdast-util-to-markdown` to enable MDX.js ESM.
*/
export const mdxjsEsmToMarkdown = {handlers: {mdxjsEsm: handleMdxjsEsm}}
export function mdxjsEsmToMarkdown() {
return {handlers: {mdxjsEsm: handleMdxjsEsm}}
}

@@ -53,5 +60,7 @@ /**

const value = this.resume()
const node = /** @type {MdxjsEsm} */ (this.exit(token))
/** @type {Program | undefined} */
// @ts-expect-error: custom.
const node = this.stack[this.stack.length - 1]
assert(node.type === 'mdxjsEsm')
this.exit(token)
const estree = token.estree

@@ -58,0 +67,0 @@

{
"name": "mdast-util-mdxjs-esm",
"version": "1.3.1",
"version": "2.0.0",
"description": "mdast extension to parse and serialize MDX.js ESM (import/exports)",

@@ -33,7 +33,5 @@ "license": "MIT",

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

@@ -44,12 +42,13 @@ "index.js"

"@types/estree-jsx": "^1.0.0",
"@types/hast": "^2.0.0",
"@types/mdast": "^3.0.0",
"mdast-util-from-markdown": "^1.0.0",
"mdast-util-to-markdown": "^1.0.0"
"@types/hast": "^3.0.0",
"@types/mdast": "^4.0.0",
"devlop": "^1.0.0",
"mdast-util-from-markdown": "^2.0.0",
"mdast-util-to-markdown": "^2.0.0"
},
"devDependencies": {
"@types/node": "^18.0.0",
"@types/node": "^20.0.0",
"acorn": "^8.0.0",
"c8": "^7.0.0",
"micromark-extension-mdxjs-esm": "^1.0.0",
"c8": "^8.0.0",
"micromark-extension-mdxjs-esm": "^2.0.0",
"prettier": "^2.0.0",

@@ -59,5 +58,5 @@ "remark-cli": "^11.0.0",

"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"unist-util-remove-position": "^4.0.0",
"xo": "^0.53.0"
"typescript": "^5.0.0",
"unist-util-remove-position": "^5.0.0",
"xo": "^0.54.0"
},

@@ -68,20 +67,19 @@ "scripts": {

"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node --conditions development test.js",
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
"test-api-prod": "node --conditions production test.js",
"test-api-dev": "node --conditions development test.js",
"test-api": "npm run test-api-dev && npm run test-api-prod",
"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
},
"remarkConfig": {
"plugins": [
"preset-wooorm"
"remark-preset-wooorm"
]

@@ -92,5 +90,19 @@ },

"detail": true,
"strict": true,
"ignoreCatch": true
"ignoreCatch": true,
"strict": true
},
"xo": {
"overrides": [
{
"files": [
"**/*.ts"
],
"rules": {
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/consistent-type-definitions": "off"
}
}
],
"prettier": true
}
}

@@ -20,4 +20,4 @@ # mdast-util-mdxjs-esm

* [API](#api)
* [`mdxjsEsmFromMarkdown`](#mdxjsesmfrommarkdown)
* [`mdxjsEsmToMarkdown`](#mdxjsesmtomarkdown)
* [`mdxjsEsmFromMarkdown()`](#mdxjsesmfrommarkdown)
* [`mdxjsEsmToMarkdown()`](#mdxjsesmtomarkdown)
* [`MdxjsEsm`](#mdxjsesm)

@@ -64,3 +64,3 @@ * [`MdxjsEsmHast`](#mdxjsesmhast)

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][]:

@@ -74,3 +74,3 @@ ```sh

```js
import {mdxjsEsmFromMarkdown, mdxjsEsmToMarkdown} from 'https://esm.sh/mdast-util-mdxjs-esm@1'
import {mdxjsEsmFromMarkdown, mdxjsEsmToMarkdown} from 'https://esm.sh/mdast-util-mdxjs-esm@2'
```

@@ -82,3 +82,3 @@

<script type="module">
import {mdxjsEsmFromMarkdown, mdxjsEsmToMarkdown} from 'https://esm.sh/mdast-util-mdxjs-esm@1?bundle'
import {mdxjsEsmFromMarkdown, mdxjsEsmToMarkdown} from 'https://esm.sh/mdast-util-mdxjs-esm@2?bundle'
</script>

@@ -112,3 +112,3 @@ ```

extensions: [mdxjsEsm({acorn, addResult: true})],
mdastExtensions: [mdxjsEsmFromMarkdown]
mdastExtensions: [mdxjsEsmFromMarkdown()]
})

@@ -118,3 +118,3 @@

const out = toMarkdown(tree, {extensions: [mdxjsEsmToMarkdown]})
const out = toMarkdown(tree, {extensions: [mdxjsEsmToMarkdown()]})

@@ -187,6 +187,6 @@ console.log(out)

### `mdxjsEsmFromMarkdown`
### `mdxjsEsmFromMarkdown()`
Extension for [`mdast-util-from-markdown`][mdast-util-from-markdown] to enable
MDX ESM.
Create an extension for [`mdast-util-from-markdown`][mdast-util-from-markdown]
to enable MDX.js ESM in markdown.

@@ -196,7 +196,17 @@ When using the [micromark syntax extension][extension] with `addResult`, nodes

### `mdxjsEsmToMarkdown`
###### Returns
Extension for [`mdast-util-to-markdown`][mdast-util-to-markdown] to enable MDX
ESM.
Extension for `mdast-util-from-markdown` to enable MDX.js ESM
([`FromMarkdownExtension`][from-markdown-extension]).
### `mdxjsEsmToMarkdown()`
Create an extension for [`mdast-util-to-markdown`][mdast-util-to-markdown]
to enable MDX.js ESM in markdown.
###### Returns
Extension for `mdast-util-to-markdown` to enable MDX.js ESM
([`ToMarkdownExtension`][to-markdown-extension]).
### `MdxjsEsm`

@@ -210,8 +220,12 @@

import type {Program} from 'estree-jsx'
import type {Literal} from 'mdast'
import type {Data, Literal} from 'mdast'
interface MdxjsEsm extends Literal {
type: 'mdxjsEsm'
data?: {estree?: Program | null | undefined}
data?: MdxjsEsmData | undefined
}
export interface MdxjsEsmData extends Data {
estree?: Program | null | undefined
}
```

@@ -228,8 +242,12 @@

import type {Program} from 'estree-jsx'
import type {Literal} from 'hast'
import type {Data, Literal} from 'hast'
interface MdxjsEsm extends Literal {
interface MdxjsEsmHast extends Literal {
type: 'mdxjsEsm'
data?: {estree?: Program | null | undefined}
data?: MdxjsEsmHastData | undefined
}
export interface MdxjsEsmHastData extends Data {
estree?: Program | null | undefined
}
```

@@ -313,3 +331,3 @@

visit(tree, (node) => {
visit(tree, function (node) {
// `node` can now be an ESM node.

@@ -321,10 +339,13 @@ })

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.
This plugin works with `mdast-util-from-markdown` version 1+ and
`mdast-util-to-markdown` version 1+.
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-util-mdxjs-esm@^2`,
compatible with Node.js 16.
This utility works with `mdast-util-from-markdown` version 2+ and
`mdast-util-to-markdown` version 2+.
## Related

@@ -367,5 +388,5 @@

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

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

[from-markdown-extension]: https://github.com/syntax-tree/mdast-util-from-markdown#extension
[to-markdown-extension]: https://github.com/syntax-tree/mdast-util-to-markdown#options
[dfn-flow-content]: #flowcontent-mdxjs-esm

@@ -430,0 +455,0 @@

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