npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@contrast/trumpet

v1.8.0

Published

parse and transform streaming html using css selectors

Downloads

11

Readme

trumpet

parse and transform streaming html using css selectors

build status

trumpet

example

table

input html:

<table>
  <tbody>blah blah blah</tbody>
  <tr><td>there</td></tr>
  <tr><td>it</td></tr>
  <tr><td>is</td></tr>
</table>
var trumpet = require('trumpet');
var tr = trumpet();
tr.pipe(process.stdout);
 
var ws = tr.select('tbody').createWriteStream();
ws.end('<tr><td>rawr</td></tr>');

var fs = require('fs');
fs.createReadStream(__dirname + '/html/table.html').pipe(tr);

output:

<table>
  <tbody><tr><td>rawr</td></tr></tbody>
  <tr><td>there</td></tr>
  <tr><td>it</td></tr>
  <tr><td>is</td></tr>
</table>

read all

input html:

<html>
  <head>
    <title>beep</title>
  </head>
  <body>
    <div class="a">¡¡¡</div>
    <div class="b">
      <span>tacos</span>
      <span> y </span>
      <span>burritos</span>
    </div>
    <div class="a">!!!</div>
  </body>
</html>
var trumpet = require('trumpet');
var tr = trumpet();

tr.selectAll('.b span', function (span) {
    span.createReadStream().pipe(process.stdout);
});

var fs = require('fs');
fs.createReadStream(__dirname + '/html/read_all.html').pipe(tr);

output:

tacos y burritos

methods

var trumpet = require('trumpet')

var tr = trumpet(opts)

Create a new trumpet stream. This stream is readable and writable. Pipe an html stream into tr and get back a transformed html stream.

Parse errors are emitted by tr in an 'error' event.

var elem = tr.select(selector)

Return a result object elem for the first element matching selector.

tr.selectAll(selector, function (elem) {})

Get a result object elem for every element matching selector.

elem.getAttribute(name, cb)

When the selector for elem matches, query the case-insensitive attribute called name with cb(value).

Returns elem.

elem.getAttributes(name, cb)

Get all the elements in cb(attributes) as an object attributes with lower-case keys.

Returns elem.

elem.setAttribute(name, value)

When the selector for elem matches, replace the case-insensitive attribute called name with value.

If the attribute doesn't exist, it will be created in the output stream.

Returns elem.

elem.removeAttribute(name)

When the selector for elem matches, remove the attribute called name if it exists.

Returns elem.

elem.createReadStream(opts)

Create a new readable stream with the inner html content under elem.

To use the outer html content instead of the inner, set opts.outer to true.

elem.createWriteStream(opts)

Create a new write stream to replace the inner html content under elem.

To use the outer html content instead of the inner, set opts.outer to true.

elem.createStream(opts)

Create a new readable writable stream that outputs the content under elem and replaces the content with the data written to it.

To use the outer html content instead of the inner, set opts.outer to true.

tr.createStream(sel, opts)

Short-hand for tr.select(sel).createStream(opts).

tr.createReadStream(sel, opts)

Short-hand for tr.select(sel).createReadStream(opts).

tr.createWriteStream(sel, opts)

Short-hand for tr.select(sel).createWriteStream(opts).

attributes

elem.name

The element name as a lower-case string. For example: 'div'.

selector syntax

Presently these css selectors work:

  • E
  • E F
  • E > F
  • E + F
  • E.class
  • E#id
  • E[attr=value]
  • E[attr~=search]
  • E[attr|=prefix]
  • E[attr^=prefix]
  • E[attr$=suffix]
  • E[attr*=search]

install

With npm do:

npm install trumpet

license

MIT