# microdata-node

> Microdata to json and json-ld parser

Latest version **2.0.0** (published 2020-05-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install microdata-node
pnpm add microdata-node
yarn add microdata-node
bun add microdata-node
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2020-05-11 |
| First published | 2014-12-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 35.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 57 |
| Author | Jan Potoms |
| Maintainers | janpotoms |
| Keywords | microdata, parser |

## Links

- npm: https://www.npmjs.com/package/microdata-node
- Repository: https://janpot@github.com/Janpot/microdata-node
- Homepage: https://github.com/Janpot/microdata-node
- Issues: https://github.com/Janpot/microdata-node/issues
- npm.io page: https://npm.io/package/microdata-node

## Dependencies (3)

- [domutils](https://npm.io/package/domutils.md) ^2.1.0
- [htmlparser2](https://npm.io/package/htmlparser2.md) ^4.1.0
- [is-absolute-url](https://npm.io/package/is-absolute-url.md) ^3.0.3

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2020-05-11
- 2.0.0-0 (next) — 2020-05-11
- 1.0.0 — 2018-05-14
- 0.2.1 — 2015-02-08
- 0.2.0 — 2015-02-08
- 0.1.4 — 2015-02-01
- 0.1.3 — 2015-02-01
- 0.1.2 — 2015-01-11
- 0.1.1 — 2015-01-08
- 0.1.0 — 2015-01-08
- 0.0.19 — 2015-01-08
- 0.0.18 — 2014-12-22
- 0.0.17 — 2014-12-22
- 0.0.16 — 2014-12-20
- 0.0.15 — 2014-12-20
- … 14 more at https://npm.io/package/microdata-node/versions

## README

microdata-node
==============

[![Build Status](https://travis-ci.org/Janpot/microdata-node.svg)](https://travis-ci.org/Janpot/microdata-node)

Microdata parser. Aims to be compatible with http://www.w3.org/TR/microdata/#json and http://www.w3.org/TR/microdata-rdf/

Demo over at http://janpot.github.io/microdata-node.

## Example:

```js
var microdata = require('microdata-node');

var html =
  '<section itemscope itemtype="http://schema.org/Person"> ' +
  '  Hello, my name is ' +
  '  <span itemprop="name">John Doe</span>, ' +
  '  I am a ' +
  '  <span itemprop="jobTitle">graduate research assistant</span> ' +
  '  at the ' +
  '  <span itemprop="affiliation">University of Dreams</span>. ' +
  '  My friends call me ' +
  '  <span itemprop="additionalName">Johnny</span>. ' +
  '  You can visit my homepage at ' +
  '  <a href="http://www.JohnnyD.com" itemprop="url">www.JohnnyD.com</a>. ' +
  '  <section itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">' +
  '    I live at ' +
  '    <span itemprop="streetAddress">1234 Peach Drive</span>,' +
  '    <span itemprop="addressLocality">Warner Robins</span>,' +
  '    <span itemprop="addressRegion">Georgia</span>.' +
  '  </section>' +
  '</section>';

var json = microdata.toJson(html, {
  base: 'http://www.example.com'
});
console.log(JSON.stringify(json, null, 2));
/*
{
  "items": [{
    "properties": {
      "address": [{
        "properties": {
          "addressRegion": [ "Georgia" ],
          "addressLocality": [ "Warner Robins" ],
          "streetAddress": [ "1234 Peach Drive" ]
        },
        "type": [ "http://schema.org/PostalAddress" ]
      }],
      "url": [ "http://www.JohnnyD.com" ],
      "additionalName": [ "Johnny" ],
      "affiliation": [ "University of Dreams" ],
      "jobTitle": [ "graduate research assistant" ],
      "name": [ "John Doe" ]
    },
    "type": [ "http://schema.org/Person" ]
  }]
}
*/

var jsonld = microdata.toJsonld(html, {
  base: 'http://www.example.com'
});
console.log(JSON.stringify(jsonld, null, 2));
/*
[{
  "@id": "_:0",
  "@type": [ "http://schema.org/Person" ],
  "http://schema.org/address": [{ "@id": "_:1" }],
  "http://schema.org/url": [{ "@id": "http://www.JohnnyD.com" }],
  "http://schema.org/additionalName": [{ "@value": "Johnny" }],
  "http://schema.org/affiliation": [{ "@value": "University of Dreams" }],
  "http://schema.org/jobTitle": [{ "@value": "graduate research assistant" }],
  "http://schema.org/name": [{ "@value": "John Doe" }]
}, {
  "@id": "_:1",
  "@type": [ "http://schema.org/PostalAddress" ],
  "http://schema.org/addressRegion": [{ "@value": "Georgia" }],
  "http://schema.org/addressLocality": [{ "@value": "Warner Robins" }],
  "http://schema.org/streetAddress": [{ "@value": "1234 Peach Drive" }]
}]
*/
```

## API

    microdata.toJson(html, [config])

parses the provided html to [microdata json](http://www.w3.org/TR/microdata/#json)

    microdata.toJsonld(html, [config])

parses the provided html to [jsonld](http://json-ld.org/)


**options**

`config.base`: Base url to resolve url properties against.

`config.registry`: The [registry](http://www.w3.org/TR/microdata-rdf/#dfn-registry) associates a URI prefix with one or more key-value pairs denoting processor behavior.

`config.useRdfType`: (default `false`) If set to true, `rdf:type` predicates won't be converted to `@type` properties.

`config.strict`: (default `false`) Parse strictly according to spec. Does not try to be forgiving of malformed microdata.

`config.useNativeTypes`: (default `true`) Converts literals that are numbers or booleans to their corresponding JSOn type.

---
_Source: https://npm.io/package/microdata-node · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
