module.exports.best_image = function()

in lib/emulator.js [143:164]


module.exports.best_image = function (project_target) {
    return this.list_images().then(function (images) {
        // Just return undefined if there is no images
        if (images.length === 0) return;

        let closest = 9999;
        let best = images[0];
        for (const i in images) {
            const target = images[i].target;
            if (target && target.indexOf('API level') > -1) {
                const num = parseInt(target.split('(API level ')[1].replace(')', ''));
                if (num === project_target) {
                    return images[i];
                } else if (project_target - num < closest && project_target > num) {
                    closest = project_target - num;
                    best = images[i];
                }
            }
        }
        return best;
    });
};