Code coverage report for master/lib/jsdoc/src/filter.js

Statements: 100% (24 / 24)      Branches: 100% (20 / 20)      Functions: 100% (5 / 5)      Lines: 100% (24 / 24)      Ignored: none     

All files » master/lib/jsdoc/src/ » filter.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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66                1 1   1 52   52 12     52                   1 26   7     26 26             1 19   19   19 2     19 3     19 13 26 6         19    
/**
    @module jsdoc/src/filter
 
    @author Michael Mathews <micmath@gmail.com>
    @license Apache License 2.0 - See file 'LICENSE.md' in this project.
 */
'use strict';
 
var env = require('jsdoc/env');
var path = require('jsdoc/path');
 
function makeRegExp(config) {
    var regExp = null;
 
    if (config) {
        regExp = (typeof config === 'string') ? new RegExp(config) : config;
    }
 
    return regExp;
}
 
/**
    @constructor
    @param {object} opts
    @param {string[]} opts.exclude - Specific files to exclude.
    @param {string|RegExp} opts.includePattern
    @param {string|RegExp} opts.excludePattern
 */
exports.Filter = function(opts) {
    this.exclude = opts.exclude && Array.isArray(opts.exclude) ?
        opts.exclude.map(function($) {
            return path.resolve(env.pwd, $);
        }) :
        null;
    this.includePattern = makeRegExp(opts.includePattern);
    this.excludePattern = makeRegExp(opts.excludePattern);
};
 
/**
    @param {string} filepath - The filepath to check.
    @returns {boolean} Should the given file be included?
 */
exports.Filter.prototype.isIncluded = function(filepath) {
    var included = true;
 
    filepath = path.resolve(env.pwd, filepath);
 
    if ( this.includePattern && !this.includePattern.test(filepath) ) {
        included = false;
    }
 
    if ( this.excludePattern && this.excludePattern.test(filepath) ) {
        included = false;
    }
 
    if (this.exclude) {
        this.exclude.forEach(function(exclude) {
            if ( filepath.indexOf(exclude) === 0 ) {
                included = false;
            }
        });
    }
 
    return included;
};