/* * Helper to encode into a base64 string */ const encode = data => { if (_.isObject(data)) data = JSON.stringify(data); return Buffer.from(data).toString('base64'); }
// This is a helper to take object data and break it into rows add(data, {joiner = this.joiner, sort = this.sort} = {}) { _.forEach(sort ? _.sortBy(_.keys(data)) : _.keys(data), key => { // Do some special things for arrays if (_.isArray(data[key])) data[key] = data[key].join(joiner); // Do something special for objects if (_.isObject(data[key])) data[key] = util.inspect(data[key], {compact: true}); // Do the normal push this.push([(chalk[this.keyColor](_.toUpper(key))), data[key]]); }); }
/* * Helper to get the applications environment variables */ const getEnvironmentVariables = appConfig => _(_.get(appConfig, 'variables.env', {})) .map((value, key) => ([key, (_.isObject(value)) ? JSON.stringify(value) : value])) .fromPairs() .value()
// Load all the tasks, remember we need to remove "disabled" tasks (eg non-object tasks) here _.forEach(_.get(config, 'tooling', {}), (task, command) => { if (_.isObject(task)) { tasks.push({ command, level, describe: _.get(task, 'description', `Runs ${command} commands`), options: _.get(task, 'options', {}), run: (level === 'app') ? appRunner(command) : engineRunner(config, command), delegate: _.isEmpty(_.get(task, 'options', {})), }); } });
/* * Helper to replace defaualt */ const replaceDefault = (data, replacer) => { if (_.isObject(data)) { return JSON.parse(JSON.stringify(data).replace(/{default}/g, replacer)); } else { return data.replace(/{default}/g, replacer); } }
_(config) .map((task, name) => _.merge({}, task, {app, name})) .filter(task => _.isObject(task)) .value()
/** * Translate Filters * 翻译字符串 */ angular.module('filters').filter('translate', function () { return function (input, options) { if (!_.isObject(options) || !options.display || !options.same || !options.source) { return input; } var target = _.find(options.source, function (item) { return item[options.same] == input; }); return target[options.display]; } });
function setup(opts) { if (opts && !_.isObject(opts)) { gutil.log('uglify expects an object, non-object provided'); opts = {}; } var options = _.assign({}, opts, { fromString: true, output: {} }); if (options.preserveComments === 'all') { options.output.comments = true; } else if (options.preserveComments === 'some') { // preserve comments with directives or that start with a bang (!) options.output.comments = /^!|@preserve|@license|@cc_on/i; } else if (options.preserveComments === 'license') { options.output.comments = saveLicense; } else if (typeof options.preserveComments === 'function') { options.output.comments = options.preserveComments; } return options; }
if (_.isObject(value) && !_.isArray(value)) {
isEmail: function (value) { return /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(value) }, isNumber: function (value) { return _.isNumber(value) }, isObject: function (value) { return _.isObject(value) }, isArray: function (value) { return _.isArray(value) }, inArray: function (param) { case 'isEmail': return /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(value); break; case 'isNumber': return _.isNumber(item); break; case 'isObject': return _.isObject(item); break; case 'isArray': return _.isArray(item); break; case 'isBoolean':
_resolveStringTypes(defObj) { a&&ert(_.isObject(defObj)); const result = {}; _.each(defObj, (value, key) => { let type = defObj[key]; if (_.isString(type)) { type = this._resolveStringType(type); } result[key] = type; }); return result; }
constructor() { this.statSocket = Socket.of('/v1/stats/'); this.statSocket.use((params, next) => { if (!params.handshake.query.token) { return next(new Error('You must pass the correct handshake values.')); } if (!_.isObject(Config.get('keys')) || !_.includes(Config.get('keys'), params.handshake.query.token)) { return next(new Error('Invalid handshake value passed.')); } return next(); }); }