<commit_before>var _ = require('underscore');

function MapConfigNamedMapAdapter() {
}

module.exports = MapConfigNamedMapAdapter;

MapConfigNamedMapAdapter.prototype.getMapConfig = function (user, requestMapConfig, params, context, callback) {
    if (context.templateParams && 
            context.templateParams.buffersize && 
            isValidBufferSize(context.templateParams.buffersize)) {
        requestMapConfig.buffersize = context.templateParams.buffersize;
    }

    process.nextTick(function () {
        callback(null, requestMapConfig);
    });
};

function isValidBufferSize (bufferSize) {
    var formats = ['png', 'png32', 'mvt', 'grid.json', 'geojson'];

    if (!_.isObject(bufferSize) || (_.isArray(bufferSize) || _.isFunction(bufferSize))) {
        return false;
    }

    for (var index = 0; index < formats.length; index++) {
        var bufferSizeByFormat = bufferSize[formats[index]];
        if (bufferSizeByFormat && !Number.isFinite(bufferSizeByFormat)) {
            return false;
        }
    }

    return true;
}<commit_msg>Be more flexible validating buffer-size customization<commit_after>function MapConfigNamedMapAdapter() {
}

module.exports = MapConfigNamedMapAdapter;

var formats = ['png', 'png32', 'mvt', 'grid.json', 'geojson'];

MapConfigNamedMapAdapter.prototype.getMapConfig = function (user, requestMapConfig, params, context, callback) {
    if (!context.templateParams || !context.templateParams.buffersize) {
        return callback(null, requestMapConfig);
    }

    formats.forEach(function (format) {
        if (Number.isFinite(context.templateParams.buffersize[format])) {
            requestMapConfig.buffersize[format] = context.templateParams.buffersize[format];
        }
    });

    process.nextTick(function () {
        callback(null, requestMapConfig);
    });
};
{'fraction_non_alphanumeric': 0.12540894220283533, 'fraction_numerical': 0.0027262813522355507, 'mean_word_length': 3.803664921465969, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6720872', 'n_tokens_mistral': 529, 'n_tokens_neox': 516, 'n_words': 93}