auditted lodash usage to ensure that it is compatible with lodash 3.0

This commit is contained in:
Spencer Alger
2015-03-17 13:47:44 -07:00
parent ed26798e5e
commit ec6b0fcefc
10 changed files with 26 additions and 18 deletions

View File

@ -163,7 +163,7 @@ function clearGeneratedFiles() {
generatedFiles.push(dirRegex(paths.src, esArchives));
var rmSteps = _.chain(generatedFiles)
.flatten()
.flattenDeep()
.uniq()
.map(function (path) {
return spawnStep('rm', ['-rf', path]);

View File

@ -108,7 +108,6 @@ fs.readdirSync(path.resolve(__dirname)).forEach(function (filename) {
if (name !== 'index') {
templates[name] = _.template(
fs.readFileSync(path.resolve(__dirname, filename), 'utf8'),
null,
{
imports: templateGlobals
}

View File

@ -45,7 +45,7 @@ function ClientAction(spec) {
var castType = {
'enum': function validSelection(param, val, name) {
if (_.isString(val) && val.indexOf(',') > -1) {
val = val.split(',');
val = commaSepList(val);
}
if (_.isArray(val)) {
@ -79,9 +79,11 @@ var castType = {
list: function (param, val, name) {
switch (typeof val) {
case 'number':
case 'string':
case 'boolean':
return '' + val;
case 'string':
val = commaSepList(val);
/* falls through */
case 'object':
if (_.isArray(val)) {
return val.join(',');
@ -299,6 +301,11 @@ function exec(transport, spec, params, cb) {
return transport.request(request, cb);
}
function commaSepList(str) {
return str.split(',').map(function (i) {
return i.trim();
});
}
ClientAction.proxy = function (fn, spec) {

View File

@ -30,7 +30,8 @@ if (typeof XMLHttpRequest !== 'undefined') {
};
} else {
// find the first MS implementation available
getXhr = _.first(['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'], function (appName) {
getXhr = _(['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'])
.map(function (appName) {
/* jshint unused: false */
try {
var test = new window.ActiveXObject(appName);
@ -38,9 +39,11 @@ if (typeof XMLHttpRequest !== 'undefined') {
return new window.ActiveXObject(appName);
};
} catch (e) {
return null;
return false;
}
});
})
.compact()
.first();
}
if (!getXhr) {

View File

@ -251,7 +251,7 @@ Log.prototype.info = function (/* ...msg */) {
*/
Log.prototype.debug = function (/* ...msg */) {
if (this.listenerCount('debug')) {
return this.emit('debug', Log.join(arguments) /*+ _.getStackTrace(Log.prototype.debug)*/);
return this.emit('debug', Log.join(arguments));
}
};

View File

@ -398,12 +398,12 @@ _.createArray = function (input, transform) {
*/
_.getUnwrittenFromStream = function (stream) {
var writeBuffer = _.getStreamWriteBuffer(stream);
if (!writeBuffer || !writeBuffer.length) {
return '';
}
if (!writeBuffer) return;
// flush the write buffer
var out = '';
if (!writeBuffer.length) return out;
_.each(writeBuffer, function (writeReq) {
if (writeReq.chunk) {
// 0.9.12+ uses WriteReq objects with a chunk prop
@ -431,7 +431,7 @@ _.getStreamWriteBuffer = function (stream) {
};
_.clearWriteStreamBuffer = function (stream) {
var buffer = _.emptyWriteStreamBuffer(stream);
var buffer = _.getStreamWriteBuffer(stream);
return buffer && buffer.splice(0);
};

View File

@ -22,10 +22,9 @@ process.once('message', function (port) {
var conns = es.transport.connectionPool._conns;
var sockets = _([].concat(conns.dead, conns.alive))
.transform(function (sockets, conn) {
[].push.apply(sockets, _.values(conn.agent.sockets));
[].push.apply(sockets, _.values(conn.agent.freeSockets));
sockets.push(_.values(conn.agent.sockets), _.values(conn.agent.freeSockets));
}, [])
.flatten()
.flattenDeep()
.value();
es.close();

View File

@ -90,7 +90,7 @@ function rangeMatchesCurrentVersion(rangeString, done) {
expect(rangeString).to.match(versionRangeRE);
var range = versionRangeRE.exec(rangeString);
range = _.map(_.last(range, 2), versionToComparableString);
range = _.map(_.takeRight(range, 2), versionToComparableString);
done(ES_VERSION >= range[0] && ES_VERSION <= range[1]);
}

View File

@ -2,7 +2,7 @@ describe('File Logger', function () {
var Log = require('../../../src/lib/log');
var FileLogger = require('../../../src/lib/loggers/file');
var once = require('events').EventEmitter.prototype.once;
var _ = require('lodash');
var _ = require('../../../src/lib/utils');
var parentLog;
var logger;
var expect = require('expect.js');

View File

@ -4,7 +4,7 @@ describe('Stream Logger', function () {
var MockWritableStream = require('../../mocks/writable_stream');
var once = require('events').EventEmitter.prototype.once;
var stream = new MockWritableStream();
var _ = require('lodash');
var _ = require('../../../src/lib/utils');
var expect = require('expect.js');
var parentLog;