lib/map.js
function filter(pObjects, opts, returnArray) {
	var filtered = returnArray ? [] : {};

    function addToFiltered(key) {
        if(returnArray) {
            filtered.push((returnArray === 'keys' ? key : pObjects[key]));
        } else {
            filtered[key] = pObjects[key];
        }
    }

    if (!opts) {
        Object.keys(pObjects).forEach();
        return;
    }

    function checkMatch(match, prop) {
        if(utils.isArray(match)){
            return match.indexOf(prop) !== -1;
        }
        return match === prop;
    }

	Object.keys(pObjects).forEach(function (key) {
        //Return only fp objects
        if(['File','Folder'].indexOf(pObjects[key].constructor.name) === -1) {
            return;
        }
        //Recursive directories always added
        if (opts.recursive && pObjects[key]._type === 'directory') {
            addToFiltered(key);
            return;
        }

        if (!opts.dotStart && pObjects[key]._name.charAt(0) === '.') {
            return;
        }

        if(opts.type && !checkMatch(opts.type, pObjects[key]._type)) {
            return;
        }

        if(opts.ext && pObjects[key]._type === 'file' && !checkMatch(opts.ext, pObjects[key]._ext)) {
            return;
        }

		if (opts.match && !pObjects[key]._name.match(opts.match)) {
			return;
		}
        if (opts.pathMatch && !pObjects[key]._path.match(opts.pathMatch)) {
            return;
        }
        addToFiltered(key);
	});

	return filtered;
}
function filter(pObjects, opts, returnArray) {
	var filtered = returnArray ? [] : {};

    function addToFiltered(key) {
        if(returnArray) {
            filtered.push((returnArray === 'keys' ? key : pObjects[key]));
        } else {
            filtered[key] = pObjects[key];
        }
    }

    if (!opts) {
        Object.keys(pObjects).forEach();
        return;
    }

    function checkMatch(match, prop) {
        if(utils.isArray(match)){
            return match.indexOf(prop) !== -1;
        }
        return match === prop;
    }

	Object.keys(pObjects).forEach(function (key) {
        //Return only fp objects
        if(['File','Folder'].indexOf(pObjects[key].constructor.name) === -1) {
            return;
        }
        //Recursive directories always added
        if (opts.recursive && pObjects[key]._type === 'directory') {
            addToFiltered(key);
            return;
        }

        if (!opts.dotStart && pObjects[key]._name.charAt(0) === '.') {
            return;
        }

        if(opts.type && !checkMatch(opts.type, pObjects[key]._type)) {
            return;
        }

        if(opts.ext && pObjects[key]._type === 'file' && !checkMatch(opts.ext, pObjects[key]._ext)) {
            return;
        }

		if (opts.match && !pObjects[key]._name.match(opts.match)) {
			return;
		}
        if (opts.pathMatch && !pObjects[key]._path.match(opts.pathMatch)) {
            return;
        }
        addToFiltered(key);
	});

	return filtered;
}
function filter ( pObjects , opts , returnArray ) { var filtered = returnArray ? [ ] : { } ; function addToFiltered ( key ) { if ( returnArray ) { filtered . push ( ( returnArray === 'keys' ? key : pObjects [ key ] ) ) ; } else { filtered [ key ] = pObjects [ key ] ; } } if ( ! opts ) { Object . keys ( pObjects ) . forEach ( ) ; return ; } function checkMatch ( match , prop ) { if ( utils . isArray ( match ) ) { return match . indexOf ( prop ) !== - 1 ; } return match === prop ; } Object . keys ( pObjects ) . forEach ( function ( key ) { //Return only fp objects if ( [ 'File' , 'Folder' ] . indexOf ( pObjects [ key ] . constructor . name ) === - 1 ) { return ; } //Recursive directories always added if ( opts . recursive && pObjects [ key ] . _type === 'directory' ) { addToFiltered ( key ) ; return ; } if ( ! opts . dotStart && pObjects [ key ] . _name . charAt ( 0 ) === '.' ) { return ; } if ( opts . type && ! checkMatch ( opts . type , pObjects [ key ] . _type ) ) { return ; } if ( opts . ext && pObjects [ key ] . _type === 'file' && ! checkMatch ( opts . ext , pObjects [ key ] . _ext ) ) { return ; } if ( opts . match && ! pObjects [ key ] . _name . match ( opts . match ) ) { return ; } if ( opts . pathMatch && ! pObjects [ key ] . _path . match ( opts . pathMatch ) ) { return ; } addToFiltered ( key ) ; } ) ; return filtered ; }
Function for filtering pointer objects based on options

@param pObjects - object with subobjects being pointer objects
@param opts - options to use when filtering
@param returnArray - return an array instead of object
@returns {*} || [*] - object or array with filtered results
Function for filtering pointer objects based on options