<commit_before>var Step = require('step');

server = Bones.Server.extend({
    initialize: function(app) {
        // Wax API Endpoint
        // ----------------
        // Provides and API for generating wax documents based on request query
        // string.
        //
        // Possible query parameters include:
        //
        // - `el` - ID of the DOM element that should be attached to.
        // - `layers` - List of layer IDs to include in the wax file. In front to
        //    back order.
        //        layers[]=test_project&layers[]=broadband-virginia_23ecea
        // - `center` - List in the form [<lon>, <lat>, <zoom>]
        //        center[]=66.5&center[]=55.8&&center[]=2
        var load = _(this.load).bind(this),
            wax = _(this.sendWax).bind(this);
        this.get('/api/v1/wax.json', load, wax);
        this.get('/api/wax.json', load, wax);
    },
    // Loader for layers. Validates `req.query` to ensure it is usable.
    load: function(req, res, next) {
        // Load defaults from Map model for each query property.
        var properties = ['el', 'api', 'center', 'options'],
            numeric = ['size', 'center'];
        _(properties).each(_(function(key) {
            req.query[key] = req.query[key] || this.defaults[key];
            req.query[key] = _(req.query[key].toJSON).isFunction()
                ? req.query[key].toJSON()
                : req.query[key];
            if (_(numeric).include(key) && _(req.query[key]).isArray()) {
                req.query[key] = _(req.query[key]).map(function(value) {
                    return parseFloat(value);
                });
            }
        }).bind(this));
        // Exception for `layers`.
        req.query.layers = req.query.layers || [];

        // Validate all query properties.
        var checkOption = function(option) {
            return _(['zoomwheel', 'zoompan', 'legend', 'tooltips']).include(option);
        };
        if (!_(req.query.el).isString()) return res.send('`el` is invalid.', 400);
        if (!_(_(this.Waxer).keys()).include(req.query.api)) return res.send('`api` is invalid.', 400);
        if (!_(req.query.size).isUndefined()) {
            if (!_(req.query.size).isArray()) return res.send('`size` is invalid.', 400);
            if (_(req.query.size).size() !== 2) return res.send('`size` is invalid.', 400);
            if (!_(req.query.size).all(_.isNumber)) return res.send('`size` is invalid.', 400);
        }
        if (!_(req.query.center).isArray()) return res.send('`center` is invalid.', 400);
        if (_(req.query.center).size() !== 3) return res.send('`center` is invalid.', 400);
        if (!_(req.query.center).all(_.isNumber)) return res.send('`center` is invalid.', 400);
        if (!_(req.query.layers).isArray()) return res.send('`layers` is invalid.', 400);
        if (_(req.query.layers).size() === 0) return res.send('`layers` is invalid.', 400);
        if (!_(req.query.options).isArray()) return res.send('`options` is invalid.', 400);<commit_msg>Separate property from numeric checks.<commit_after>var Step = require('step');

server = Bones.Server.extend({
    initialize: function(app) {
        // Wax API Endpoint
        // ----------------
        // Provides and API for generating wax documents based on request query
        // string.
        //
        // Possible query parameters include:
        //
        // - `el` - ID of the DOM element that should be attached to.
        // - `layers` - List of layer IDs to include in the wax file. In front to
        //    back order.
        //        layers[]=test_project&layers[]=broadband-virginia_23ecea
        // - `center` - List in the form [<lon>, <lat>, <zoom>]
        //        center[]=66.5&center[]=55.8&&center[]=2
        var load = _(this.load).bind(this),
            wax = _(this.sendWax).bind(this);
        this.get('/api/v1/wax.json', load, wax);
        this.get('/api/wax.json', load, wax);
    },
    // Loader for layers. Validates `req.query` to ensure it is usable.
    load: function(req, res, next) {
        // Load defaults from Map model for each query property.
        var properties = ['el', 'api', 'center', 'options'],
            numeric = ['size', 'center'];
        _(properties).each(_(function(key) {
            req.query[key] = req.query[key] || this.defaults[key];
            req.query[key] = _(req.query[key].toJSON).isFunction()
                ? req.query[key].toJSON()
                : req.query[key];
        }).bind(this));
        _(numeric).each(_(function(key) {
            if (_(req.query[key]).isArray()) {
                req.query[key] = _(req.query[key]).map(parseFloat);
            }
        }).bind(this));
        // Exception for `layers`.
        req.query.layers = req.query.layers || [];

        // Validate all query properties.
        var checkOption = function(option) {
            return _(['zoomwheel', 'zoompan', 'legend', 'tooltips']).include(option);
        };
        if (!_(req.query.el).isString()) return res.send('`el` is invalid.', 400);
        if (!_(_(this.Waxer).keys()).include(req.query.api)) return res.send('`api` is invalid.', 400);
        if (!_(req.query.size).isUndefined()) {
            if (!_(req.query.size).isArray()) return res.send('`size` is invalid.', 400);
            if (_(req.query.size).size() !== 2) return res.send('`size` is invalid.', 400);
            if (!_(req.query.size).all(_.isNumber)) return res.send('`size` is invalid.', 400);
        }
        if (!_(req.query.center).isArray()) return res.send('`center` is invalid.', 400);
        if (_(req.query.center).size() !== 3) return res.send('`center` is invalid.', 400);
        if (!_(req.query.center).all(_.isNumber)) return res.send('`center` is invalid.', 400);
        if (!_(req.query.layers).isArray()) return res.send('`layers` is invalid.', 400);
        if (_(req.query.layers).size() === 0) return res.send('`layers` is invalid.', 400);
        if (!_(req.query.options).isArray()) return res.send('`options` is invalid.', 400);
{'fraction_non_alphanumeric': 0.1885610680731828, 'fraction_numerical': 0.015164001977913302, 'mean_word_length': 2.1736401673640167, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2082597', 'n_tokens_mistral': 1883, 'n_tokens_neox': 1788, 'n_words': 444}