{"size": 1728, "ext": "js", "max_stars_repo_path": "tasks/gulp/helpers/paths.js", "max_stars_repo_name": "jsstd/js-util-it", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tasks/gulp/helpers/paths.js", "max_issues_repo_name": "jsstd/js-util-it", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tasks/gulp/helpers/paths.js", "max_forks_repo_name": "jsstd/js-util-it", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.3513513514, "max_line_length": 83, "alphanum_fraction": 0.4762731481}
const path    = require("path"),
      appRoot = require("app-root-path"),
      extend  = require("extend");

const DEFAULT_VALUES = {
    autoNormalizePath : true
};

function isArray(object) {
    return Object.prototype.toString.call(object) === "[object Array]";
}

function arrayMerge(array) {
    return array.concat.apply(
        array,
        Array.prototype.slice.call(arguments, 1)
    );
}

const Paths = function() {
    this.addPath("root",  path.normalize(appRoot.toString()));
};

    Paths.prototype = {
        constructor : Paths,

        _paths : {},

        addPath : function(name, glob, options) {
            options = extend({}, DEFAULT_VALUES, options);

            if (options.autoNormalizePath) {
                glob = path.normalize(glob);
            }

            this._paths[name] = glob;

            return glob;
        },
        getPath : function(name) {
            if (!(name in this._paths)) {
                throw new Error("The given path cannot be found: \"" + name +"\"");
            }

            return this._paths[name];
        },
        appendToPath : function(name, glob) {
            if (!(name in this._paths)) {
                this._paths[name] = glob;

            } else {
                var path = this._paths[name];

                if (!isArray(path)) {
                    path = [path];
                }

                if (isArray(glob)) {
                    path = arrayMerge(path, glob);
                } else {
                    path.push(glob);
                }

                this._paths[name] = path;
            }

        },
        getAll : function() {
            return this._paths;
        }
    };

module.exports = new Paths();
