microdata-minimal
v1.0.2
Published
A simple library to get HTML5 microdata in a structured way
Readme
Microdata Minimal
Microdata-Minimal is a lightweight JavaScript library for working with microdata in HTML documents. It provides simple extractraction of structured data from web pages for node.js
Installation
Install the library using npm:
npm install microdata-minimalUsage
Mostly, take a look at the tests.
Example
import { microdata } from './index.mjs';
// Example HTML string with microdata
const html = `
<div itemscope itemtype="http://schema.org/Person">
<span itemprop="name">John Doe</span>
</div>
`;
// Parse the microdata
const data = microdata(html);
console.log(data);
// Output:
// {
// "@type": "Person",
// "@context": "http://schema.org/",
// "name": "John Doe",
// }API
microdata
Extract microdata from HTML. Takes an HTML string and optionally, either an array with a list of selectors that limits the selection, or an options object that can contain a limiter property that does the same. The options object can also contain a base property to help fully qualify relative URLs. Returns an array of objects, each representing an item with its properties.
Parameters
Returns Array<Object> An array of extracted microdata objects.
Testing
To run the tests, use the following command:
npm testThe tests are located in the test/ directory, with test/00-basic.mjs providing a basic example of how the library works.
License
This project is licensed under the MIT License. See the LICENSE file for details.
