Socket
Socket
Sign inDemoInstall

hyperstream

Package Overview
Dependencies
8
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.0 to 0.3.0

95

index.js
var trumpet = require('trumpet');
var through = require('through');
var throughout = require('throughout');
var concat = require('concat-stream');
var upto = require('./lib/upto');
module.exports = function (streamMap) {
if (!streamMap) streamMap = {};
module.exports = function (streams) {
if (!streams) streams = {};
var tr = trumpet();
var output = upto();
var dup = throughout(tr, output);
tr.on('data', function () {});
tr.on('end', function () {
if (!active && stack.length === 0) output.to(-1);
});
var streams = Object.keys(streamMap).reduce(function (acc, key) {
var sm = streamMap[key];
if (sm && typeof sm === 'object') {
var stream = sm.pipe(through());
acc[key] = stream.pause();
Object.keys(streams).forEach(function (key) {
var value = streams[key];
var vstream;
if (typeof value === 'object' && value.pipe) {
vstream = through().pause();
value.pipe(vstream);
}
if (typeof sm === 'function') {
}
if (!sm || typeof sm !== 'object' && typeof sm !== 'function') {
var stream = through();
acc[key] = stream.pause();
var s = String(sm);
if (s.length) stream.queue(s);
stream.queue(null);
}
return acc;
}, {});
var active = false;
var stack = [];
Object.keys(streamMap).forEach(function (key) {
tr.select(key, function (node) {
if (typeof streamMap[key] === 'function') {
node.update(streamMap[key]);
tr.selectAll(key, function (elem) {
if (typeof value === 'string') {
elem.createWriteStream().end(value);
}
else {
onupdate(tr.parser.position);
else if (typeof value === 'object' && value.pipe) {
vstream.pipe(elem.createWriteStream());
vstream.resume();
}
else if (typeof value === 'function') {
var stream = elem.createStream();
stream.pipe(concat(function (body) {
stream.end(value(body.toString('utf8')));
}));
}
});
function onupdate (pos) {
if (active) return stack.push(function () { onupdate(pos) });
streams[key].pipe(through(
function (buf) {
if (buf.length) output.queue(buf)
},
function () {
active = false;
if (stack.length) {
stack.shift()()
}
else output.to(-1)
}
));
active = true;
output.to(pos);
process.nextTick(function () {
streams[key].resume();
});
}
});
dup.select = tr.select.bind(tr);
dup.update = tr.update.bind(tr);
dup.remove = tr.remove.bind(tr);
dup.replace = tr.replace.bind(tr);
return dup;
return tr;
};
{
"name" : "hyperstream",
"version" : "0.2.0",
"version" : "0.3.0",
"description" : "stream html into html at a css selector",
"main" : "index.js",
"dependencies" : {
"trumpet" : "~0.4.0",
"trumpet" : "~1.5.0",
"duplexer" : "~0.0.2",

@@ -9,0 +9,0 @@ "through" : "~2.3.4",

var test = require('tap').test;
var hyperstream = require('../');
var Stream = require('stream');
var through = require('through');
var concat = require('concat-stream');

@@ -17,7 +18,5 @@ var fs = require('fs');

});
var data = '';
hs.on('data', function (buf) { data += buf });
hs.on('end', function () {
t.equal(data, expected);
});
hs.pipe(concat(function (src) {
t.equal(src.toString('utf8'), expected);
}));

@@ -29,10 +28,9 @@ var rs = fs.createReadStream(__dirname + '/az_multi/index.html');

function createAzStream () {
var rs = new Stream;
rs.readable = true;
var rs = through();
var ix = 0;
var iv = setInterval(function () {
rs.emit('data', String.fromCharCode(97+ix));
rs.queue(String.fromCharCode(97+ix));
if (++ix === 26) {
clearInterval(iv);
rs.emit('end');
rs.queue(null);
}

@@ -39,0 +37,0 @@ }, 25);

@@ -17,3 +17,3 @@ var test = require('tap').test;

rs.pipe(hs).pipe(concat(function (src) {
t.equal(src, [
t.equal(src.toString(), [
'<div class="a">' + Array(SIZE).join('THEBEST') + '</div>',

@@ -20,0 +20,0 @@ '<div class="b">onetwothreefourfive</div>'

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc