all files / popper/utils/ runModifiers.js

100% Statements 5/5
100% Branches 6/6
100% Functions 2/2
100% Lines 5/5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25                        125×       125× 1039× 940×       125×    
import isFunction from './isFunction';
import findIndex from './findIndex';
 
/**
 * Loop trough the list of modifiers and run them in order, each of them will then edit the data object
 * @method
 * @memberof Popper.Utils
 * @param {Object} data
 * @param {Array} modifiers
 * @param {Function} ends
 */
export default function runModifiers(modifiers, data, ends) {
    const modifiersToRun = (ends === undefined) ?
          modifiers :
          modifiers.slice(0, findIndex(modifiers, 'name', ends));
 
    modifiersToRun.forEach((modifier) => {
        if (modifier.enabled && isFunction(modifier.function)) {
            data = modifier.function(data, modifier);
        }
    });
 
    return data;
}