-
Notifications
You must be signed in to change notification settings - Fork 486
/
Copy pathfilter_js.js
34 lines (28 loc) · 1.02 KB
/
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
32
33
34
'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
*
* @private
* @param {string|Array} extension to be filtered
* @param {boolean} allowAll ignore the entire extension check and always
* pass through files. This is used by the polglot mode.
* @return {Function} a filter function, this function returns true if the input filename extension
* is in the extension whitelist
*/
function filterJS(extension, allowAll) {
if (allowAll) {
return function () {
return true;
};
}
var extensions = [].concat(extension || []).concat(['js', 'es6', 'jsx']);
return function (data) {
return extensions.indexOf(path.extname(data.file).substring(1)) !== -1;
};
}
module.exports = filterJS;