head-parser

0.0.1 • Public • Published

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 until done is executed. Also returns any parsing errors while parsing the <head>.
  • obj - An object with the results:
    • title - the <title> of the document, if any
    • meta[] - an array of meta element attributes
    • links[] - an array of link element attributes

Readme

Keywords

none

Package Sidebar

Install

npm i head-parser

Weekly Downloads

1

Version

0.0.1

License

MIT

Last publish

Collaborators

  • jongleberry