0.0.1 • Published 10 years ago
head-parser v0.0.1
Head Parser
Parse the <head>
of documents to get the <title>
, <meta
, and <link>
elements.
Example
var parse = require('head-parser')
var request = require('request')
var req = request('https://github.com/')
parse(req, function (err, res) {
req.destroy() // destroy the request since we only need to read the <head>
res.title === 'GitHub · Build software better, together.'
res.meta[0] === {
charset: 'utf-8'
}
res.links[0] === {
rel: 'search',
type: 'application/opensearchdescription+xml',
href: '/opensearch.xml',
title: 'GitHub'
}
})
API
parse(stream, done)
Parses the stream
. Since it only reads the <head>
of the stream, you can destroy it once the callback is executed.
done
returns:
err
-streams
's errors are propagated here untildone
is executed. Also returns any parsing errors while parsing the<head>
.obj
- An object with the results:title
- the<title>
of the document, if anymeta[]
- an array of meta element attributeslinks[]
- an array of link element attributes