/** * 保存用户头像 * @returns {Promise.<void>} */ async saveAvatarAction() { const avatar = this.file('avatar'); if (think.isEmpty(avatar)) { return this.fail('保存失败'); } const avatarPath = think.RESOURCE_PATH + `/static/user/avatar/${this.getLoginUserId()}.` + _.last(_.split(avatar.path, '.')); fs.rename(avatar.path, avatarPath, function(res) { return this.success(); }); }
get(key, defaultResponse) { let getObject; try { getObject = _.reduce(_.split(key, '.'), (o, i) => o[i], Cache.get('config')); } catch (ex) { _.noop(); } if (!_.isUndefined(getObject)) { return getObject; } return (!_.isUndefined(defaultResponse)) ? defaultResponse : undefined; }
_.flow([ _.trim, text => _.split(text, ' '), words => _.reject(words, _.isEmpty), words => _.join(words, ' ') ])
getReplacement(replacement) { return replacement.replace(/{{\s?([\w.-]+)\s?}}/g, ($0, $1) => { // eslint-disable-line if (_.startsWith($1, 'server')) { return _.reduce(_.split(_.replace($1, 'server.', ''), '.'), (o, i) => o[i], this.server.json); } else if (_.startsWith($1, 'env')) { return _.get(this.server.json, `build.env.${_.replace($1, 'env.', '')}`, ''); } else if (_.startsWith($1, 'config')) { return Config.get(_.replace($1, 'config.', '')); } return $0; }); }
const getQuerySelectParser = (value, {req, location, path}) => { return _.split(value, ' ') || []; }
_.forEach(attributes, (criteria, object_attribute) => { if (criteria.hasOwnProperty('field')) { if (!rule_attributes.hasOwnProperty(criteria.comparison_target)) rule_attributes[criteria.comparison_target] = []; if (!_.includes(rule_attributes[criteria.comparison_target], criteria.field)) rule_attributes[criteria.comparison_target].push(criteria.field); } let [object, attribute] = _.split(object_attribute, '.', 2); if (!rule_attributes.hasOwnProperty(object)) rule_attributes[object] = []; if (!_.includes(rule_attributes[object], attribute)) rule_attributes[object].push(attribute); });
size(next) { const Exec = Process.spawn('du', ['-hsb', this.server.path()], {}); Exec.stdout.on('data', data => { next(null, parseInt(_.split(data.toString(), '\t')[0], 10)); }); Exec.on('error', execErr => { this.server.log.error(execErr); return next(new Error('There was an error while attempting to check the size of the server data folder.')); }); Exec.on('exit', (code, signal) => { if (code !== 0) { return next(new Error(`Unable to determine size of server data folder, exited with code ${code} signal ${signal}.`)); } }); }
_.forEach(formats, (seconds, scale) => { const data = _.split(time_format, scale); if (time_format.length !== data[0].length) { time += data[0] * seconds; time_format = data[1]; } });
self.fetchContent(url, function (err, content) { if (err) { return callback(err, null); } // Parse the content fetch from google finance var bid = self.parseContent(content); if (_.isNull(bid) || _.isUndefined(bid) || bid.length === 0) { return callback(new UnsupportedCurrencyPairException(currencyPair, Provider), null); } // split the fetched rate to remove currency symbol and verify if its number var parts = _.split(bid, ' '); if (parts.length == 0 || !_.toNumber(parts[0])) { return callback(new UnsupportedCurrencyPairException(currencyPair, Provider), null); } return callback(null, new Rate(parts[0], new Date(), Provider)); });
function getLoginPage() { return new Promise((fulfill, reject)=> { request(techcombank_page + 'BrowserServlet', (err, res, body) => { if (err) { reject(err) } else { var cookies = res.headers['set-cookie']; cookie = _.map(cookies, (string) => { return _.split(string, ';')[0]; }).join('; '); var $ = cheerio.load(res.body); formToken = $('input[name="formToken"]').val(); counter = $('input[name="counter"]').val(); fulfill(res) } }) }) }
_.map(cookies, (string) => { return _.split(string, ';')[0]; }).join('; ')
const [space, contentTypeId] = _.split(selector, '/') const validSelector = space && contentTypeId
formatFileMode(item) { let longname = 'd'; if (!item.directory) { longname = '-'; } const permissions = _.split((item.mode & 0o777).toString(8), ''); _.forEach(permissions, el => { el == 1 ? longname += '--x' : null; // eslint-disable-line el == 2 ? longname += '-w-' : null; // eslint-disable-line el == 3 ? longname += '-wx' : null; // eslint-disable-line el == 4 ? longname += 'r--' : null; // eslint-disable-line el == 5 ? longname += 'r-x' : null; // eslint-disable-line el == 6 ? longname += 'rw-' : null; // eslint-disable-line el == 7 ? longname += 'rwx' : null; // eslint-disable-line }); return (item.directory) ? `${longname} 2` : `${longname} 1`; }
_.forEach(rule.attributes, (criteria, object_attribute) => { const [object, attribute] = _.split(object_attribute, '.', 2), type = criteria.comparison_type, mode = criteria.comparison, object_value = objects[object][attribute]; let comparison_result, criteria_value, field_value; if (criteria.hasOwnProperty('field')) { criteria_value = objects[criteria.comparison_target][criteria.field]; field_value = criteria_value; } else criteria_value = criteria.value; comparison_result = Comparator.compare(type, mode, object_value, criteria_value); results.push({ criteria: criteria, field_value: field_value, result: comparison_result, subject: object, subject_attribute: attribute, subject_value: object_value }); });
var getTags = function(value) { return lodash.split(value, ','); }