GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Janpot/microdata-node: Cheerio based microdata parser

BranchesTags
Open more actions menu

Latest commit

 

History

131 Commits
131 Commits

Folders and files

NameName
Last commit message
Last commit date
scripts
scripts
 
 
src
src
 
 
test
test
 
 
.gitignore
.gitignore
 
 
.jshintignore
.jshintignore
 
 
.jshintrc
.jshintrc
 
 
.npmignore
.npmignore
 
 
.travis.yml
.travis.yml
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 
tsconfig.json
tsconfig.json
 
 

Repository files navigation

microdata-node

Build Status

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:

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

microdata.toJsonld(html, [config])

parses the provided html to jsonld

options

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

config.registry: The 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.

About

Cheerio based microdata parser

Resources

Readme
MIT license
Activity

Stars

57 stars

Watchers

4 watching

Forks

8 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.