function filterGripdCrops()

in public/src/js/utils/validate-image-src.js [76:96]


function filterGripdCrops (json, desired, {minWidth, maxWidth, widthAspectRatio, heightAspectRatio}) {
    return grid().filterCrops(json, function (crop) {
        if (desired.crop && crop.id !== desired.crop) {
            return false;
        }

        let ratio = widthAspectRatio && heightAspectRatio ? widthAspectRatio / heightAspectRatio : NaN;
        return !!_.find(crop.assets, function (asset) {
            let {width, height} = asset.dimensions;
            let actualRatio = width / height;
            if (maxWidth && maxWidth < width) {
                return false;
            } else if (minWidth && minWidth > width) {
                return false;
            } else if (ratio && Math.abs(ratio - actualRatio) > 0.01) {
                return false;
            }
            return true;
        });
    });
}