Registry / serialization / microformats-parser

microformats-parser

JSON →
library2.0.4jsnpmunverified

microformats-parser is a JavaScript library for parsing HTML content to extract microformats v2 data, strictly adhering to the microformats2 parsing specification. It also provides back-compatibility for microformats v1, though with limited support to the official test suite. The library, currently at version 2.0.4, is actively maintained with frequent releases (roughly monthly or bi-monthly) for bug fixes and dependency updates. It supports both Node.js (requiring Node.js >=18) and browser environments. Its primary differentiator is its close adherence to the specification, robust handling of implied properties, and features for resolving relative URLs, making it a reliable choice for Indieweb and semantic web applications.

npm install microformats-parser
INSTALL
IMPORT
SIG · MICROFORMATS-PARSE
M
microformats-parser
serializationjavascriptv2.0.4
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.

mf2
import { mf2 } from 'microformats-parser'
import mf2 from 'microformats-parser'
The primary parsing function is a named export. Default imports are not available.
mf2
const { mf2 } = require('microformats-parser')
const mf2 = require('microformats-parser').mf2
CommonJS `require` is supported, but ensure to destructure the named export.
mf2
import type { MicroformatRoot } from 'microformats-parser'
TypeScript users can import type definitions for the parsed output.

Demonstrates basic parsing of an HTML string containing an h-card microformat, resolving a relative URL with a `baseUrl`.

import { mf2 } from 'microformats-parser'; const htmlString = '<a class="h-card" href="/" rel="me">Jimmy</a>'; const options = { baseUrl: "http://example.com/" // baseUrl is required to resolve relative URLs }; const parsed = mf2(htmlString, options); console.log(JSON.stringify(parsed, null, 2)); // Expected output: // { // "items": [ // { // "properties": { // "name": ["Jimmy"], // "url": ["http://example.com/"] // }, // "type": ["h-card"] // } // ], // "rel-urls": { // "http://example.com/": { // "rels": ["me"], // "text": "Jimmy" // } // }, // "rels": { // "me": ["http://example.com/"] // } // }
Debug
Known issues
breakingNode.js v14 support was dropped in `microformats-parser@2.0.0`. The library now requires Node.js v18 or newer.
fix
Upgrade your Node.js environment to version 18 or higher.
affects: >=2.0.0
gotchaThe `experimental` options (`lang`, `textContent`, `metaformats`) are subject to change without major version updates. Their behavior or availability might be modified in minor or patch releases.
fix
Use experimental options with caution in production environments and monitor release notes for changes if relying on them.
affects: >=1.5.0
gotchaSupport for microformats v1 is limited to the official microformats test suite. While it parses some v1, comprehensive and robust support is focused on microformats v2.
fix
For critical applications, convert v1 microformats to v2 or thoroughly test v1 parsing outcomes.
affects: >=1.0.0
gotchaThe `baseUrl` option is required when calling `mf2()` to correctly resolve relative URLs within the parsed HTML, otherwise URLs may be incomplete or incorrect.
fix
Always provide a valid `baseUrl` string in the options object to ensure accurate URL resolution.
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: require is not defined in ES module scope
Attempting to use CommonJS `require()` syntax within an ES Module (ESM) file.
fix
Change your import statement to `import { mf2 } from 'microformats-parser';`
TypeError: Invalid URL: /some-relative-path
The `baseUrl` option was not provided or was an invalid URL string when parsing HTML with relative links.
fix
Ensure the `options` object passed to `mf2()` includes a valid `baseUrl` string, e.g., `{ baseUrl: 'http://example.com/' }`.
Error: The "html" argument must be of type string. Received type undefined
The first argument to `mf2()` (the HTML string) was not provided or was `undefined`.
fix
Always pass a valid HTML string as the first argument to `mf2()`, e.g., `mf2('<html>...</html>', options)`.
Upgrade
Version history
2.0.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
microformats-parser — npm install microformats-parser · libregistry