lib/utils.js
function getExclusionMatcher(rules, defaultIsExclude) {

    return function isExcluded(name, ofType) {
        var index,
            include,
            pattern,
            rule,
            type,
            matchedRule,
            ret = null;

        if (!(ofType === 'file' || ofType === 'dir')) {
            throw new Error(
                'Internal error: file type was not provided, was [' +
                    ofType + ']'
            );
        }

        /* check if there are any rules */

        if (rules.length < 1) {
            throw new Error('No rules specified');
        }

        // console.log('checking ' + name + '...');
        for (index in rules) {
            // console.log('\t against ' + excludes[regex] + ': ' +
            //     name.search(excludes[regex]));
            if (rules.hasOwnProperty(index)) {

                rule = rules[index];

                if (rule instanceof RegExp) {
                    pattern = rule;
                    include = false;
                    type = 'any';
                } else {
                    pattern = rule.pattern;
                    include = !!rule.include;
                    type = rule.type || 'any';
                }

                if (!(type === 'file' || type === 'dir' || type === 'any')) {
                    throw new Error('Invalid type for match [' + type + ']');
                }

                if (!(pattern instanceof RegExp)) {
                    console.log(rule);
                    throw new Error('Pattern was not a regexp for rule');
                }

                if (name.search(pattern) !== -1 &&
                        (type === 'any' || type === ofType)) {
                    matchedRule = rule;
                    ret = !include;
                    break;
                }
            }
        }

        ret = ret === null ? !!defaultIsExclude : ret;
        //console.log('Match [' + name + '], Exclude= [' + ret + ']');
        //console.log('Used rule');
        //console.log(matchedRule);
        return ret;
    };
}
function getExclusionMatcher(rules, defaultIsExclude) {

    return function isExcluded(name, ofType) {
        var index,
            include,
            pattern,
            rule,
            type,
            matchedRule,
            ret = null;

        if (!(ofType === 'file' || ofType === 'dir')) {
            throw new Error(
                'Internal error: file type was not provided, was [' +
                    ofType + ']'
            );
        }

        /* check if there are any rules */

        if (rules.length < 1) {
            throw new Error('No rules specified');
        }

        // console.log('checking ' + name + '...');
        for (index in rules) {
            // console.log('\t against ' + excludes[regex] + ': ' +
            //     name.search(excludes[regex]));
            if (rules.hasOwnProperty(index)) {

                rule = rules[index];

                if (rule instanceof RegExp) {
                    pattern = rule;
                    include = false;
                    type = 'any';
                } else {
                    pattern = rule.pattern;
                    include = !!rule.include;
                    type = rule.type || 'any';
                }

                if (!(type === 'file' || type === 'dir' || type === 'any')) {
                    throw new Error('Invalid type for match [' + type + ']');
                }

                if (!(pattern instanceof RegExp)) {
                    console.log(rule);
                    throw new Error('Pattern was not a regexp for rule');
                }

                if (name.search(pattern) !== -1 &&
                        (type === 'any' || type === ofType)) {
                    matchedRule = rule;
                    ret = !include;
                    break;
                }
            }
        }

        ret = ret === null ? !!defaultIsExclude : ret;
        //console.log('Match [' + name + '], Exclude= [' + ret + ']');
        //console.log('Used rule');
        //console.log(matchedRule);
        return ret;
    };
}
function getExclusionMatcher ( rules , defaultIsExclude ) { return function isExcluded ( name , ofType ) { var index , include , pattern , rule , type , matchedRule , ret = null ; if ( ! ( ofType === 'file' || ofType === 'dir' ) ) { throw new Error ( 'Internal error: file type was not provided, was [' + ofType + ']' ) ; } /* check if there are any rules */ if ( rules . length < 1 ) { throw new Error ( 'No rules specified' ) ; } // console.log('checking ' + name + '...'); for ( index in rules ) { // console.log('\t against ' + excludes[regex] + ': ' + //     name.search(excludes[regex])); if ( rules . hasOwnProperty ( index ) ) { rule = rules [ index ] ; if ( rule instanceof RegExp ) { pattern = rule ; include = false ; type = 'any' ; } else { pattern = rule . pattern ; include = ! ! rule . include ; type = rule . type || 'any' ; } if ( ! ( type === 'file' || type === 'dir' || type === 'any' ) ) { throw new Error ( 'Invalid type for match [' + type + ']' ) ; } if ( ! ( pattern instanceof RegExp ) ) { console . log ( rule ) ; throw new Error ( 'Pattern was not a regexp for rule' ) ; } if ( name . search ( pattern ) !== - 1 && ( type === 'any' || type === ofType ) ) { matchedRule = rule ; ret = ! include ; break ; } } } ret = ret === null ? ! ! defaultIsExclude : ret ; //console.log('Match [' + name + '], Exclude= [' + ret + ']'); //console.log('Used rule'); //console.log(matchedRule); return ret ; } ; }
returns a function that determines whether a name is excluded from a list
using a set of firewall style rules.

Each rule looks like this:
{ pattern: /matchPattern/, include: true|false, type: file|dir|any }

If a file matches a rule, it is included or excluded based on the value of
the include flag If rule is a regexp, it is taken to be { pattern: regexp,
include: false, type: 'any' } - i.e. it is an exclusion rule.
The first rule that matches, wins.
The defaultIsExclude value specifies the behavior when none of the rules
match (if not specified, the file is included)

@param {Array} rules set of rules to determine what files and directories are
copied.
@param {boolean} defaultIsExclude determines what to do when none of the
rules match.
@return {function} A match function.
returns a function that determines whether a name is excluded from a list using a set of firewall style rules .