Modules (188)

Preferences

Description

Dependencies

Functions

settingsToRegExp

Convert an array of strings with optional wildcards, to an equivalent regular expression.

settings Array.<string,RegExp>
from the file (note: this may be mutated by this function)
baseRegExp nullable RegExp
base regular expression that is always used
defaultRegExp nullable RegExp
additional regular expression that is only used if the user has not configured settings
Returns: RegExp
Regular expression that captures the array of string with optional wildcards.
    function settingsToRegExp(settings, baseRegExp, defaultRegExp) {
        var regExpString = "";

        if (settings instanceof Array && settings.length > 0) {

            // Append base settings to user settings. The base
            // settings are builtin and cannot be overridden.
            if (baseRegExp) {
                settings.push("/" + baseRegExp.source + "/");
            }

            // convert each string, with optional wildcards to an equivalent
            // string in a regular expression.
            settings.forEach(function (value, index) {

                if (typeof value === "string") {
                    var isRegExp = value[0] === '/' && value[value.length - 1] === '/';

                    if (isRegExp) {
                        value = value.substring(1, value.length - 1);
                    } else {
                        value = StringUtils.regexEscape(value);

                        // convert user input wildcard, "*" or "?", to a regular
                        // expression. We can just replace the escaped "*" or "?"
                        // since we know it is a wildcard.
                        value = value.replace("\\?", ".?");
                        value = value.replace("\\*", ".*");

                        // Add "^" and "$" to prevent matching in the middle of strings.
                        value = "^" + value + "$";
                    }

                    if (index > 0) {
                        regExpString += "|";
                    }

                    regExpString = regExpString.concat(value);
                }
            });
        }

        if (!regExpString) {
            var defaultParts = [];
            if (baseRegExp) {
                defaultParts.push(baseRegExp.source);
            }
            if (defaultRegExp) {
                defaultParts.push(defaultRegExp.source);
            }
            if (defaultParts.length > 0) {
                regExpString  = defaultParts.join("|");
            } else {
                return null;
            }
        }

        return new RegExp(regExpString);
    }

Classes

Constructor

Preferences

Constructor to create a default preference object.

prefs Object
preference object
    function Preferences(prefs) {
        var BASE_EXCLUDED_DIRECTORIES = null,

Methods

getExcludedDirectories

Get the regular expression for excluded directories.

Returns: ?RegExp
Regular expression matching the directories that should be excluded. Returns null if no directories are excluded.
    Preferences.prototype.getExcludedDirectories = function () {
        return this._excludedDirectories;
    };

getExcludedFiles

Get the regular expression for excluded files.

Returns: ?RegExp
Regular expression matching the files that should be excluded. Returns null if no files are excluded.
    Preferences.prototype.getExcludedFiles = function () {
        return this._excludedFiles;
    };

getMaxFileCount

Get the maximum number of files that will be analyzed.

Returns: number
    Preferences.prototype.getMaxFileCount = function () {
        return this._maxFileCount;
    };

getMaxFileSize

Get the maximum size of a file that will be analyzed. Files that are larger will be ignored.

Returns: number
    Preferences.prototype.getMaxFileSize = function () {
        return this._maxFileSize;
    };

    module.exports = Preferences;

});