Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsftp

Package Overview
Dependencies
Maintainers
1
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsftp - npm Package Compare versions

Comparing version 0.1.5 to 0.1.6

lib/ftpParser_test.js

46

jsftp_test.js

@@ -18,6 +18,6 @@ /*

var FTPCredentials = {
host: "sergimansilla.com",
user: "mrclash",
host: "",
user: "",
port: 21,
pass: "ketu48"
pass: ""
};

@@ -73,3 +73,4 @@

},
"test features command": function(next) {
/*
">test features command": function(next) {
var ftp = this.ftp;

@@ -88,3 +89,17 @@ ftp.auth(FTPCredentials.user, FTPCredentials.pass, function(err, res) {

},
*/
"test initialize": function(next) {
var ftp = this.ftp;
assert.equal(ftp.options, FTPCredentials);
assert.equal(ftp.host, FTPCredentials.host);
assert.equal(ftp.port, FTPCredentials.port);
assert.equal(ftp.onError, null);
assert.equal(ftp.onTimeout, null);
assert.equal(ftp.onConnect, null);
next();
},
"test print working directory": function(next) {

@@ -141,2 +156,4 @@ var ftp = this.ftp;

ftp.list(remoteCWD, function(err, res){
assert.ok(res);
assert.ok(!err);
next();

@@ -155,2 +172,3 @@ });

assert.ok(!err);
assert.ok(res)

@@ -260,2 +278,22 @@ assert.ok(res.code === 211 || res.code === 212 || res.code === 213);

"test get two files synchronously": function(next) {
var ftp = this.ftp;
ftp.auth(FTPCredentials.user, FTPCredentials.pass, function(err, res) {
ftp.get(remoteCWD + "/testfile.txt", function(err, data) {
assert.ok(!err, err);
assert.ok(data);
});
ftp.get(remoteCWD + "/testfile.txt", function(err, data) {
assert.ok(!err, err);
assert.ok(data);
});
ftp.get(remoteCWD + "/testfile.txt", function(err, data) {
assert.ok(!err, err);
assert.ok(data);
next()
});
});
},
"test get fileList array": function(next) {

@@ -262,0 +300,0 @@ var ftp = this.ftp;

256

jsftp.js

@@ -8,9 +8,11 @@ /*

var S;
var Net = require("net");
var ftpPasv = require("./lib/ftpPasv");
var S;
var Parser = require('./lib/ftpParser');
try { S = require("streamer"); }
catch (e) { S = require("./support/streamer"); }
catch (e) { S = require("./support/streamer/core"); }
var Parser = require('./lib/ftp_parser');
var slice = Array.prototype.slice;

@@ -24,2 +26,3 @@ var FTP_PORT = 21;

var DEBUG_MODE = false;
var TIMEOUT = 60000;

@@ -37,18 +40,41 @@ var IDLE_TIME = 30000;

// This array contains the codes for special commands, such as RETR or STOR,
// which send two responses instead of one. Not a multiline response, but
// literally two.
var SPECIAL_CMDS = [150, 125];
function queue() {
var next;
var buffer = slice.call(arguments);
function stream($, stop) {
next = $;
stream._update();
}
stream._update = function _update() {
buffer.push.apply(buffer, arguments);
if (next && buffer.length) {
if (false !== next(buffer.shift()))
_update();
else
next = null;
}
};
return stream;
}
function enqueue(stream, element) {
stream._update.apply(null, slice.call(arguments, 1));
}
// Codes from 100 to 200 are FTP marks
function isMark(code) {
return code > 100 && code < 200;
};
var Ftp = module.exports = function(cfg) {
this.raw = {};
this.options = cfg;
if (cfg.onError)
if (cfg) {
this.onError = cfg.onError;
if (cfg.onTimeout)
this.onTimeout = cfg.onTimeout;
if (cfg.onConnect)
this.onConnect = cfg.onConnect;
}

@@ -59,3 +85,2 @@ // Generate generic methods from parameter names. They can easily be

var self = this;
this.raw = {};
COMMANDS.forEach(function(cmd) {

@@ -68,3 +93,3 @@ var lcCmd = cmd.toLowerCase();

if (arguments.length) {
var args = Array.prototype.slice.call(arguments);
var args = slice.call(arguments);

@@ -77,2 +102,3 @@ if (typeof args[args.length - 1] == "function")

}
self.keepAlive();

@@ -84,4 +110,6 @@ self.push(action, callback);

this.cmdListeners = [];
this.addCmdListener(this._log);
if (DEBUG_MODE)
this.addCmdListener(this._log);
this.host = cfg.host;

@@ -98,4 +126,7 @@ this.port = cfg.port || FTP_PORT;

this.push = function(command, callback) {
var self = this;
if (!command || typeof command != "string")
return;
command = command.toLowerCase();
function send() {

@@ -108,4 +139,3 @@ cmd([command, callback]);

var pass = this.options.pass;
var commandLC = command ? command.toLowerCase() : "";
var isAuthCmd = /feat.*/.test(commandLC) || /user.*/.test(commandLC) || /pass.*/.test(commandLC);
var isAuthCmd = /feat.*/.test(command) || /user.*/.test(command) || /pass.*/.test(command);

@@ -119,3 +149,5 @@ if (socket.writable) {

else {
console.log("FTP socket is not writable, reopening socket...")
if (DEBUG_MODE)
console.log("FTP socket is not writable, reopening socket...");
if (!this.connecting) {

@@ -127,3 +159,2 @@ this.connecting = true;

self.connecting = false;
self.connected = true;
if (!err && !isAuthCmd)

@@ -156,2 +187,20 @@ send();

var createStreams = function() {
/*
self.cmdQueue = queue();
(self.nextCmd = function nextCmd() {
S.head(self.cmdQueue)(function(obj) {
self.push(obj, self.nextCmd);
});
})();
*/
self.pasvQueue = queue();
(self.nextPasv = function nextPasv() {
// Take first element from `pasvQueue` and process it via `processElement` black box that will call
// `recur` once it's done to process next element from the `pasvQueue` queue.
S.head(self.pasvQueue)(function(element) {
self.processPasv(element, self.nextPasv);
});
})();
// Stream of FTP commands from the client.

@@ -167,5 +216,12 @@ cmds = function(next, stop) {

*/
tasks = S.zip(self.serverResponse(input), S.append(S.list(null), cmds));
tasks = S.zip(S.filter(function(x) {
// We ignore FTP marks for now. They don't convey useful
// information. A more elegant solution should be found int he
// future.
return !isMark(x.code);
}, self.serverResponse(input)), S.append(S.list(null), cmds));
tasks(self.parse.bind(self), function(err) {
console.log("Ftp socket closed its doors to the public.", err || "");
if (DEBUG_MODE)
console.log("Ftp socket closed its doors to the public.", err || "");
if (err && self.onError)

@@ -180,3 +236,2 @@ self.onError(err);

this.cmd = cmd;
this.connected = false;
};

@@ -192,3 +247,2 @@

this._createSocket = function(port, host, firstTask) {
var self = this;
this.connecting = true;

@@ -205,6 +259,6 @@ var socket = this.socket = Net.createConnection(port, host);

var self = this;
socket.on("connect", function() {
console.log("FTP socket connected");
if (DEBUG_MODE) console.log("FTP socket connected");
firstTask && firstTask();
self.connected = true;
self.connecting = false;

@@ -226,3 +280,2 @@ });

var currentCode = 0;
var self = this;

@@ -239,2 +292,3 @@ return function stream(next, stop) {

var code = parseInt(simpleRes[1], 10);
if (buffer.length) {

@@ -250,9 +304,2 @@ buffer.push(line);

// If the response code belongs to one of the 'special'
// commands (see above), insert a dummy command to pair
// it up properly with its response, and avoid messing
// up the zipped streams.
if (SPECIAL_CMDS.indexOf(code) > -1)
self.cmd(null);
next({ code: code, text: line });

@@ -268,4 +315,2 @@ }

}, this);
self.keepAlive();
}, stop);

@@ -286,17 +331,12 @@ };

this.parse = function(action) {
var ftpResponse = action[0];
var command = action[1];
if (!command)
if (!action || !action[1])
return;
var cmdName, callback;
if (command) {
cmdName = command[0];
callback = command[1] ? command[1] : null;
}
var ftpResponse = action[0];
var command = action[1];
var cleanCmd = this._sanitize(command[0]);
var callback = command[1];
var sanitizedCmd = this._sanitize(cmdName);
this.cmdListeners.forEach(function(listener) {
listener(sanitizedCmd, ftpResponse);
listener(cleanCmd, ftpResponse);
});

@@ -309,4 +349,3 @@

var hasFailed = ftpResponse && ftpResponse.code > 399;
var error = hasFailed ? ftpResponse.text : null;
callback(error, ftpResponse);
callback(hasFailed && ftpResponse.text, ftpResponse);
}

@@ -367,5 +406,3 @@ };

});
}
return features;

@@ -381,12 +418,9 @@ };

if (this.dataConn)
this.dataConn.destroy();
this.dataConn.socket.destroy();
this.features = null;
this.tasks = null;
this.cmds = null;
this.connected = false;
this.authenticated = false;
};
// Below this point all the methods are action helpers for FTP that compose

@@ -403,2 +437,3 @@ // several actions in one command

this.auth = function(user, pass, callback) {
var self = this;
if (this.authenticating)

@@ -410,5 +445,4 @@ return;

var self = this;
this.authenticating = true;
this._initialize(function() {
//this._initialize(function() {
self.raw.user(user, function(err, res) {

@@ -442,3 +476,3 @@ if ([230, 331, 332].indexOf(res.code) > -1) {

});
});
//});
};

@@ -455,15 +489,41 @@

*/
this.setPassive = function(mode, callback, onConnect) {
this.setPassive = function(data) {
enqueue(this.pasvQueue, data);
};
this.processPasv = function(data, next) {
var callback = function(err, res) {
data.callback && data.callback(err, res);
next();
};
var self = this;
this.raw.pasv(function(err, res) {
if (err || res.code !== 227)
return callback(res.text);
var doPasv = function doPasv() {
self.raw.pasv(function(err, res) {
if (err || res.code !== 227)
return callback(res.text);
var match = RE_PASV.exec(res.text);
if (!match)
return callback("PASV: Bad port "); // bad port
var match = RE_PASV.exec(res.text);
if (!match)
return callback("PASV: Bad port");
var port = (parseInt(match[1], 10) & 255) * 256 + (parseInt(match[2], 10) & 255);
this.dataConn = new ftpPasv(self.host, port, mode, callback, onConnect);
});
var port = (parseInt(match[1], 10) & 255) * 256 + (parseInt(match[2], 10) & 255);
self.dataConn = new ftpPasv({
host: self.host,
port: port,
mode: data.mode,
callback: callback,
onConnect: data.onConnect,
ftp: self
});
});
};
if (this.dataConn && this.dataConn.writable) {
this.dataConn.on("close", doPasv);
this.dataConn.end();
}
else {
doPasv();
}
};

@@ -482,11 +542,8 @@

var self = this;
var mode = "A";
this.raw.type(mode, function(err, res) {
if (err || (res.code !== 250 && res.code !== 200))
return callback(res.text);
self.setPassive(mode, callback, function() {
self.push("LIST" + (filePath ? " " + filePath : ""));
});
var self = this
this.setPassive({
callback: callback,
onConnect: function(socket) {
self.raw.list(filePath);
}
});

@@ -501,11 +558,8 @@ };

var self = this;
var mode = "I";
this.raw.type(mode, function(err, res) {
if (err || (res.code !== 250 && res.code !== 200)) {
return callback(res.text);
self.setPassive({
mode: "I",
callback: callback,
onConnect: function(socket) {
self.raw.retr(filePath);
}
self.setPassive(mode, callback, function() {
self.push("RETR" + (filePath ? " " + filePath : ""));
});
});

@@ -516,15 +570,17 @@ };

var self = this;
var mode = "I";
this.raw.type(mode, function(err, res) {
if (err || (res.code !== 250 && res.code !== 200))
return callback(res.text);
self.setPassive(mode, callback, function(socket) {
this.setPassive({
mode: "I",
callback: callback,
onConnect: function(socket) {
self.raw.stor(filePath, function(err, res) {
if (err)
callback(err);
});
// We make sure that we close the socket AFTER the 'stor'
// command has been sent to the server.
setTimeout(function() {
socket.end(buffer);
});
});
}, 100);
}
});

@@ -554,3 +610,3 @@ };

*
* The constants used in the object are defined in ftp_parser.js
* The constants used in the object are defined in ftpParser.js
*

@@ -569,3 +625,3 @@ * @param filePath {String} Path to the file or directory to list

self.list(filePath, function(err, data) {
entriesToList(err, data)
entriesToList(err, data);
});

@@ -595,16 +651,16 @@ }

this.rename = function(from, to, callback) {
var raw = this.raw;
raw.rnfr(from, function(err, res) {
var self = this;
self.raw.rnfr(from, function(err, res) {
if (err)
return callback(err);
raw.rnto(to, function(err, res) { callback(err, res) });
self.raw.rnto(to, function(err, res) { callback(err, res); });
});
}
};
this.keepAlive = function() {
var self = this;
if (this._keepAliveInterval)
clearInterval(this._keepAliveInterval);
var self = this;
this._keepAliveInterval = setInterval(self.raw.noop, IDLE_TIME);

@@ -611,0 +667,0 @@ };

@@ -11,13 +11,25 @@ /*

try { S = require("streamer"); }
catch (e) { S = require("../support/streamer/streamer"); }
catch (e) { S = require("../support/streamer/core"); }
var ftpPasv = module.exports = function(host, port, mode, callback, onConnect) {
var data = [];
var ftpPasv = module.exports = function(cfg) {
var data;
var callback = cfg.callback;
var socket = this.socket = Net.createConnection(cfg.port, cfg.host);
var socket = this.socket = Net.createConnection(port, host);
socket.setEncoding("utf8");
if (onConnect)
socket.on("connect", function() { onConnect(socket); });
if (cfg.onConnect) {
socket.on("connect", function() {
if (cfg.mode)
cfg.ftp.raw.type(cfg.mode, function(err, res) {
cfg.onConnect(socket);
});
else
cfg.onConnect(socket)
});
}
if (!callback || typeof callback != "function")
callback = function() {};
var input = function(next, stop) {

@@ -32,13 +44,8 @@ socket.on("data", next);

source(function(result) {
data.push(result);
if (cfg.mode === "I")
data = concat([data || [], result]);
else
data = [data, result].join("\n");
}, function(error) {
if (error && callback)
return callback(error);
if (callback) {
if (mode === "I")
callback(null, concat(data));
else if(mode === "A")
callback(null, data.join("\n"));
}
callback(error, data);
});

@@ -45,0 +52,0 @@ };

{
"name": "jsftp",
"id": "jsftp",
"version": "0.1.5",
"version": "0.1.6",
"description": "A sane FTP client implementation for NodeJS",

@@ -6,0 +6,0 @@ "keywords": [ "ftp", "streams", "files", "server", "client", "async" ],

# Changes #
## 0.2.0 / 2011-09-01 ##
- Splitting library into two core and experimental modules.
- Created clojure style aliases for 'head': 'first', 'pick' and 'tail':
'rest'.
- Exposing experimental `normilize` and `tree` APIs via
'streamer/experimental' module.
## 0.1.1 / 2011-08-20 ##
- Adding implementation of `stack`.
- Adding implementation of `join`.
- Some internal implementation simplifications.
## 0.1.0 / 2011-08-20 ##
- Breaking API by changing argument order in filter / map / reduce functions.
This style is more friendly when writing code in functional style. So that
high order functions can be defined by currying.
`var odds = map.bind(null, function($) { return !($%2) })`
- Adding `take` function that is similar to `filter`, but resulting stream
contains only first `n` elements that were not filtered out.
## 0.0.4 / 2011-06-27 ##

@@ -4,0 +27,0 @@

{
"name": "streamer",
"id": "streamer",
"version": "0.0.4",
"version": "0.2.0",
"description": "Asynchronously recursive, pure function <3 via lazy streams.",

@@ -20,6 +20,3 @@ "keywords": [ "stream", "functional", "spaghetti", "lazy", "iteration", "async" ],

},
"main": "./streamer.js",
"engines": {
"node": ">=0.4.0"
},
"main": "./core.js",
"scripts": {

@@ -26,0 +23,0 @@ "test": "node tests/test-streamer.js"

@@ -266,6 +266,6 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */

function map(source, mapper) {
function map(lambda, source) {
return function stream(next, stop) {
source(function onElement(element) {
next(mapper(element))
next(lambda(element))
}, stop)

@@ -276,3 +276,3 @@ }

// Let's try to map numbers into doubled values:
print(map(list(1, 2, 3), function(x) { return x * 2 }))
print(map(function(x) { return x * 2 }, list(1, 2, 3)))
//

@@ -290,3 +290,3 @@ // >>>

var join = require("path").join
function paths(path) { return map(ls(path), join.bind(null, path)) }
function paths(path) { return map(join.bind(null, path), ls(path)) }

@@ -307,6 +307,6 @@ // Test drive:

// and returns the steam of elements for which the filterer returned true.
function filter(source, filterer) {
function filter(lambda, source) {
return function stream(next, stop) {
source(function onElement(element) {
if (filterer(element)) next(element)
if (lambda(element)) next(element)
}, stop)

@@ -316,3 +316,3 @@ }

// Simple example for filtering out odd numbers from a number stream.
print(filter(list(1, 2, 3, 4), function(x) { return x % 2 }))
print(filter(function(x) { return x % 2 }, list(1, 2, 3, 4)))
//

@@ -329,5 +329,5 @@ // >>>

function dirs(paths) {
var stats = map(paths, stat)
var dirStats = filter(stats, function(stat) { return stat.isDirectory() })
return map(dirStats, function(stat) { return stat.path })
var stats = map(stat, paths)
var dirStats = filter(function(stat) { return stat.isDirectory() }, stats)
return map(function(stat) { return stat.path }, dirStats)
}

@@ -370,4 +370,4 @@

var stats = merge(map(paths, stat))
var dirStats = filter(stats, function(stat) { return stat.isDirectory() })
return map(dirStats, function(stat) { return stat.path })
var dirStats = filter(function(stat) { return stat.isDirectory() }, stats)
return map(function(stat) { return stat.path }, dirStats)
}

@@ -388,3 +388,3 @@

var entries = paths(path)
var nested = merge(map(dirs(entries), lstree))
var nested = merge(map(lstree, dirs(entries)))
return merge(list(entries, nested))

@@ -410,11 +410,11 @@ }

function paths(path) { return map(ls(path), join.bind(null, path)) }
function paths(path) { return map(join.bind(null, path), ls(path)) }
function dirs(paths) {
var stats = map(paths, stat)
var dirStats = filter(stats, function(stat) { return stat.isDirectory() })
return map(dirStats, function(stat) { return stat.path })
var stats = map(stat, paths)
var dirStats = filter(function(stat) { return stat.isDirectory() }, stats)
return map(function(stat) { return stat.path }, dirStats)
}
function lstree(path) {
var entries = paths(path)
var nested = merge(map(dirs(entries), lstree))
var nested = merge(map(lstree, dirs(entries)))
return merge(list(entries, nested))

@@ -421,0 +421,0 @@ }

@@ -6,7 +6,7 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */

(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
!(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
'use strict';
var streamer = require('../streamer.js'),
var streamer = require('../core.js'),
append = streamer.append, list = streamer.list

@@ -114,2 +114,2 @@ var test = require('./utils.js').test

})
});

@@ -6,3 +6,3 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */

(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
!(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {

@@ -17,3 +17,3 @@ 'use strict';

}
var list = require('../streamer.js').list
var list = require('../core.js').list

@@ -49,3 +49,2 @@ function test(assert, expected) {

})
});

@@ -6,7 +6,7 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */

(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
!(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
'use strict';
var streamer = require('../streamer.js'),
var streamer = require('../core.js'),
cache = streamer.cache, list = streamer.list

@@ -102,5 +102,4 @@ var utils = require('./utils.js'),

if (module == require.main)
require('test').run(exports);
require('test').run(exports)
})
});

@@ -6,7 +6,7 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */

(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
!(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
'use strict';
var streamer = require('../streamer.js'),
var streamer = require('../core.js'),
filter = streamer.filter, list = streamer.list

@@ -17,5 +17,5 @@ var test = require('./utils.js').test

var empty = list()
var mapped = filter(empty, function onEach(element) {
var mapped = filter(function onEach(element) {
assert.fail('filterer was executed')
})
}, empty)
test(assert, done, mapped, [])

@@ -26,5 +26,5 @@ }

var numbers = list(1, 2, 3, 4)
var evens = filter(numbers, function onElement(number) {
var evens = filter(function onElement(number) {
return !(number % 2)
})
}, numbers)
test(assert, done, evens, [2, 4])

@@ -41,3 +41,3 @@ }

}
var odds = filter(stream, function(number) { return number % 2 })
var odds = filter(function(number) { return number % 2 }, stream)
test(assert, done, odds, [ 5, 3, 1 ])

@@ -54,3 +54,3 @@ }

}
var filtered = filter(stream, function(number) { return number % 2 })
var filtered = filter(function(number) { return number % 2 }, stream)
var expected = [ 3, 1 ]

@@ -71,3 +71,3 @@ var actual = []

var stops = []
var filtered = filter(stream, function(x) { called++; return x % 2 })
var filtered = filter(function(x) { called++; return x % 2 }, stream)

@@ -90,2 +90,2 @@ filtered(function next(element) {

})
});

@@ -6,7 +6,7 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */

(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
!(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
'use strict';
var streamer = require('../streamer.js'),
var streamer = require('../core.js'),
head = streamer.head, list = streamer.list

@@ -72,4 +72,4 @@ var test = require('./utils.js').test

if (module == require.main)
require('test').run(exports);
require('test').run(exports)
})
});

@@ -6,7 +6,7 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */

(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
!(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
'use strict';
var hub = require('../streamer.js').hub
var hub = require('../core.js').hub
var utils = require('./utils.js'),

@@ -117,5 +117,4 @@ test = utils.test, pipe = utils.pipe

if (module == require.main)
require('test').run(exports);
require('test').run(exports)
})
});

@@ -6,7 +6,7 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */

(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
!(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
'use strict';
var list = require('../streamer.js').list
var list = require('../core.js').list
var test = require('./utils.js').test

@@ -42,5 +42,4 @@

if (module == require.main)
require('test').run(exports);
require('test').run(exports)
})
});

@@ -6,7 +6,7 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */

(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
!(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
'use strict';
var streamer = require('../streamer.js'),
var streamer = require('../core.js'),
map = streamer.map, list = streamer.list

@@ -17,5 +17,5 @@ var test = require('./utils.js').test

var empty = list()
var mapped = map(empty, function onEach(element) {
var mapped = map(function onEach(element) {
assert.fail('mapper was executed')
})
}, empty)
test(assert, done, mapped, [])

@@ -26,3 +26,3 @@ }

var numbers = list(1, 2, 3, 4)
var doubled = map(numbers, function onElement(number) { return number * 2 })
var doubled = map(function onElement(number) { return number * 2 }, numbers)
test(assert, done, doubled, [2, 4, 6, 8])

@@ -39,3 +39,3 @@ }

}
var mapped = map(stream, function(x) { return x + 1 })
var mapped = map(function(x) { return x + 1 }, stream)
test(assert, done, mapped, [ 6, 5, 4, 3, 2 ])

@@ -52,3 +52,3 @@ }

}
var mapped = map(stream, function(x) { return x * x })
var mapped = map(function(x) { return x * x }, stream)
var expected = [ 9, 4, 1]

@@ -69,3 +69,3 @@ var actual = []

var stops = []
var mapped = map(stream, function(x) { called++; return x * x })
var mapped = map(function(x) { called++; return x * x }, stream)

@@ -85,4 +85,4 @@ mapped(function next(element) {

if (module == require.main)
require('test').run(exports);
require('test').run(exports)
})
});

@@ -6,7 +6,7 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */

(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
!(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
'use strict';
var streamer = require('../streamer.js'),
var streamer = require('../core.js'),
merge = streamer.merge, list = streamer.list

@@ -114,4 +114,4 @@ var test = require('./utils.js').test

if (module == require.main)
require('test').run(exports);
require('test').run(exports)
})
});

@@ -6,7 +6,7 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */

(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
!(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
'use strict';
var streamer = require('../streamer.js'),
var streamer = require('../core.js'),
reduce = streamer.reduce, list = streamer.list

@@ -17,5 +17,5 @@ var test = require('./utils.js').test

var empty = list()
var reduced = reduce(empty, function onEach(element) {
var reduced = reduce(function onEach(element) {
assert.fail('reducer was called on empty list')
}, null)
}, empty, null)
test(assert, done, reduced, [ null ])

@@ -26,5 +26,5 @@ }

var numbers = list(1, 2, 3, 4)
var sum = reduce(numbers, function onElement(previous, current) {
var sum = reduce(function onElement(previous, current) {
return (previous || 0) + current
})
}, numbers)
test(assert, done, sum, [ 10 ])

@@ -42,5 +42,5 @@ }

}
var sum = reduce(stream, function(previous, current) {
var sum = reduce(function(previous, current) {
return previous + current
}, 3)
}, stream, 3)
test(assert, done, sum, [ 18 ])

