lib/map.js
function map(opts, callback) {
    if(utils.isArray(opts)) {
        mapWithArrayInput(opts, callback);
        return;
    }
    opts = normalize(opts);
    // Assume that the root is a folder
    var root = new fp.Folder(opts.path);

    var sent = false;
    root.__listen('error', function (err) {
        if (!sent) {
            callback(err);
            sent = true;
        }
    });
    root.__listen('missing', function (err) {
        if (!sent) {
            callback(err);
            sent = true;
        }
    });
    root.__stats(function (err, stats) {
        if (err) {
            if (!sent) {
                callback(err);
            }
            return;
        }

        // If the root is a file simply return it
        if (!stats.isDirectory()) {
            callback(null, new fp.File(opts.path));
            return;
        }

        // Add functions
        addMaping(root);

        if(typeof opts.simple !== 'number' || !opts.recursive) {
            root.__map(opts, callback);
        } else {
            var lvls = opts.simple;
            var type = opts.type;
            var ext = opts.ext;
            opts.recursive = false;
            opts.simple = true;
            if(opts.type === 'file') {
                delete opts.type;
            }
            if(opts.ext) {
                delete opts.ext;
            }
            root.__map(opts, function (err, map) {
                if(err) {
                    callback(err);
                    return;
                }

                simpleMap(map, lvls, opts, type, ext, callback);
            });
        }
    });
}
function map(opts, callback) {
    if(utils.isArray(opts)) {
        mapWithArrayInput(opts, callback);
        return;
    }
    opts = normalize(opts);
    // Assume that the root is a folder
    var root = new fp.Folder(opts.path);

    var sent = false;
    root.__listen('error', function (err) {
        if (!sent) {
            callback(err);
            sent = true;
        }
    });
    root.__listen('missing', function (err) {
        if (!sent) {
            callback(err);
            sent = true;
        }
    });
    root.__stats(function (err, stats) {
        if (err) {
            if (!sent) {
                callback(err);
            }
            return;
        }

        // If the root is a file simply return it
        if (!stats.isDirectory()) {
            callback(null, new fp.File(opts.path));
            return;
        }

        // Add functions
        addMaping(root);

        if(typeof opts.simple !== 'number' || !opts.recursive) {
            root.__map(opts, callback);
        } else {
            var lvls = opts.simple;
            var type = opts.type;
            var ext = opts.ext;
            opts.recursive = false;
            opts.simple = true;
            if(opts.type === 'file') {
                delete opts.type;
            }
            if(opts.ext) {
                delete opts.ext;
            }
            root.__map(opts, function (err, map) {
                if(err) {
                    callback(err);
                    return;
                }

                simpleMap(map, lvls, opts, type, ext, callback);
            });
        }
    });
}
function map ( opts , callback ) { if ( utils . isArray ( opts ) ) { mapWithArrayInput ( opts , callback ) ; return ; } opts = normalize ( opts ) ; // Assume that the root is a folder var root = new fp . Folder ( opts . path ) ; var sent = false ; root . __listen ( 'error' , function ( err ) { if ( ! sent ) { callback ( err ) ; sent = true ; } } ) ; root . __listen ( 'missing' , function ( err ) { if ( ! sent ) { callback ( err ) ; sent = true ; } } ) ; root . __stats ( function ( err , stats ) { if ( err ) { if ( ! sent ) { callback ( err ) ; } return ; } // If the root is a file simply return it if ( ! stats . isDirectory ( ) ) { callback ( null , new fp . File ( opts . path ) ) ; return ; } // Add functions addMaping ( root ) ; if ( typeof opts . simple !== 'number' || ! opts . recursive ) { root . __map ( opts , callback ) ; } else { var lvls = opts . simple ; var type = opts . type ; var ext = opts . ext ; opts . recursive = false ; opts . simple = true ; if ( opts . type === 'file' ) { delete opts . type ; } if ( opts . ext ) { delete opts . ext ; } root . __map ( opts , function ( err , map ) { if ( err ) { callback ( err ) ; return ; } simpleMap ( map , lvls , opts , type , ext , callback ) ; } ) ; } } ) ; }
Function for mapping a folder and returning a foldermap
@param opts -> object or array of objects
@param callback
Function for mapping a folder and returning a foldermap