Registry / serialization / very-small-parser

very-small-parser

JSON →
library1.14.0jsnpmunverified

very-small-parser is a lightweight JavaScript parser designed for Markdown, HTML, and inline CSS, operating as a dependency-free solution. It currently sits at version 1.14.0 and maintains a relatively active release cadence, typically pushing minor feature updates and bug fixes every 1-3 months. A key differentiator is its minimal footprint, weighing in at just over 4KB (minified module), making it suitable for performance-sensitive browser environments as well as Node.js applications. It parses Markdown into an MDAST (Markdown Abstract Syntax Tree) compliant structure and HTML into HAST (Hypertext Abstract Syntax Tree), facilitating interoperability with other syntax tree processing tools. It also includes utilities for converting between these ASTs and pretty-printing them back to text.

npm install very-small-parser
INSTALL
IMPORT
SIG · VERY-SMALL-PARSER
V
very-small-parser
serializationjavascriptv1.14.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.

markdown
import { markdown } from 'very-small-parser';
const markdown = require('very-small-parser').markdown;
The primary entry point for Markdown parsing functions. The package is ESM-first.
html
import { html } from 'very-small-parser';
const html = require('very-small-parser').html;
The primary entry point for HTML parsing functions. The package is ESM-first.
toText (Markdown)
import { toText } from 'very-small-parser/lib/markdown/block/toText';
import { toText } from 'very-small-parser';
Utilities like 'toText' are often imported from specific sub-paths, not directly from the main package export. Ensure correct subpath for Markdown AST conversion.
toText (HTML)
import { toText } from 'very-small-parser/lib/html/toText';
import { toText } from 'very-small-parser';
Utilities like 'toText' are often imported from specific sub-paths. Ensure correct subpath for HTML AST conversion.
is
import { is } from 'very-small-parser/lib/markdown/is';
import { is } from 'very-small-parser';
The 'is' utility for Markdown detection must be imported from its specific sub-path.

Demonstrates parsing Markdown to MDAST and HTML to HAST, then converting the ASTs back to their respective string formats, including pretty-printing HTML.

import { markdown, html } from 'very-small-parser'; import { toText as markdownToText } from 'very-small-parser/lib/markdown/block/toText'; import { toText as htmlToText } from 'very-small-parser/lib/html/toText'; // Parse Markdown into MDAST const markdownInput = '## Hello __world__!\n\n- Item 1\n- Item 2'; const mdast = markdown.block.parse(markdownInput); console.log('MDAST:', JSON.stringify(mdast, null, 2)); // Convert MDAST back to Markdown text const restoredMarkdown = markdownToText(mdast); console.log('Restored Markdown:', restoredMarkdown); // Parse HTML into HAST const htmlInput = '<div><p><b>Hello</b> <i>world</i>!</p></div>'; const hast = html.parse(htmlInput); console.log('HAST:', JSON.stringify(hast, null, 2)); // Convert HAST back to HTML text (pretty-printed) const restoredHtml = htmlToText(hast, ' '); // 2 spaces indentation console.log('Restored HTML:\n', restoredHtml);
Debug
Known issues
gotchaThe library's parsing logic may evolve with minor version updates, potentially leading to subtle changes in the generated AST structure or string output for complex or edge-case inputs. While semantic versioning (1.x.x) implies no breaking API changes, the interpretation of non-standard Markdown/HTML can be refined.
fix
Always test parsing outputs with critical content after updates. Consider pinning to exact patch versions if output stability is paramount for your application logic relying on specific AST structures.
affects: >=1.0.0
gotchaSome utility functions (e.g., `toText`, `toHast`, `toMdast`, `is`) are located in deep sub-paths (`/lib/markdown/block/toText`, `/lib/html/toText`, etc.). Importing from incorrect paths will lead to `Module not found` or `undefined` errors.
fix
Refer to the documentation for the exact import path of each specific utility. Use named imports from these specific sub-paths.
affects: >=1.0.0
gotchaThe `markdown` and `html` parsers have different top-level APIs, such as `markdown.block.parse` for block-level Markdown and `markdown.inline.parse` for inline Markdown. HTML parsing is directly `html.parse`.
fix
Ensure you are calling the correct method for the type of content you are parsing. For Markdown, differentiate between `block` and `inline` parsing contexts.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'very-small-parser'
The package has not been installed or is not correctly linked in the project's node_modules.
fix
Run `npm install very-small-parser` or `yarn add very-small-parser` in your project directory.
TypeError: markdown.block.parsef is not a function
This typically occurs when trying to use CommonJS `require()` or when the import path for an ESM module is incorrect, leading to the entire module being imported as a default, or the named export simply not existing in the imported object.
fix
Ensure you are using ESM `import { markdown } from 'very-small-parser';` and running your environment as an ESM module (e.g., `"type": "module"` in `package.json` for Node.js or using a bundler for browser).
TypeError: Cannot read properties of undefined (reading 'parse')
You might be trying to access `markdown.block.parse` when `markdown` itself is undefined, usually due to an incorrect or failed import of the `markdown` object from the package.
fix
Verify that `import { markdown } from 'very-small-parser';` is correctly specified and that the module resolution is working in your environment.
Upgrade
Version history
1.14.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
very-small-parser — npm install very-small-parser · libregistry