Code coverage report for lib/filter_js.js

Statements: 100% (9 / 9)      Branches: 100% (4 / 4)      Functions: 100% (2 / 2)      Lines: 100% (9 / 9)      Ignored: none     

All files » lib/ » filter_js.js
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    25                           25   65 65 1   65   65 108       25  
'use strict';
 
var path = require('path');
 
/**
 * Node & browserify support requiring JSON files. JSON files can't be documented
 * with JSDoc or parsed with espree, so we filter them out before
 * they reach documentation's machinery.
 * This creates a filter function for use with Array.prototype.filter, which
 * expect as argument a file as an objectg with the 'file' property
 *
 * @public
 * @param {String|Array} extensions to be filtered
 * @return {Function} a filter function, this function returns true if the input filename extension
 * is in the extension whitelist
 */
function filterJS(extensions) {
 
  extensions = extensions || [];
  if (typeof extensions === 'string') {
    extensions = [extensions];
  }
  extensions = extensions.concat('js');
 
  return function (data) {
    return extensions.indexOf(path.extname(data.file).substring(1)) !== -1;
  };
}
 
module.exports = filterJS;