Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Parse and transform streaming html using css selectors.
var trumpet = require('trumpet');
var tr = trumpet();
tr.select('.b span', function (node) {
node.html(function (html) {
console.log(node.name + ': ' + html);
});
});
var fs = require('fs');
fs.createReadStream(__dirname + '/select.html').pipe(tr);
<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>
output:
$ node example/select.js
span: tacos
span: y
span: burritos
var trumpet = require('trumpet');
var tr = trumpet();
tr.select('.b span', function (node) {
node.update(function (html) {
return html.toUpperCase();
});
});
tr.select('.c', function (node) {
node.update('---');
});
tr.select('.d', function (node) {
node.remove();
});
var fs = require('fs');
tr.pipe(process.stdout, { end : false });
fs.createReadStream(__dirname + '/update.html').pipe(tr);
<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>
<div class="c">
<span>beep</span>
<span>boop</span>
</div>
<div class="d">
<span>x</span>
<span>y</span>
</div>
</body>
</html>
output:
$ node example/update.js
<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>
<div class="c">---</div>
</body>
</html>
var trumpet = require('trumpet')
Create a new trumpet stream. This stream is readable and writable.
Pipe an html stream into tr
and get back a transformed html stream.
By default, trumpet uses this list of self-closing tags:
[ 'area', 'base', 'basefont', 'br', 'col', 'hr', 'input', 'img', 'link', 'meta' ]
You can specify a custom list by setting opts.special
.
Fire fn(node)
for every element in the html stream that matches the css
selector
.
The nodes are described in the nodes section of this document.
The name of the html element node, such as 'div'
or 'span'
.
An object with all the html attributes.
For example,
<img src="/beep.png" width="32" height="32">
has an attribute object of:
{ src : 'beep.png', width : '32', height : '32' }
Get the inner text and html for the element, which may not have arrived yet.
cb(text)
fires when the inner contents are ready.
Replace the node's inner contents with the string return value from cb(html)
.
Replace the node's inner contents with a string html
.
Replace completely the node's inner context with the string return value from
cb(html)
. The html
will be the inner contents.
Replace completely the node's contents with a string html
.
Remove a node completely from the output stream.
Presently these css selectors work:
With npm do:
npm install trumpet
MIT/X11
FAQs
parse and transform streaming html using css selectors
The npm package trumpet receives a total of 6,178 weekly downloads. As such, trumpet popularity was classified as popular.
We found that trumpet 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
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.