<commit_before>/**
 *
 * Get the width and height for an DOM-element based given selector.
 *
 * <example>
    :getElementSize.js
    client
        .getElementSize('.header-logo-wordmark', function(err,size) {
            console.log(size) // outputs: { width: 37, height: 33 }
        })
 * </example>
 *
 * @param   {String} selector element with requested size
 * @returns {Object}          requested element size (`{width:number, height:number}`)
 * @callbackParameter error, size
 *
 * @uses protocol/elements, protocol/elementIdSize
 * @type property
 *
 */

var async = require('async'),
    ErrorHandler = require('../utils/ErrorHandler.js');

module.exports = function getElementSize (selector) {

    /*!
     * make sure that callback contains chainit callback
     */
    var callback = arguments[arguments.length - 1];

    /*!
     * parameter check
     */
    if(typeof selector !== 'string') {
        return callback(new ErrorHandler.CommandError('number or type of arguments don\'t agree with getElementSize command'));
    }

    var self = this,
        response = {};

    async.waterfall([
        function(cb) {
            self.elements(selector, cb);
        },
        function(res, cb) {
            response.elements = res;
            response.elementIdSize = [];

            if(res.value.length === 0) {
                // throw NoSuchElement error if no element was found
                return callback(new ErrorHandler(7));
            }

            async.eachSeries(res.value, function(val, seriesCallback) {
                self.elementIdSize(val.ELEMENT, function(err,res) {
                    response.elementIdSize.push(res);
                    seriesCallback(err);
                });
            }, cb);
        }
    ], function(err) {

        var value = null;

        if(response.elementIdSize && response.elementIdSize.length === 1) {

            value = {
                width: response.elementIdSize[0].value.width,
                height: response.elementIdSize[0].value.height
            };

        } else if(response.elementIdSize && response.elementIdSize.length > 1) {

            value = response.elementIdSize.map(function(res) {
                return {
                    width: res.value.width,
                    height: res.value.height
                };
            });

        }

        callback(err, value, response);

    });
<commit_msg>enhance getElementSize command to filter width|height property - closes #455<commit_after>/**
 *
 * Get the width and height for an DOM-element based given selector.
 *
 * <example>
    :getElementSize.js
    client
        .getElementSize('.header-logo-wordmark').then(function(size) {
            console.log(size) // outputs: { width: 100, height: 200 }
        })
        .getElementSize('.header-logo-wordmark', 'width').then(function(width) {
            console.log(width) // outputs: 100
        })
        .getElementSize('.header-logo-wordmark', 'height').then(function(height) {
            console.log(height) // outputs: 200
        });
 * </example>
 *
 * @param   {String} selector element with requested size
 * @returns {Object}          requested element size (`{width:number, height:number}`)
 * @callbackParameter error, size
 *
 * @uses protocol/elements, protocol/elementIdSize
 * @type property
 *
 */

var Q = require('q'),
    ErrorHandler = require('../utils/ErrorHandler.js');

module.exports = function getElementSize (selector, prop) {

    /*!
     * parameter check
     */
    if(typeof selector !== 'string') {
        throw new ErrorHandler.CommandError('number or type of arguments don\'t agree with getElementSize command');
    }

    return this.elements(selector).then(function(res) {

        if(!res.value || res.value.length === 0) {
            // throw NoSuchElement error if no element was found
            return callback(new ErrorHandler(7));
        }

        var self = this,
            elementIdSizeCommands = [];

        res.value.forEach(function(elem) {
            elementIdSizeCommands.push(self.elementIdSize(elem.ELEMENT))
        });

        return Q.all(elementIdSizeCommands)

    }).then(function(sizes) {

        sizes = sizes.map(function(size) {

            if(typeof prop === 'string' && prop.match(/(width|height)/)) {
                return size.value[prop];
            }

            return {
                width: size.value.width,
                height: size.value.height
            };

        });

        return sizes.length === 1 ? sizes[0] : sizes;

    });

{'fraction_non_alphanumeric': 0.12691801841297676, 'fraction_numerical': 0.00657606313020605, 'mean_word_length': 2.0480961923847696, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, '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': '6176500', 'n_tokens_mistral': 1258, 'n_tokens_neox': 1194, 'n_words': 276}