
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
microformat-node
Advanced tools
microformat-node is a microformats 2 parser built for node.js. The library can parse both versions 1 and 2 of microformats. It is built using a thoroughly tested and fast parsing engine.
Demo API - http://glennjones.net/tools/microformats/
h-adr, h-card, h-entry, h-event, h-geo, h-news, h-product, h-recipe, h-resume, h-review-aggregate, h-review, adr, hCard, hEntry, hEvent, geo, hNews hProduct, hRecipe, hResume, hReview-aggregate, hReview, rel=tag, rel=licence, rel=no-follow, rel=author and XFN
npm install microformat-node
or
git clone http://github.com/glennjones/microformat-node.git
cd microformat-node
npm link
var microformats = require("microformat-node"),
options = {};
microformats.parseUrl('http://glennjones.net/about', options, function(err, data){
// do something with data
});
var microformats = require("microformat-node"),
options = {};
microformats.parseUrl('http://glennjones.net/about', options)
.then(
function (data) {
// do something with data
},
function (error) {
// do something with error
}
)
var microformats = require("microformat-node"),
options = {};
microformats.parseUrl('http://glennjones.net/about', options, function(err, data){
// do something with data
});
var microformats = require("microformat-node"),
options = {};
var html = '<p class="vcard"><a class="fn url" href="http://glennjones.net">Glenn Jones</a></p>';
microformats.parseHtml(html, options, function(err, data){
// do something with data
});
This function takes both a Cheerio DOM and node object.
var microformats = require("microformat-node"),
options = {};
microformats.parseDom(dom, node, options function(err, data){
// do something with data
});
var microformats = require("microformat-node"),
options = {'filters': ['h-card']};
microformats.parseUrl('http://glennjones.net/about', options, function(err, data){
// do something with data
});
Version 0.2.0 was a complete rewrite of microformat-node to conform to the new version 2 specification of microformats. If you used the older 0.1.x versions of microformat-node you will find the JSON output has changed. The output changes were designed to bring it closer to the microdata specification.
Typical data structure. This is an example of a h-card microformat.
{
"items": [{
"type": ["h-card"],
"properties": {
"url": ["http://blog.lizardwrangler.com/"],
"name": ["Mitchell Baker"],
"org": ["Mozilla Foundation"],
"note": ["Mitchell is responsible for setting the direction Mozilla ..."],
"category": ["Strategy", "Leadership"]
}
}]
}
Typical error structure.
{
"errors": [{
"error": "Error: Invalid protocol - xhttp://microformats.org/"
}]
}
microformats-node uses an in-memory cache to store the HTML of web pages.
The options object contains a property called cacheTimeLimit
that can be used to set the cache refresh time. By default, this is 3600000ms. The number of items stored in the cache can be limited using the options property cacheItemLimit
. By default, the cache is limited to 1000 items. The 'useCache' property of the options object is set to false by default.
You can replace the cache with your own, for example, to store the cached data in a database or file system. To add you own custom cache, all you need to do is provide an object containing the following interface:
{
function get (url) {
// add code to get data
returns data
}
function has(url) {
// add code to check your data store
returns true or false
}
function fetch (url, callback) {
// add code to return data
fires callback(null, data);
}
function set(url, data) {
// add code to store data
returns object
}
function setCacheLimits (newCacheTimeLimit, newCacheItemLimit) {
// can be used to collect setting from options
}
}
and then add this interface as the cache
property of the options object passed into the parseUrl()
or parseHtml()
methods.
microformats-node uses a simple logging system that writes to Node's console. You can replace the logger with your own, for example, to store warnings and errors in a database or log file. To add your own custom logger, all you need to do is provide an object containing the following interface:
{
function info (message) { /* code to pass on message */ }
function log (message) { /* code to pass on message */ }
function warn (message) { /* code to pass on message */ }
function error(message) { /* code to pass on message */ }
}
and then add this interface to the logger
property of the options object passed into the parseUrl()
, parseHtml()
or parseDom()
methods.
Start the server binary:
$ bin/microformat-node
Then visit the server URL
http://localhost:8888/
You need to provide the url of the web page:
GET http://localhost:8888/?url=http%3A%2F%2Flocalhost%3A8888%2Ftest%2F
The module includes web pages which runs the microfomats 2 test suite. Once you have started the server using the details above you can view the mocha tests in a browser. If you install mocha you can also run the tests from the command line.
http://localhost:8888/test/mocha-v1.html
http://localhost:8888/test/mocha-v2.html
Having trouble, please raise an issue at: https://github.com/glennjones/microformat-node/issues
The project is open sourced under MIT license. See the license.txt file within the project source.
FAQs
A microformat parser for node.js
The npm package microformat-node receives a total of 827 weekly downloads. As such, microformat-node popularity was classified as not popular.
We found that microformat-node demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.