Socket
Socket
Sign inDemoInstall

trumpet

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

trumpet - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

example/special.html

13

index.js
var sax = require('sax');
var select = require('./lib/select');
module.exports = function () {
module.exports = function (opts) {
if (!opts) opts = {};
if (!opts.special) {
opts.special = [
'area', 'base', 'basefont', 'br', 'col',
'hr', 'input', 'img', 'link', 'meta'
];
}
opts.special = opts.special.map(function (x) { return x.toUpperCase() });
var parser = sax.parser(false);
var stream = select(parser);
var stream = select(parser, opts);

@@ -8,0 +17,0 @@ function write (buf) {

23

lib/select.js
var Stream = require('stream').Stream;
module.exports = function (parser) {
module.exports = function (parser, opts) {
var stream = new Stream;

@@ -11,3 +11,3 @@ stream.writable = true;

stream.select = function (s, fn) {
var sel = createSelector(s, fn);
var sel = createSelector(s, fn, opts.special);
selectors.push(sel);

@@ -29,5 +29,8 @@ return stream;

var up = sel.updating;
var level = parser.tags.reduce(function (sum, t) {
return sum + (opts.special.indexOf(t.name) < 0 ? 1 : 0);
}, 0);
sel.pending = sel.pending.filter(function (p) {
var done = parser.tags.length < p.level;
var done = level < p.level;
if (done) p.callback.call(stream, p.buffered);

@@ -57,2 +60,10 @@ return !done;

});
for (var i = 0; i < parser.tags.length; i++) {
var t = parser.tags[i];
if (opts.special.indexOf(t.name) >= 0) {
parser.tags.splice(i, 1);
i--;
}
}
}

@@ -83,3 +94,3 @@ else if (name == 'close') {

function createSelector (selector, fn) {
function createSelector (selector, fn, special) {
var parts = selector.split(/([\s>+]+)/).map(function (s) {

@@ -112,3 +123,5 @@ if (s.match(/^\s+$/)) return;

var sel = function (tag, parser) {
var tags = parser.tags;
var tags = parser.tags.filter(function (t) {
return special.indexOf(t.name) < 0;
});
if (depth > tags.length) return;

@@ -115,0 +128,0 @@

{
"name" : "trumpet",
"version" : "0.2.0",
"version" : "0.2.1",
"description" : "parse and transform streaming html using css selectors",

@@ -5,0 +5,0 @@ "main" : "index.js",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc