helper.js 581 Bytes
'use strict';

const _ = require('lodash');

/**
 * 七牛图片路径处理
 * @param  {[string]} url
 * @param  {[string]} width
 * @param  {[string]} height
 * @param  {[string]} mode
 * @param {int} quality
 * @return {[string]}
 */
exports.image = (url, width, height, mode, quality) => {
    mode = _.isNumber(mode) ? mode : 2;
    url = url || '';
    url = url.replace(/{width}/g, width).replace(/{height}/g, height).replace(/{mode}/g, mode);
    if (url.indexOf('imageView2') > 0) {
        quality = quality || 90;
        url += '/q/' + quality;
    }
    return url;
};