"use strict";

function sortIconsBySize(icons) {
    return icons.sort(function (a, b) {
        if (a.size < b.size) {
            return 1;
        } else {
            return -1;
        }
    });
}

/**
 *
 * @param icons
 * @param [ext]
 */
function findBestIcon(icons, ext) {
    var sorted = sortIconsBySize(icons);
    if (ext) {
        var _iteratorNormalCompletion = true;
        var _didIteratorError = false;
        var _iteratorError = undefined;

        try {
            for (var _iterator = sorted[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
                var icon = _step.value;

                if (icon.ext === ext) {
                    return icon;
                }
            }
        } catch (err) {
            _didIteratorError = true;
            _iteratorError = err;
        } finally {
            try {
                if (!_iteratorNormalCompletion && _iterator.return) {
                    _iterator.return();
                }
            } finally {
                if (_didIteratorError) {
                    throw _iteratorError;
                }
            }
        }
    }

    return sorted[0];
}

module.exports = findBestIcon;
//# sourceMappingURL=findBestIcon.js.map