Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

microdata-node

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

microdata-node

Cheerio based microdata parser

  • 0.0.18
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8.5K
increased by16.12%
Maintainers
1
Weekly downloads
 
Created
Source

microdata-node Build Status

Cheerio based microdata parser. Aims to be compatible with http://www.w3.org/TR/microdata/#json.

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

Example:

var cheerio = require('cheerio');
var microdata = require('microdata-node');

var $ = cheerio.load(
  '<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 result = microdata.parse($, null, {
  base: 'http://www.example.com'
});
console.log(JSON.stringify(result, null, 2));

Output:

{
  "items": [
    {
      "type": [ "http://schema.org/Person" ],
      "properties": {
        "name": [ "John Doe" ],
        "jobTitle": [ "graduate research assistant" ],
        "affiliation": [ "University of Dreams" ],
        "additionalName": [ "Johnny" ],
        "url": [ "http://www.johnnyd.com/" ],
        "address": [
          {
            "type": [ "http://schema.org/PostalAddress" ],
            "properties": {
              "streetAddress": [ "1234 Peach Drive" ],
              "addressLocality": [ "Warner Robins" ],
              "addressRegion": [ "Georgia" ]
            }
          }
        ]
      }
    }
  ]
}

API

microdata.parse($, [$nodes], [config])

parses the provided cheerio object with optional configuration.

Optionally specify a subset of nodes to parse. Can be obtained by $('.nodes-to-parse').

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

Keywords

FAQs

Package last updated on 22 Dec 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc