All files / env webp.js

100% Statements 8/8
100% Branches 4/4
100% Functions 2/2
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 401x                                         2x         2x       2x 1x   2x     1x   1x  
var isSupportWebp = null;
 
/**
 * 判断浏览器是否支持webp
 * @method env/webp
 * @returns {Boolean} 是否支持webp
 * @example
 * var $webp = require('@spore-ui/kit/packages/env/webp');
 * console.info($webp()); // true/false
 */
 
/**
 * 判断浏览器是否支持webp
 * @method env/webp.support
 * @memberof env/webp
 * @returns {Boolean} 是否支持webp
 * @example
 * var $webp = require('@spore-ui/kit/packages/env/webp');
 * console.info($webp.support()); // true/false
 */
function support() {
  var rs = !![].map
    && document
      .createElement('canvas')
      .toDataURL('image/webp')
      .indexOf('data:image/webp') === 0;
  return rs;
}
 
function webp() {
  if (isSupportWebp === null) {
    isSupportWebp = support();
  }
  return isSupportWebp;
}
 
webp.support = support;
 
module.exports = webp;