# node-trumpet
**Repository Path**: mirrors_regular/node-trumpet
## Basic Information
- **Project Name**: node-trumpet
- **Description**: parse and transform streaming html using css selectors
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2020-09-25
- **Last Updated**: 2026-05-17
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# trumpet
parse and transform streaming html using css selectors
[](http://travis-ci.org/substack/node-trumpet)

# example
## table
input html:
``` html
blah blah blah
| there |
| it |
| is |
```
``` js
var trumpet = require('trumpet');
var tr = trumpet();
tr.pipe(process.stdout);
var ws = tr.select('tbody').createWriteStream();
ws.end('| rawr |
');
var fs = require('fs');
fs.createReadStream(__dirname + '/html/table.html').pipe(tr);
```
output:
``` html
```
## read all
input html:
``` html
beep
¡¡¡
tacos
y
burritos
!!!
```
``` js
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:
``` html
tacos y burritos
```
# methods
``` js
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](http://www.w3.org/TR/CSS2/selector.html) 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](http://npmjs.org) do:
```
npm install trumpet
```
# license
MIT