@@ -58,5 +58,5 @@ }

}
var sum = reduce(stream, function(x, y) { return x + y })
var sum = reduce(function(x, y) { return x + y }, stream)
sum(function next(x) {
assert.fail('should not yield value if stream failed');
assert.fail('should not yield value if stream failed')
}, function stop(error) {

@@ -69,4 +69,4 @@ assert.equal(error.message, 'Boom!', 'error propagated to reduced stream')

if (module == require.main)
require('test').run(exports);
require('test').run(exports)
})
});

@@ -6,7 +6,7 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */

(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
!(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
'use strict';
var streamer = require('../streamer.js'),
var streamer = require('../core.js'),
tail = streamer.tail, list = streamer.list

@@ -77,4 +77,4 @@ var test = require('./utils.js').test

if (module == require.main)
require('test').run(exports);
require('test').run(exports)
})
});

@@ -6,22 +6,24 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */

(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
!(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
'use strict';
exports['test list'] = require('./list.js')
exports['test map'] = require('./map.js')
exports['test filter'] = require('./filter.js')
exports['test reduce'] = require('./reduce.js')
exports['test zip'] = require('./zip.js')
exports['test head'] = require('./head.js')
exports['test tail'] = require('./tail.js')
exports['test append'] = require('./append.js')
exports['test merge'] = require('./merge.js')
exports['test hub'] = require('./hub.js')
exports['test cache'] = require('./cache.js')
exports['test list'] = require('./list')
exports['test map'] = require('./map')
exports['test filter'] = require('./filter')
exports['test reduce'] = require('./reduce')
exports['test zip'] = require('./zip')
exports['test head'] = require('./head')
exports['test tail'] = require('./tail')
exports['test append'] = require('./append')
exports['test merge'] = require('./merge')
exports['test hub'] = require('./hub')
exports['test cache'] = require('./cache')
exports['test stack'] = require('./stack')
exports['test join'] = require('./join')
if (module == require.main)
require('test').run(exports);
require('test').run(exports)
})
});

@@ -6,3 +6,3 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */

(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
!(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {

@@ -42,2 +42,2 @@ 'use strict';

})
});

@@ -6,7 +6,7 @@ /* vim:set ts=2 sw=2 sts=2 expandtab */

(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
!(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) {
'use strict';
var streamer = require('../streamer.js'),
var streamer = require('../core.js'),
zip = streamer.zip, list = streamer.list

@@ -111,4 +111,4 @@ var test = require('./utils.js').test

if (module == require.main)
require('test').run(exports);
require('test').run(exports)
})
});
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