Registry / serialization / recma-stringify

recma-stringify

JSON →
library1.0.0jsnpmunverified

The `recma-stringify` package is a `unified` plugin designed to serialize JavaScript Abstract Syntax Trees (ASTs) back into JavaScript code. It operates within the `recma` ecosystem, which focuses on transforming JavaScript ASTs, similar to how `remark` handles Markdown and `rehype` handles HTML. Currently at version `1.0.0`, it is part of an active project with a stable release cadence that generally aligns with Node.js LTS versions, with major releases dropping support for unmaintained Node.js environments. Its primary differentiator is its seamless integration into the `unified` processing pipeline, abstracting the underlying `estree-util-to-js` utility. This allows developers to easily incorporate JavaScript code generation into broader content processing workflows, such as compiling MDX. It does not parse JavaScript itself; for that, it's typically paired with `recma-parse` or used via the overarching `recma` core package.

npm install recma-stringify
INSTALL
IMPORT
SIG · RECMA-STRINGIFY
R
recma-stringify
serializationjavascriptv1.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

recmaStringify
import recmaStringify from 'recma-stringify'
const recmaStringify = require('recma-stringify')
Package is ESM-only and exports a default function. CommonJS `require` will fail.
Options
import type { Options } from 'recma-stringify'
Type import for configuring the plugin.
unified
import { unified } from 'unified'
`recma-stringify` is a unified plugin and requires `unified` for its processing pipeline.

Demonstrates processing an HTML fragment through rehype, converting it to a recma (JS) AST, applying JSX transformations, and then stringifying it to output JSX code. This shows the typical `unified` pipeline usage.

import recmaJsx from 'recma-jsx' import recmaStringify from 'recma-stringify' import rehypeParse from 'rehype-parse' import rehypeRecma from 'rehype-recma' import {unified} from 'unified' async function processHtmlToJsx() { const file = await unified() .use(rehypeParse, {fragment: true}) // Parse HTML fragment .use(rehypeRecma) // Convert HTML AST (hast) to JS AST (esast) .use(recmaJsx) // Transform JS AST for JSX elements .use(recmaStringify) // Serialize the JS AST back to code .process('<p>Hi!<h1>Hello!') // Process the input string console.log(String(file)) } processHtmlToJsx().catch(console.error)
Debug
Known issues
breakingThis package is ESM-only. Direct `require()` statements will result in an `ERR_REQUIRE_ESM` error.
fix
Migrate to ES modules and use `import recmaStringify from 'recma-stringify'`.
affects: >=1.0.0
breakingMajor version releases of `recma-stringify` (and the unified collective) will drop support for unmaintained Node.js versions. Ensure your Node.js runtime is actively supported.
fix
Upgrade Node.js to a currently maintained LTS version (e.g., Node.js 18+ for future major releases).
affects: >=1.0.0
gotchaThe `recma` ecosystem, including `recma-stringify`, works on JavaScript abstract syntax trees. While `recma-stringify` itself generates code, handling and evaluating arbitrary JavaScript can have security implications. Sanitize inputs if they originate from untrusted sources.
fix
Implement robust input validation and sanitization for any user-provided JavaScript or content that feeds into the recma pipeline.
affects: >=1.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module .../node_modules/recma-stringify/index.js from ... not supported.
Attempting to use `require()` to import `recma-stringify`, which is an ES module.
fix
Change your project to use ES Modules (`type: "module"` in package.json) and use `import recmaStringify from 'recma-stringify'`.
TypeError: recmaStringify is not a function
Incorrectly attempting to instantiate `recmaStringify` with `new` or treating a non-function as a function, often in a CJS context or after a failed default import.
fix
Ensure you are using `import recmaStringify from 'recma-stringify'` and passing the imported function directly to `unified().use()`.
TypeError: unified(...).use(...).process is not a function
Missing `await` keyword before `unified().use(...).process(...)` or incorrect chaining in an async context, leading to processing an unresolved Promise.
fix
Always `await` the result of `unified().process()` as it returns a Promise. Ensure the surrounding function is `async`.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
unifiedrequiredCore ecosystem dependency for plugin integration.
Agent activity
2 hits · last 30 days
node
2
Resources
recma-stringify — npm install recma-stringify · libregistry