This commit is contained in:
nannal
2020-01-26 21:03:32 +02:00
commit 562b320154
700 changed files with 120537 additions and 0 deletions

1
node_modules/lazy/.npmignore generated vendored Normal file
View File

@@ -0,0 +1 @@
*.swp

185
node_modules/lazy/README.md generated vendored Normal file
View File

@@ -0,0 +1,185 @@
Lazy lists for node
===================
# Table of contents:
[Introduction](#Introduction)
[Documentation](#Documentation)
<a name="Introduction" />
# Introduction
Lazy comes really handy when you need to treat a stream of events like a list.
The best use case currently is returning a lazy list from an asynchronous
function, and having data pumped into it via events. In asynchronous
programming you can't just return a regular list because you don't yet have
data for it. The usual solution so far has been to provide a callback that gets
called when the data is available. But doing it this way you lose the power of
chaining functions and creating pipes, which leads to not that nice interfaces.
(See the 2nd example below to see how it improved the interface in one of my
modules.)
Check out this toy example, first you create a Lazy object:
```javascript
var Lazy = require('lazy');
var lazy = new Lazy;
lazy
.filter(function (item) {
return item % 2 == 0
})
.take(5)
.map(function (item) {
return item*2;
})
.join(function (xs) {
console.log(xs);
});
```
This code says that 'lazy' is going to be a lazy list that filters even
numbers, takes first five of them, then multiplies all of them by 2, and then
calls the join function (think of join as in threads) on the final list.
And now you can emit 'data' events with data in them at some point later,
```javascript
[0,1,2,3,4,5,6,7,8,9,10].forEach(function (x) {
lazy.emit('data', x);
});
```
The output will be produced by the 'join' function, which will output the
expected [0, 4, 8, 12, 16].
And here is a real-world example. Some time ago I wrote a hash database for
node.js called node-supermarket (think of key-value store except greater). Now
it had a similar interface as a list, you could .forEach on the stored
elements, .filter them, etc. But being asynchronous in nature it lead to the
following code, littered with callbacks and temporary lists:
```javascript
var Store = require('supermarket');
var db = new Store({ filename : 'users.db', json : true });
var users_over_20 = [];
db.filter(
function (user, meta) {
// predicate function
return meta.age > 20;
},
function (err, user, meta) {
// function that gets executed when predicate is true
if (users_over_20.length < 5)
users_over_20.push(meta);
},
function () {
// done function, called when all records have been filtered
// now do something with users_over_20
}
)
```
This code selects first five users who are over 20 years old and stores them
in users_over_20.
But now we changed the node-supermarket interface to return lazy lists, and
the code became:
```javascript
var Store = require('supermarket');
var db = new Store({ filename : 'users.db', json : true });
db.filter(function (user, meta) {
return meta.age > 20;
})
.take(5)
.join(function (xs) {
// xs contains the first 5 users who are over 20!
});
```
This is so much nicer!
Here is the latest feature: .lines. Given a stream of data that has \n's in it,
.lines converts that into a list of lines.
Here is an example from node-iptables that I wrote the other week,
```javascript
var Lazy = require('lazy');
var spawn = require('child_process').spawn;
var iptables = spawn('iptables', ['-L', '-n', '-v']);
Lazy(iptables.stdout)
.lines
.map(String)
.skip(2) // skips the two lines that are iptables header
.map(function (line) {
// packets, bytes, target, pro, opt, in, out, src, dst, opts
var fields = line.trim().split(/\s+/, 9);
return {
parsed : {
packets : fields[0],
bytes : fields[1],
target : fields[2],
protocol : fields[3],
opt : fields[4],
in : fields[5],
out : fields[6],
src : fields[7],
dst : fields[8]
},
raw : line.trim()
};
});
```
This example takes the `iptables -L -n -v` command and uses .lines on its output.
Then it .skip's two lines from input and maps a function on all other lines that
creates a data structure from the output.
<a name="Documentation" />
# Documentation
Supports the following operations:
* lazy.filter(f)
* lazy.forEach(f)
* lazy.map(f)
* lazy.take(n)
* lazy.takeWhile(f)
* lazy.bucket(init, f)
* lazy.lines
* lazy.sum(f)
* lazy.product(f)
* lazy.foldr(op, i, f)
* lazy.skip(n)
* lazy.head(f)
* lazy.tail(f)
* lazy.join(f)
The Lazy object itself has a .range property for generating all the possible ranges.
Here are several examples:
* Lazy.range('10..') - infinite range starting from 10
* Lazy.range('(10..') - infinite range starting from 11
* Lazy.range(10) - range from 0 to 9
* Lazy.range(-10, 10) - range from -10 to 9 (-10, -9, ... 0, 1, ... 9)
* Lazy.range(-10, 10, 2) - range from -10 to 8, skipping every 2nd element (-10, -8, ... 0, 2, 4, 6, 8)
* Lazy.range(10, 0, 2) - reverse range from 10 to 1, skipping every 2nd element (10, 8, 6, 4, 2)
* Lazy.range(10, 0) - reverse range from 10 to 1
* Lazy.range('5..50') - range from 5 to 49
* Lazy.range('50..44') - range from 50 to 45
* Lazy.range('1,1.1..4') - range from 1 to 4 with increment of 0.1 (1, 1.1, 1.2, ... 3.9)
* Lazy.range('4,3.9..1') - reverse range from 4 to 1 with decerement of 0.1
* Lazy.range('[1..10]') - range from 1 to 10 (all inclusive)
* Lazy.range('[10..1]') - range from 10 to 1 (all inclusive)
* Lazy.range('[1..10)') - range grom 1 to 9
* Lazy.range('[10..1)') - range from 10 to 2
* Lazy.range('(1..10]') - range from 2 to 10
* Lazy.range('(10..1]') - range from 9 to 1
* Lazy.range('(1..10)') - range from 2 to 9
* Lazy.range('[5,10..50]') - range from 5 to 50 with a step of 5 (all inclusive)
Then you can use other lazy functions on these ranges.

349
node_modules/lazy/lazy.js generated vendored Normal file
View File

@@ -0,0 +1,349 @@
var EventEmitter = require('events').EventEmitter;
var util = require('util');
var stream = require('stream');
function Lazy(em, opts) {
if (!(this instanceof Lazy)) return new Lazy(em, opts);
EventEmitter.call(this);
var self = this;
self.once = function (name, f) {
self.on(name, function g () {
self.removeListener(name, g);
f.apply(this, arguments);
});
}
if (!opts) opts = {};
var dataName = opts.data || 'data';
var pipeName = opts.pipe || 'pipe';
var endName = opts.pipe || 'end';
if (pipeName != endName) {
var piped = false;
self.once(pipeName, function () { piped = true });
self.once(endName, function () {
if (!piped) self.emit(pipeName);
});
}
self.push = function (x) {
self.emit(dataName, x);
}
self.end = function () {
self.emit(endName);
}
if (em && em.on) {
em.on(endName, function () {
self.emit(endName);
});
self.on(pipeName, function () {
em.emit(pipeName);
});
// Check for v0.10 or Greater (Stream2 has Duplex type)
if (stream.Duplex && em instanceof(stream)) {
em.on('readable', function () {
var x = em.read();
self.emit(dataName, x);
});
} else {
// Old Stream1 or Event support
em.on(dataName, function (x) {
self.emit(dataName, x);
});
}
}
function newLazy (g, h, l) {
if (!g) {
g = function () {
return true;
};
}
if (!h) {
h = function (x) {
return x;
};
}
var lazy = new Lazy(null, opts, l);
self.on(dataName, function (x, y) {
if (g.call(lazy, x)) {
lazy.emit(dataName, h(x), y);
}
});
self.once(pipeName, function () {
lazy.emit(pipeName);
});
return lazy;
}
self.filter = function (f) {
return newLazy(function (x) {
return f(x);
});
}
self.forEach = function (f) {
return newLazy(function (x) {
f(x);
return true;
});
}
self.map = function (f) {
return newLazy(
function () { return true },
function (x) { return f(x) }
);
}
self.head = function (f) {
var lazy = newLazy();
lazy.on(dataName, function g (x) {
f(x)
lazy.removeListener(dataName, g)
})
}
self.tail = function () {
var skip = true;
return newLazy(function () {
if (skip) {
skip = false;
return false;
}
return true;
});
}
self.skip = function (n) {
return newLazy(function () {
if (n > 0) {
n--;
return false;
}
return true;
});
}
self.take = function (n) {
return newLazy(function () {
if (n == 0) self.emit(pipeName);
return n-- > 0;
});
}
self.takeWhile = function (f) {
var cond = true;
return newLazy(function (x) {
if (cond && f(x)) return true;
cond = false;
self.emit(pipeName);
return false;
});
}
self.foldr = function (op, i, f) {
var acc = i;
var lazy = newLazy();
lazy.on(dataName, function g (x) {
acc = op(x, acc);
});
lazy.once(pipeName, function () {
f(acc);
});
}
self.sum = function (f) {
return self.foldr(function (x, acc) { return x + acc }, 0, f);
}
self.product = function (f) {
return self.foldr(function (x, acc) { return x*acc }, 1, f);
}
self.join = function (f) {
var data = []
var lazy = newLazy(function (x) {
data.push(x);
return true;
});
lazy.once(pipeName, function () { f(data) });
return self;
}
self.bucket = function (init, f) {
var lazy = new Lazy(null, opts);
var yieldTo = function (x) {
lazy.emit(dataName, x);
};
var acc = init;
self.on(dataName, function (x) {
acc = f.call(yieldTo, acc, x);
});
self.once(pipeName, function () {
lazy.emit(pipeName);
});
// flush on end event
self.once(endName, function () {
var finalBuffer = mergeBuffers(acc);
if (finalBuffer) {
yieldTo(finalBuffer);
}
});
return lazy;
}
// Streams that use this should emit strings or buffers only
self.__defineGetter__('lines', function () {
return self.bucket([], function (chunkArray, chunk) {
var newline = '\n'.charCodeAt(0), lastNewLineIndex = 0;
if (typeof chunk === 'string') chunk = new Buffer(chunk);
if (chunk){
for (var i = 0; i < chunk.length; i++) {
if (chunk[i] === newline) {
// If we have content from the current chunk to append to our buffers, do it.
if (i > 0) {
chunkArray.push(chunk.slice(lastNewLineIndex, i));
}
// Wrap all our buffers and emit it.
this(mergeBuffers(chunkArray));
lastNewLineIndex = i + 1;
}
}
}
if (lastNewLineIndex > 0) {
// New line found in the chunk, push the remaining part of the buffer.
if (lastNewLineIndex < chunk.length) {
chunkArray.push(chunk.slice(lastNewLineIndex));
}
} else {
// No new line found, push the whole buffer.
if (chunk && chunk.length) {
chunkArray.push(chunk);
}
}
return chunkArray;
});
});
}
Lazy.range = function () {
var args = arguments;
var step = 1;
var infinite = false;
if (args.length == 1 && typeof args[0] == 'number') {
var i = 0, j = args[0];
}
else if (args.length == 1 && typeof args[0] == 'string') { // 'start[,next]..[end]'
var arg = args[0];
var startOpen = false, endClosed = false;
if (arg[0] == '(' || arg[0] == '[') {
if (arg[0] == '(') startOpen = true;
arg = arg.slice(1);
}
if (arg.slice(-1) == ']') endClosed = true;
var parts = arg.split('..');
if (parts.length != 2)
throw new Error("single argument range takes 'start..' or 'start..end' or 'start,next..end'");
if (parts[1] == '') { // 'start..'
var i = parts[0];
infinite = true;
}
else { // 'start[,next]..end'
var progression = parts[0].split(',');
if (progression.length == 1) { // start..end
var i = parts[0], j = parts[1];
}
else { // 'start,next..end'
var i = progression[0], j = parts[1];
step = Math.abs(progression[1]-i);
}
}
i = parseInt(i, 10);
j = parseInt(j, 10);
if (startOpen) {
if (infinite || i < j) i++;
else i--;
}
if (endClosed) {
if (i < j) j++;
else j--;
}
}
else if (args.length == 2 || args.length == 3) { // start, end[, step]
var i = args[0], j = args[1];
if (args.length == 3) {
var step = args[2];
}
}
else {
throw new Error("range takes 1, 2 or 3 arguments");
}
var lazy = new Lazy;
var stopInfinite = false;
lazy.on('pipe', function () {
stopInfinite = true;
});
if (infinite) {
process.nextTick(function g () {
if (stopInfinite) return;
lazy.emit('data', i++);
process.nextTick(g);
});
}
else {
process.nextTick(function () {
if (i < j) {
for (; i<j; i+=step) {
lazy.emit('data', i)
}
}
else {
for (; i>j; i-=step) {
lazy.emit('data', i)
}
}
lazy.emit('end');
});
}
return lazy;
}
var mergeBuffers = function mergeBuffers(buffers) {
// We expect buffers to be a non-empty Array
if (!buffers || !Array.isArray(buffers) || !buffers.length) return;
var finalBufferLength, finalBuffer, currentBuffer, currentSize = 0;
// Sum all the buffers lengths
finalBufferLength = buffers.reduce(function(left, right) { return (left.length||left) + (right.length||right); }, 0);
finalBuffer = new Buffer(finalBufferLength);
while(buffers.length) {
currentBuffer = buffers.shift();
currentBuffer.copy(finalBuffer, currentSize);
currentSize += currentBuffer.length;
}
return finalBuffer;
}
util.inherits(Lazy, EventEmitter);
module.exports = Lazy;

348
node_modules/lazy/lazy.js~ generated vendored Normal file
View File

@@ -0,0 +1,348 @@
var EventEmitter = require('events').EventEmitter;
var util = require('util');
var stream = require('stream');
function Lazy(em, opts) {
if (!(this instanceof Lazy)) return new Lazy(em, opts);
EventEmitter.call(this);
var self = this;
self.once = function (name, f) {
self.on(name, function g () {
self.removeListener(name, g);
f.apply(this, arguments);
});
}
if (!opts) opts = {};
var dataName = opts.data || 'data';
var pipeName = opts.pipe || 'pipe';
var endName = opts.pipe || 'end';
if (pipeName != endName) {
var piped = false;
self.once(pipeName, function () { piped = true });
self.once(endName, function () {
if (!piped) self.emit(pipeName);
});
}
self.push = function (x) {
self.emit(dataName, x);
}
self.end = function () {
self.emit(endName);
}
if (em && em.on) {
em.on(endName, function () {
self.emit(endName);
});
self.on(pipeName, function () {
em.emit(pipeName);
});
// Check for v0.10 or Greater (Stream2 has Duplex type)
if (stream.Duplex && em instanceof(stream)) {
em.on('readable', function () {
var x = em.read();
self.emit(dataName, x);
});
} else {
// Old Stream1 or Event support
em.on(dataName, function (x) {
self.emit(dataName, x);
});
}
}
function newLazy (g, h, l) {
if (!g) {
g = function () {
return true;
};
}
if (!h) {
h = function (x) {
return x;
};
}
var lazy = new Lazy(null, opts, l);
self.on(dataName, function (x, y) {
if (g.call(lazy, x)) {
lazy.emit(dataName, h(x), y);
}
});
self.once(pipeName, function () {
lazy.emit(pipeName);
});
return lazy;
}
self.filter = function (f) {
return newLazy(function (x) {
return f(x);
});
}
self.forEach = function (f) {
return newLazy(function (x) {
f(x);
return true;
});
}
self.map = function (f) {
return newLazy(
function () { return true },
function (x) { return f(x) }
);
}
self.head = function (f) {
var lazy = newLazy();
lazy.on(dataName, function g (x) {
f(x)
lazy.removeListener(dataName, g)
})
}
self.tail = function () {
var skip = true;
return newLazy(function () {
if (skip) {
skip = false;
return false;
}
return true;
});
}
self.skip = function (n) {
return newLazy(function () {
if (n > 0) {
n--;
return false;
}
return true;
});
}
self.take = function (n) {
return newLazy(function () {
if (n == 0) self.emit(pipeName);
return n-- > 0;
});
}
self.takeWhile = function (f) {
var cond = true;
return newLazy(function (x) {
if (cond && f(x)) return true;
cond = false;
self.emit(pipeName);
return false;
});
}
self.foldr = function (op, i, f) {
var acc = i;
var lazy = newLazy();
lazy.on(dataName, function g (x) {
acc = op(x, acc);
});
lazy.once(pipeName, function () {
f(acc);
});
}
self.sum = function (f) {
return self.foldr(function (x, acc) { return x + acc }, 0, f);
}
self.product = function (f) {
return self.foldr(function (x, acc) { return x*acc }, 1, f);
}
self.join = function (f) {
var data = []
var lazy = newLazy(function (x) {
data.push(x);
return true;
});
lazy.once(pipeName, function () { f(data) });
return self;
}
self.bucket = function (init, f) {
var lazy = new Lazy(null, opts);
var yieldTo = function (x) {
lazy.emit(dataName, x);
};
var acc = init;
self.on(dataName, function (x) {
acc = f.call(yieldTo, acc, x);
});
self.once(pipeName, function () {
lazy.emit(pipeName);
});
// flush on end event
self.once(endName, function () {
var finalBuffer = mergeBuffers(acc);
if (finalBuffer) {
yieldTo(finalBuffer);
}
});
return lazy;
}
// Streams that use this should emit strings or buffers only
self.__defineGetter__('lines', function () {
return self.bucket([], function (chunkArray, chunk) {
var newline = '\n'.charCodeAt(0), lastNewLineIndex = 0;
if (typeof chunk === 'string') chunk = new Buffer(chunk);
for (var i = 0; i < chunk.length; i++) {
if (chunk[i] === newline) {
// If we have content from the current chunk to append to our buffers, do it.
if (i > 0) {
chunkArray.push(chunk.slice(lastNewLineIndex, i));
}
// Wrap all our buffers and emit it.
this(mergeBuffers(chunkArray));
lastNewLineIndex = i + 1;
}
}
if (lastNewLineIndex > 0) {
// New line found in the chunk, push the remaining part of the buffer.
if (lastNewLineIndex < chunk.length) {
chunkArray.push(chunk.slice(lastNewLineIndex));
}
} else {
// No new line found, push the whole buffer.
if (chunk.length) {
chunkArray.push(chunk);
}
}
return chunkArray;
});
});
}
Lazy.range = function () {
var args = arguments;
var step = 1;
var infinite = false;
if (args.length == 1 && typeof args[0] == 'number') {
var i = 0, j = args[0];
}
else if (args.length == 1 && typeof args[0] == 'string') { // 'start[,next]..[end]'
var arg = args[0];
var startOpen = false, endClosed = false;
if (arg[0] == '(' || arg[0] == '[') {
if (arg[0] == '(') startOpen = true;
arg = arg.slice(1);
}
if (arg.slice(-1) == ']') endClosed = true;
var parts = arg.split('..');
if (parts.length != 2)
throw new Error("single argument range takes 'start..' or 'start..end' or 'start,next..end'");
if (parts[1] == '') { // 'start..'
var i = parts[0];
infinite = true;
}
else { // 'start[,next]..end'
var progression = parts[0].split(',');
if (progression.length == 1) { // start..end
var i = parts[0], j = parts[1];
}
else { // 'start,next..end'
var i = progression[0], j = parts[1];
step = Math.abs(progression[1]-i);
}
}
i = parseInt(i, 10);
j = parseInt(j, 10);
if (startOpen) {
if (infinite || i < j) i++;
else i--;
}
if (endClosed) {
if (i < j) j++;
else j--;
}
}
else if (args.length == 2 || args.length == 3) { // start, end[, step]
var i = args[0], j = args[1];
if (args.length == 3) {
var step = args[2];
}
}
else {
throw new Error("range takes 1, 2 or 3 arguments");
}
var lazy = new Lazy;
var stopInfinite = false;
lazy.on('pipe', function () {
stopInfinite = true;
});
if (infinite) {
process.nextTick(function g () {
if (stopInfinite) return;
lazy.emit('data', i++);
process.nextTick(g);
});
}
else {
process.nextTick(function () {
if (i < j) {
for (; i<j; i+=step) {
lazy.emit('data', i)
}
}
else {
for (; i>j; i-=step) {
lazy.emit('data', i)
}
}
lazy.emit('end');
});
}
return lazy;
}
var mergeBuffers = function mergeBuffers(buffers) {
// We expect buffers to be a non-empty Array
if (!buffers || !Array.isArray(buffers) || !buffers.length) return;
var finalBufferLength, finalBuffer, currentBuffer, currentSize = 0;
// Sum all the buffers lengths
finalBufferLength = buffers.reduce(function(left, right) { return (left.length||left) + (right.length||right); }, 0);
finalBuffer = new Buffer(finalBufferLength);
while(buffers.length) {
currentBuffer = buffers.shift();
currentBuffer.copy(finalBuffer, currentSize);
currentSize += currentBuffer.length;
}
return finalBuffer;
}
util.inherits(Lazy, EventEmitter);
module.exports = Lazy;

60
node_modules/lazy/package.json generated vendored Normal file
View File

@@ -0,0 +1,60 @@
{
"_from": "lazy@>=1.0.3",
"_id": "lazy@1.0.11",
"_inBundle": false,
"_integrity": "sha1-2qBoIGKCVCwIgojpdcKXwa53tpA=",
"_location": "/lazy",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "lazy@>=1.0.3",
"name": "lazy",
"escapedName": "lazy",
"rawSpec": ">=1.0.3",
"saveSpec": null,
"fetchSpec": ">=1.0.3"
},
"_requiredBy": [
"/markov"
],
"_resolved": "https://registry.npmjs.org/lazy/-/lazy-1.0.11.tgz",
"_shasum": "daa068206282542c088288e975c297c1ae77b690",
"_spec": "lazy@>=1.0.3",
"_where": "/home/dabbott/dev/chainy/node_modules/markov",
"author": {
"name": "Peteris Krumins",
"email": "peteris.krumins@gmail.com",
"url": "http://www.catonmat.net"
},
"bugs": {
"url": "https://github.com/pkrumins/node-lazy/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "Lazy lists for node",
"devDependencies": {
"expresso": ">=0.7.5"
},
"engines": {
"node": ">=0.2.0"
},
"homepage": "https://github.com/pkrumins/node-lazy#readme",
"keywords": [
"lazy lists",
"functional"
],
"license": {
"type": "MIT"
},
"main": "./lazy.js",
"name": "lazy",
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/pkrumins/node-lazy.git"
},
"scripts": {
"test": "expresso"
},
"version": "1.0.11"
}

32
node_modules/lazy/package.json~ generated vendored Normal file
View File

@@ -0,0 +1,32 @@
{
"name": "lazy",
"version": "1.0.10",
"description": "Lazy lists for node",
"main": "./lazy.js",
"keywords": [
"lazy lists", "functional"
],
"author": {
"name": "Peteris Krumins",
"email": "peteris.krumins@gmail.com",
"web": "http://www.catonmat.net",
"twitter": "pkrumins"
},
"license": {
"type": "MIT"
},
"repository": {
"type": "git",
"url": "http://github.com/pkrumins/node-lazy.git"
},
"devDependencies" : {
"expresso" : ">=0.7.5"
},
"engines": {
"node": ">=0.2.0"
},
"scripts": {
"test": "expresso"
}
}

37
node_modules/lazy/test/bucket.js generated vendored Normal file
View File

@@ -0,0 +1,37 @@
var assert = require('assert');
var Lazy = require('..');
exports.bucket = function () {
var joined = false;
var lazy = new Lazy;
lazy.bucket('', function splitter (acc, x) {
var accx = acc + x;
var i = accx.indexOf('\n');
if (i >= 0) {
this(accx.slice(0, i));
return splitter.call(this, accx.slice(i + 1), '');
}
return accx;
}).join(function (lines) {
assert.deepEqual(lines, 'foo bar baz quux moo'.split(' '));
joined = true;
});
setTimeout(function () {
lazy.emit('data', 'foo\nba');
}, 50);
setTimeout(function () {
lazy.emit('data', 'r');
}, 100);
setTimeout(function () {
lazy.emit('data', '\nbaz\nquux\nm');
}, 150);
setTimeout(function () {
lazy.emit('data', 'oo');
}, 200);
setTimeout(function () {
lazy.emit('data', '\nzoom');
lazy.emit('end');
assert.ok(joined);
}, 250);
};

52
node_modules/lazy/test/complex.js generated vendored Normal file
View File

@@ -0,0 +1,52 @@
var assert = require('assert');
var Lazy = require('..');
var expresso = expresso;
function range(i, j) {
var r = [];
for (;i<j;i++) r.push(i);
return r;
}
exports['complex'] = function () {
var lazy = new Lazy;
var data1 = [];
var data2 = [];
var data3 = [];
var joinExecuted = false;
lazy
.map(function (x) {
return 2*x;
})
.forEach(function (x) {
data1.push(x);
})
.map(function (x) {
return x/2;
})
.take(5)
.forEach(function (x) {
data2.push(x);
})
.filter(function (x) {
return x % 2 == 0;
})
.forEach(function (x) {
data3.push(x);
})
.join(function (xs) {
joinExecuted = true;
assert.deepEqual(xs, [0, 2, 4]);
});
range(0,10).forEach(function (x) {
lazy.emit('data', x);
});
lazy.emit('end');
assert.deepEqual(data1, range(0,10).map(function (x) { return x*2 }));
assert.deepEqual(data2, range(0,5));
assert.deepEqual(data3, [0, 2, 4]);
assert.ok(joinExecuted);
}

32
node_modules/lazy/test/custom.js generated vendored Normal file
View File

@@ -0,0 +1,32 @@
var assert = require('assert');
var Lazy = require('..');
var expresso = expresso;
function range(i, j) {
var r = [];
for (;i<j;i++) r.push(i);
return r;
}
exports['custom event names'] = function () {
var lazy = new Lazy(null, { data : 'meow', pipe : 'all done' });
var data = [];
var executed = false;
lazy.take(10).join(function (xs) {
assert.deepEqual(xs, range(0,10));
executed = true;
});
var allDone = 0;
lazy.on('all done', function () {
allDone ++;
});
range(0,20).forEach(function (x) {
lazy.emit('meow', x);
});
assert.ok(executed, 'join didn\'t execute');
assert.equal(allDone, 1);
}

33
node_modules/lazy/test/em.js generated vendored Normal file
View File

@@ -0,0 +1,33 @@
var assert = require('assert');
var Lazy = require('..');
var EventEmitter = require('events').EventEmitter;
function range(i, j) {
var r = [];
for (;i<j;i++) r.push(i);
return r;
}
exports.em = function () {
var em = new EventEmitter;
var i = 0;
var iv = setInterval(function () {
em.emit('data', i++);
}, 10);
var caughtDone = 0;
em.on('pipe', function () { caughtDone ++ });
var joined = 0;
Lazy(em).take(10).join(function (xs) {
assert.deepEqual(xs, range(0, 10));
clearInterval(iv);
joined ++;
});
setTimeout(function () {
assert.equal(joined, 1);
assert.equal(caughtDone, 1);
}, 500);
}

27
node_modules/lazy/test/filter.js generated vendored Normal file
View File

@@ -0,0 +1,27 @@
var assert = require('assert');
var Lazy = require('..');
var expresso = expresso;
function range(i, j) {
var r = [];
for (;i<j;i++) r.push(i);
return r;
}
exports['filter'] = function () {
var lazy = new Lazy;
var data = [];
var executed = false;
lazy.filter(function(x) { return x > 5 }).join(function (xs) {
assert.deepEqual(xs, [6,7,8,9]);
executed = true;
});
range(0,10).forEach(function (x) {
lazy.emit('data', x);
});
lazy.emit('pipe');
assert.ok(executed, 'join didn\'t execute');
}

26
node_modules/lazy/test/foldr.js generated vendored Normal file
View File

@@ -0,0 +1,26 @@
var assert = require('assert');
var Lazy = require('..');
var expresso = expresso;
function range(i, j) {
var r = [];
for (;i<j;i++) r.push(i);
return r;
}
exports['foldr'] = function () {
var lazy = new Lazy;
var executed = 0;
lazy.foldr(function (x, acc) { return acc + x; }, 0, function (y) {
executed++;
assert.equal(y, 45);
})
range(0,10).forEach(function (x) {
lazy.emit('data', x);
});
lazy.emit('end');
assert.equal(executed, 1, 'foldr failed to execute');
}

31
node_modules/lazy/test/forEach.js generated vendored Normal file
View File

@@ -0,0 +1,31 @@
var assert = require('assert');
var Lazy = require('..');
var expresso = expresso;
function range(i, j) {
var r = [];
for (;i<j;i++) r.push(i);
return r;
}
exports['forEach'] = function () {
var lazy = new Lazy;
var executed = false;
var data1 = [];
var data2 = [];
lazy
.forEach(function (x) {
data1.push(x);
})
.forEach(function (x) {
data2.push(x);
});
range(0,10).forEach(function (x) {
lazy.emit('data', x);
});
assert.deepEqual(data1, range(0,10));
assert.deepEqual(data2, range(0,10));
}

26
node_modules/lazy/test/head.js generated vendored Normal file
View File

@@ -0,0 +1,26 @@
var assert = require('assert');
var Lazy = require('..');
var expresso = expresso;
function range(i, j) {
var r = [];
for (;i<j;i++) r.push(i);
return r;
}
exports['head'] = function () {
var lazy = new Lazy;
var data = [];
var executed = 0;
lazy.head(function (x) {
assert.equal(x, 0);
executed++;
})
range(0,10).forEach(function (x) {
lazy.emit('data', x);
});
assert.equal(executed, 1, 'head executed too much');
}

26
node_modules/lazy/test/join.js generated vendored Normal file
View File

@@ -0,0 +1,26 @@
var assert = require('assert');
var Lazy = require('..');
var expresso = expresso;
function range(i, j) {
var r = [];
for (;i<j;i++) r.push(i);
return r;
}
exports['join'] = function () {
var lazy = new Lazy;
var data = [];
var executed = false;
lazy.take(10).join(function (xs) {
assert.deepEqual(xs, range(0,10));
executed = true;
});
range(0,20).forEach(function (x) {
lazy.emit('data', x);
});
assert.ok(executed, 'join didn\'t execute');
}

89
node_modules/lazy/test/lines.js generated vendored Normal file
View File

@@ -0,0 +1,89 @@
var assert = require('assert');
var Lazy = require('..');
var EventEmitter = require('events').EventEmitter;
exports['buffered lines'] = function () {
var lazy = Lazy();
var joined = false;
lazy.lines
.forEach(function (line) {
assert.ok(line instanceof Buffer);
assert.ok(!line.toString().match(/\n/));
assert.ok(line.length > 0);
})
.join(function (lines) {
assert.deepEqual(
lines.map(function (x) { return x.toString() }),
'foo bar baz quux moo'.split(' ')
);
joined = true;
});
;
setTimeout(function () {
lazy.push(new Buffer('foo\nbar'));
lazy.push(new Buffer('\nbaz\nquux\nmoo'));
lazy.push(new Buffer(''));
lazy.push(new Buffer('\ndoom'));
lazy.end();
assert.ok(joined);
}, 50);
};
exports['string lines'] = function () {
var lazy = Lazy();
var joined = false;
lazy.lines
.forEach(function (line) {
assert.ok(line instanceof Buffer);
assert.ok(!line.toString().match(/\n/));
assert.ok(line.length > 0);
})
.join(function (lines) {
assert.deepEqual(
lines.map(function (x) { return x.toString() }),
'foo bar baz quux moo'.split(' ')
);
joined = true;
});
;
setTimeout(function () {
lazy.push('foo\nbar');
lazy.push('\nbaz\nquux\nmoo');
lazy.push('');
lazy.push('\ndoom');
lazy.end();
assert.ok(joined);
}, 50);
};
exports.endStream = function () {
var to = setTimeout(function () {
assert.fail('never finished');
}, 2500);
var em = new EventEmitter;
var i = 0;
var lines = [];
Lazy(em).lines.forEach(function (line) {
i ++;
lines.push(line);
if (i == 2) {
clearTimeout(to);
assert.eql(lines.map(String), [ 'foo', 'bar' ]);
}
});
setTimeout(function () {
em.emit('data', 'fo');
}, 100);
setTimeout(function () {
em.emit('data', 'o\nbar');
}, 150);
setTimeout(function () {
em.emit('end');
}, 200);
};

29
node_modules/lazy/test/map.js generated vendored Normal file
View File

@@ -0,0 +1,29 @@
var assert = require('assert');
var Lazy = require('..');
var expresso = expresso;
function range(i, j) {
var r = [];
for (;i<j;i++) r.push(i);
return r;
}
exports['map'] = function () {
var lazy = new Lazy;
var executed = false;
var data = [];
lazy
.map(function (x) {
return 2*x;
})
.forEach(function (x) {
data.push(x);
});
range(0,10).forEach(function (x) {
lazy.emit('data', x);
});
assert.deepEqual(data, range(0,10).map(function (x) { return x*2 }));
}

38
node_modules/lazy/test/pipe.js generated vendored Normal file
View File

@@ -0,0 +1,38 @@
var assert = require('assert');
var Lazy = require('..');
var EventEmitter = require('events').EventEmitter;
function range(i, j) {
var r = [];
for (;i<j;i++) r.push(i);
return r;
}
exports.pipe = function () {
var em = new EventEmitter;
var i = 0;
var iv = setInterval(function () {
em.emit('data', i++);
}, 10);
var caught = { pipe : 0, end : 0 };
em.on('pipe', function () {
caught.pipe ++;
setTimeout(em.emit.bind(em, 'end'), 50);
});
em.on('end', function () { caught.end ++ });
var joined = 0;
Lazy(em).take(10).join(function (xs) {
assert.deepEqual(xs, range(0, 10));
clearInterval(iv);
joined ++;
});
setTimeout(function () {
assert.equal(joined, 1);
assert.equal(caught.pipe, 1);
assert.equal(caught.end, 1);
}, 1000);
}

26
node_modules/lazy/test/product.js generated vendored Normal file
View File

@@ -0,0 +1,26 @@
var assert = require('assert');
var Lazy = require('..');
var expresso = expresso;
function range(i, j) {
var r = [];
for (;i<j;i++) r.push(i);
return r;
}
exports['product'] = function () {
var lazy = new Lazy;
var executed = 0;
lazy.product(function (y) {
executed++;
assert.equal(y, 1*2*3*4*5*6*7*8*9);
})
range(1,10).forEach(function (x) {
lazy.emit('data', x);
});
lazy.emit('end');
assert.equal(executed, 1, 'product failed to execute');
}

272
node_modules/lazy/test/range.js generated vendored Normal file
View File

@@ -0,0 +1,272 @@
var assert = require('assert');
var Lazy = require('..');
var expresso = expresso;
function range(i, j, s) {
var r = [];
var s = s || 1;
if (j > i) for (;i<j;i+=s) r.push(i);
else for(;i>j;i-=s) r.push(i);
return r;
}
exports['infinite range'] = function () {
var joinExecuted = false;
Lazy.range('10..').take(10).join(function (xs) {
joinExecuted = true;
assert.deepEqual(xs, range(10, 20));
assert.equal(xs.length, 10);
});
setTimeout(function () {
assert.ok(joinExecuted, 'join didn\'t execute');
}, 2000);
}
exports['infinite range half-open'] = function () {
var joinExecuted = false;
Lazy.range('(10..').take(10).join(function (xs) {
joinExecuted = true;
assert.deepEqual(xs, range(11, 21));
assert.equal(xs.length, 10);
});
setTimeout(function () {
assert.ok(joinExecuted, 'join didn\'t execute');
}, 2000);
}
exports['range i'] = function () {
var joinExecuted = false;
Lazy.range(10).join(function (xs) {
joinExecuted = true;
assert.deepEqual(xs, range(0, 10));
assert.equal(xs.length, 10);
});
setTimeout(function () {
assert.ok(joinExecuted, 'join didn\'t execute');
}, 2000);
}
exports['range i,j (i<j)'] = function () {
var joinExecuted = false;
Lazy.range(-10, 10).join(function (xs) {
joinExecuted = true;
assert.deepEqual(xs, range(-10, 10));
assert.equal(xs.length, 20);
});
setTimeout(function () {
assert.ok(joinExecuted, 'join didn\'t execute');
}, 2000);
}
exports['range i,j,s (i<j)'] = function () {
var joinExecuted = false;
Lazy.range(-10, 10, 2).join(function (xs) {
joinExecuted = true;
assert.deepEqual(xs, range(-10, 10, 2));
assert.equal(xs.length, 10);
});
setTimeout(function () {
assert.ok(joinExecuted, 'join didn\'t execute');
}, 2000);
}
exports['range i,j,s (i>j)'] = function () {
var joinExecuted = false;
Lazy.range(10, 0, 2).join(function (xs) {
joinExecuted = true;
assert.deepEqual(xs, range(10, 0, 2));
assert.equal(xs.length, 5);
});
setTimeout(function () {
assert.ok(joinExecuted, 'join didn\'t execute');
}, 2000);
}
exports['range i,j (i>j)'] = function () {
var joinExecuted = false;
Lazy.range(10, -8).join(function (xs) {
joinExecuted = true;
assert.deepEqual(xs, range(10, -8));
assert.equal(xs.length, 18);
});
setTimeout(function () {
assert.ok(joinExecuted, 'join didn\'t execute');
}, 2000);
}
exports['range i..j (i<j)'] = function () {
var joinExecuted = false;
Lazy.range('5..50').join(function (xs) {
joinExecuted = true;
assert.deepEqual(xs, range(5, 50));
assert.equal(xs.length, 45);
});
setTimeout(function () {
assert.ok(joinExecuted, 'join didn\'t execute');
}, 2000);
}
exports['range i..j (i>j)'] = function () {
var joinExecuted = false;
Lazy.range('50..44').join(function (xs) {
joinExecuted = true;
assert.deepEqual(xs, range(50, 44));
assert.equal(xs.length, 6);
});
setTimeout(function () {
assert.ok(joinExecuted, 'join didn\'t execute');
}, 2000);
}
exports['range i,next..j (i<j)'] = function () {
var joinExecuted = false;
Lazy.range('1,1.1..4').join(function (xs) {
joinExecuted = true;
assert.deepEqual(xs, range(1,4,0.1));
assert.equal(xs.length, 30);
});
setTimeout(function () {
assert.ok(joinExecuted, 'join didn\'t execute');
}, 2000);
}
exports['range i,next..j (i>j)'] = function () {
var joinExecuted = false;
Lazy.range('4,3.9..1').join(function (xs) {
joinExecuted = true;
assert.deepEqual(xs, range(4,1,0.1));
assert.equal(xs.length, 30);
});
setTimeout(function () {
assert.ok(joinExecuted, 'join didn\'t execute');
}, 2000);
}
exports['range [i..j] (i<j)'] = function () {
var joinExecuted = false;
Lazy.range('[1..10]').join(function (xs) {
joinExecuted = true;
assert.deepEqual(xs, range(1,11));
assert.equal(xs.length, 10);
});
setTimeout(function () {
assert.ok(joinExecuted, 'join didn\'t execute');
}, 2000);
}
exports['range [i..j] (i>j)'] = function () {
var joinExecuted = false;
Lazy.range('[10..1]').join(function (xs) {
joinExecuted = true;
assert.deepEqual(xs, range(10,0));
assert.equal(xs.length, 10);
});
setTimeout(function () {
assert.ok(joinExecuted, 'join didn\'t execute');
}, 2000);
}
exports['range [i..j) (i<j)'] = function () {
var joinExecuted = false;
Lazy.range('[1..10)').join(function (xs) {
joinExecuted = true;
assert.deepEqual(xs, range(1,10));
assert.equal(xs.length, 9);
});
setTimeout(function () {
assert.ok(joinExecuted, 'join didn\'t execute');
}, 2000);
}
exports['range [i..j) (i>j)'] = function () {
var joinExecuted = false;
Lazy.range('[10..1)').join(function (xs) {
joinExecuted = true;
assert.deepEqual(xs, range(10,1));
assert.equal(xs.length, 9);
});
setTimeout(function () {
assert.ok(joinExecuted, 'join didn\'t execute');
}, 2000);
}
exports['range (i..j] (i<j)'] = function () {
var joinExecuted = false;
Lazy.range('(1..10]').join(function (xs) {
joinExecuted = true;
assert.deepEqual(xs, range(2,11));
assert.equal(xs.length, 9);
});
setTimeout(function () {
assert.ok(joinExecuted, 'join didn\'t execute');
}, 2000);
}
exports['range (i..j] (i>j)'] = function () {
var joinExecuted = false;
Lazy.range('(10..1]').join(function (xs) {
joinExecuted = true;
assert.deepEqual(xs, range(9,0));
assert.equal(xs.length, 9);
});
setTimeout(function () {
assert.ok(joinExecuted, 'join didn\'t execute');
}, 2000);
}
exports['range (i..j) (i<j)'] = function () {
var joinExecuted = false;
Lazy.range('(1..10)').join(function (xs) {
joinExecuted = true;
assert.deepEqual(xs, range(2,10));
assert.equal(xs.length, 8);
});
setTimeout(function () {
assert.ok(joinExecuted, 'join didn\'t execute');
}, 2000);
}
exports['range (i..j) (i>j)'] = function () {
var joinExecuted = false;
Lazy.range('(10..1)').join(function (xs) {
joinExecuted = true;
assert.deepEqual(xs, range(9,1));
assert.equal(xs.length, 8);
});
setTimeout(function () {
assert.ok(joinExecuted, 'join didn\'t execute');
}, 2000);
}
exports['range [i,step..j]'] = function () {
var joinExecuted = false;
Lazy.range('[5,10..50]').join(function (xs) {
joinExecuted = true;
assert.deepEqual(xs, range(5,51,5));
assert.equal(xs.length, 10);
});
setTimeout(function () {
assert.ok(joinExecuted, 'join didn\'t execute');
}, 2000);
}

27
node_modules/lazy/test/skip.js generated vendored Normal file
View File

@@ -0,0 +1,27 @@
var assert = require('assert');
var Lazy = require('..');
var expresso = expresso;
function range(i, j) {
var r = [];
for (;i<j;i++) r.push(i);
return r;
}
exports['skip'] = function () {
var lazy = new Lazy;
var data = [];
var executed = 0;
lazy.skip(6).join(function (xs) {
assert.deepEqual(xs, range(6,10));
executed++;
});
range(0,10).forEach(function (x) {
lazy.emit('data', x);
});
lazy.emit('end');
assert.equal(executed, 1, 'join executed incorrectly');
}

26
node_modules/lazy/test/sum.js generated vendored Normal file
View File

@@ -0,0 +1,26 @@
var assert = require('assert');
var Lazy = require('..');
var expresso = expresso;
function range(i, j) {
var r = [];
for (;i<j;i++) r.push(i);
return r;
}
exports['sum'] = function () {
var lazy = new Lazy;
var executed = 0;
lazy.sum(function (y) {
executed++;
assert.equal(y, 45);
})
range(0,10).forEach(function (x) {
lazy.emit('data', x);
});
lazy.emit('end');
assert.equal(executed, 1, 'sum failed to execute');
}

27
node_modules/lazy/test/tail.js generated vendored Normal file
View File

@@ -0,0 +1,27 @@
var assert = require('assert');
var Lazy = require('..');
var expresso = expresso;
function range(i, j) {
var r = [];
for (;i<j;i++) r.push(i);
return r;
}
exports['tail'] = function () {
var lazy = new Lazy;
var data = [];
var executed = false;
lazy.tail().join(function (xs) {
assert.deepEqual(xs, range(1,10));
executed = true;
});
range(0,10).forEach(function (x) {
lazy.emit('data', x);
});
lazy.emit('end');
assert.ok(executed, 'join didn\'t execute');
}

26
node_modules/lazy/test/take.js generated vendored Normal file
View File

@@ -0,0 +1,26 @@
var assert = require('assert');
var Lazy = require('..');
var expresso = expresso;
function range(i, j) {
var r = [];
for (;i<j;i++) r.push(i);
return r;
}
exports['take'] = function () {
var lazy = new Lazy;
var data = [];
var executed = 0;
lazy.take(6).join(function (xs) {
assert.deepEqual(xs, range(0,6));
executed++;
});
range(0,10).forEach(function (x) {
lazy.emit('data', x);
});
assert.equal(executed, 1, 'join executed incorrectly');
}

26
node_modules/lazy/test/takeWhile.js generated vendored Normal file
View File

@@ -0,0 +1,26 @@
var assert = require('assert');
var Lazy = require('..');
var expresso = expresso;
function range(i, j) {
var r = [];
for (;i<j;i++) r.push(i);
return r;
}
exports['takeWhile'] = function () {
var lazy = new Lazy;
var data = [];
var executed = false;
lazy.takeWhile(function (x) { return x < 5 }).join(function (xs) {
assert.deepEqual(xs, range(0,5));
executed = true;
});
range(0,10).forEach(function (x) {
lazy.emit('data', x);
});
assert.ok(executed, 'join didn\'t execute');
}