micromark utility to try and parse events w/ acorn
npm install micromark-util-events-to-acorn[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]
[![Sponsors][sponsors-badge]][opencollective]
[![Backers][backers-badge]][opencollective]
[![Chat][chat-badge]][chat]
[micromark][] utility to try and parse events with acorn.
* Install
* Use
* API
* eventsToAcorn(events, options)
* Options
* Result
* Types
* Compatibility
* Security
* Contribute
* License
This package is [ESM only][esm].
In Node.js (version 16+), install with [npm][]:
``sh`
npm install micromark-util-events-to-acorn
In Deno with [esm.sh][esmsh]:
`js`
import {eventsToAcorn} from 'https://esm.sh/micromark-util-events-to-acorn@2'
In browsers with [esm.sh][esmsh]:
`html`
`js
import {eventsToAcorn} from 'micromark-util-events-to-acorn'
// A factory that uses the utility:
/* @type {Tokenizer} /
function factoryMdxExpression(effects, ok, nok) {
return start
// …
// …
// Gnostic mode: parse w/ acorn.
const result = eventsToAcorn(this.events.slice(eventStart), {
acorn,
acornOptions,
start: pointStart,
expression: true,
allowEmpty,
prefix: spread ? '({' : '',
suffix: spread ? '})' : ''
})
// …
// …
}
`
This module exports the identifier [eventsToAcorn][api-events-to-acorn].
There is no default export.
The export map supports the [development condition][development].node --conditions development module.js
Run to get instrumented dev code.
Without this condition, production code is loaded.
###### Parameters
* events (Array)options
— events
* ([Options][api-options])
— configuration (required)
###### Returns
Result ([Result][api-result]).
Configuration (TypeScript type).
###### Fields
* acorn ([Acorn][acorn], required)acorn
— typically , object with parse and parseExpressionAt fieldstokenTypes
* (Array], required)'lineEnding'
— names of (void) tokens to consider as data; is alwaysacornOptions
included
* ([AcornOptions][acorn-options], optional)acorn
— configuration for start
* (Point, optional, required if allowEmpty)prefix
— place where events start
* (string, default: '')suffix
— text to place before events
* (string, default: '')expression
— text to place after events
* (boolean, default: false)allowEmpty
— whether this is a program or expression
* (boolean, default: false)
— whether an empty expression is allowed (programs are always allowed to be
empty)
Result (TypeScript type).
###### Fields
* estree ([Program][program] or undefined)error
— Program
* (Error or undefined)swallow
— error if unparseable
* (boolean)
— whether the error, if there is one, can be swallowed and more JavaScript
could be valid
This package is fully typed with [TypeScript][].
It exports the additional types [Acorn][acorn],AcornOptions
[][acorn-options], [Options][api-options], andResult
[][api-result].
Projects maintained by the unified collective are compatible with maintained
versions of Node.js.
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,
micromark-util-events-to-acorn@^2, compatible with Node.js 16.
This package works with micromark version 3 and later.
This package is safe.
See [contributing.md][contributing] in [micromark/.github][health] for wayssupport.md`][support] for ways to get help.
to get started.
See [
This project has a [code of conduct][coc].
By interacting with this repository, organisation, or community you agree to
abide by its terms.
[MIT][license] © [Titus Wormer][author]
[acorn]: https://github.com/acornjs/acorn
[acorn-options]: https://github.com/acornjs/acorn/blob/96c721dbf89d0ccc3a8c7f39e69ef2a6a3c04dfa/acorn/dist/acorn.d.ts#L16
[api-events-to-acorn]: #eventstoacornevents-options
[api-options]: #options
[api-result]: #result
[author]: https://wooorm.com
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[build]: https://github.com/micromark/micromark-extension-mdx-expression/actions
[build-badge]: https://github.com/micromark/micromark-extension-mdx-expression/workflows/main/badge.svg
[chat]: https://github.com/micromark/micromark/discussions
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[coc]: https://github.com/micromark/.github/blob/main/code-of-conduct.md
[contributing]: https://github.com/micromark/.github/blob/main/contributing.md
[coverage]: https://codecov.io/github/micromark/micromark-extension-mdx-expression
[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark-extension-mdx-expression.svg
[development]: https://nodejs.org/api/packages.html#packages_resolving_user_conditions
[downloads]: https://www.npmjs.com/package/micromark-util-events-to-acorn
[downloads-badge]: https://img.shields.io/npm/dm/micromark-util-events-to-acorn.svg
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[esmsh]: https://esm.sh
[health]: https://github.com/micromark/.github
[license]: https://github.com/micromark/micromark-extension-mdx-expression/blob/main/license
[micromark]: https://github.com/micromark/micromark
[npm]: https://docs.npmjs.com/cli/install
[opencollective]: https://opencollective.com/unified
[program]: https://github.com/estree/estree/blob/master/es2015.md#programs
[size]: https://bundlejs.com/?q=micromark-util-events-to-acorn
[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=micromark-util-events-to-acorn
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[support]: https://github.com/micromark/.github/blob/main/support.md
[typescript]: https://www.typescriptlang.org