mysql-live-client
Version:
The client side script of mysql-live package.
59 lines (58 loc) • 2.23 kB
JavaScript
/// <reference path="../../typings/lodash/lodash.d.ts" />
var _ = require("lodash");
var Helper = (function () {
function Helper() {
}
Helper.forEachKey = function (map, callback) {
var result;
for (var id in map) {
if ((result = callback(id)))
break;
}
return result;
};
Helper._findAndUpdate = function (_theArray, theObjOrKeyToFind, theNewObject) {
var match = _.find(_theArray, theObjOrKeyToFind);
if (match) {
_.merge(match, theNewObject);
}
else {
_theArray.push(theNewObject);
}
return match;
};
Helper.escapeRegExp = function (str) {
return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
};
Helper.replaceAll = function (str, find, replace) {
return str.replace(new RegExp(Helper.escapeRegExp(find), 'g'), replace);
};
Helper.isString = function (something) {
return typeof something === 'string' || something instanceof String;
};
Helper.getArgumentsFromCallback = function (cb) {
return cb.toString().split(')', 1)[0].replace(/\s/g, '').substr(9).split(',');
};
Helper.hasNextFnInside = function (cb) {
var cbArgs = Helper.getArgumentsFromCallback(cb);
if (cbArgs[1] !== undefined) {
var body = cb.toString().replace(/\s+/g, " ").replace(/^\s|\s$/g, "");
var thisFuncIsDirectlyCalling = body.indexOf(cbArgs[1] + '()') !== -1;
var thisFuncIsPassingAsOtherArgumentInsideOtherCallback = body.indexOf(',' + cbArgs[1]) !== -1
|| body.indexOf(', ' + cbArgs[1]) !== -1
|| body.indexOf(cbArgs[1] + ',') !== -1
|| body.indexOf(cbArgs[1] + ' ,') !== -1
|| body.indexOf(cbArgs[1] + ')') !== -1
|| body.indexOf(cbArgs[1] + ' )') !== -1;
if (thisFuncIsDirectlyCalling || thisFuncIsPassingAsOtherArgumentInsideOtherCallback) {
return true;
}
else {
}
}
return false;
};
return Helper;
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = Helper;