<commit_before>import * as Synergy from '../synergy';

/**
 * Modifier
 * 
 * @param {*} options.target
 * @param {*} options.module
 * @param {*} options.modifiers
 * @param {*} options.query
 * @param {*} options.operator
 */
export function modifier(options) {
    // setup constants
    const target = (options.target instanceof HTMLElement) ? options.target : options.target[0];
    const namespace = Synergy.getBlockName(target, options.module, options.glue) + options.glue + options.query;
    const modifiers = Synergy.getModifiers(target, options.module, options.glue);
    const selector = `.${namespace}, [class*="${namespace}${options.glue}"]`;
    const querySelector = document.querySelectorAll(selector);
    const moduleSelector = `.${options.module}, [class*="${options.module}${options.glue}"]`;
    const childModifier = Synergy.getChildrenWithoutSelector(target, selector, moduleSelector);
    const query = (modifiers !== options.modifiers) ? [options.query] : options.modifiers;

    if ((typeof options.query !== 'undefined') && target instanceof HTMLElement) {
        // add/remove a modifier
        if (options.operator) {
            if (options.operator === 'set') {
                return toggleModifier(options.module, target, options.query, 'set', options.glue);
            } 
            else if (options.operator === 'unset') {
                return toggleModifier(options.module, target, options.query, 'unset', options.glue);
            }
            else if (options.operator === 'add' || options.operator === 'remove') {
                return target.classList[options.operator](namespace);
            }
        }

        // get children with modifier
        if (childModifier.length !== 0) return childModifier;

        // determine if element has modifier
        let matchesQuery = false;

        modifiers.forEach(modifier => {
            query.forEach(queryModifier => {
                if (queryModifier === modifier) return matchesQuery = true;
            });
        });

        if (matchesQuery || options.operator == 'isset') return matchesQuery;

        // get all components with modifier from document 
        return (querySelector.length === 0) ? false : querySelector;
    }
    
    // get modifiers on element
    return (modifiers.length > 0) ? modifiers : false;
}

/**
 * Toggle a modifier on a module
 * 
 * @function toggleModifier
 * 
 * @param {*} moduleName 
 * @param {*} target 
 * @param {*} query 
 * @param {*} operator 
 */<commit_msg>fixing bug when determining if component has specified modifier<commit_after>import * as Synergy from '../synergy';

/**
 * Modifier
 * 
 * @param {*} options.target
 * @param {*} options.module
 * @param {*} options.modifiers
 * @param {*} options.query
 * @param {*} options.operator
 */
export function modifier(options) {
    // setup constants
    const target = (options.target instanceof HTMLElement) ? options.target : options.target[0];
    const namespace = Synergy.getBlockName(target, options.module, options.glue) + options.glue + options.query;
    const modifiers = Synergy.getModifiers(target, options.module, options.glue);
    const selector = `.${namespace}, [class*="${namespace}${options.glue}"]`;
    const querySelector = document.querySelectorAll(selector);
    const moduleSelector = `.${options.module}, [class*="${options.module}${options.glue}"]`;
    const childModifier = Synergy.getChildrenWithoutSelector(target, selector, moduleSelector);
    const query = (modifiers !== options.modifiers) ? [options.query] : options.modifiers;

    if ((typeof options.query !== 'undefined') && target instanceof HTMLElement) {
        // add/remove a modifier
        if (options.operator) {
            if (options.operator === 'set') {
                return toggleModifier(options.module, target, options.query, 'set', options.glue);
            } 
            else if (options.operator === 'unset') {
                return toggleModifier(options.module, target, options.query, 'unset', options.glue);
            }
            else if (options.operator === 'add' || options.operator === 'remove') {
                return target.classList[options.operator](namespace);
            }
        }

        // get children with modifier
        if (childModifier.length !== 0) return childModifier;

        // determine if element has modifier
        let matchesQuery = false;

        modifiers.forEach(modifier => {
            query.forEach(queryModifier => {
                if (queryModifier === modifier) return matchesQuery = true;
            });
        });

        if (matchesQuery || options.operator == 'isset') return matchesQuery;

        // @TODO get all components with modifier from document
        // return (querySelector.length === 0) ? false : querySelector;

        return false;
    }
    
    // get modifiers on element
    return (modifiers.length > 0) ? modifiers : false;
}

/**
 * Toggle a modifier on a module
 * 
 * @function toggleModifier
 * 
 * @param {*} moduleName 
 * @param {*} target 
 * @param {*} query 
 * @param {*} operator 
 */
{'fraction_non_alphanumeric': 0.1356793743890518, 'fraction_numerical': 0.0015640273704789834, 'mean_word_length': 2.7590007347538577, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3677953', 'n_tokens_mistral': 1392, 'n_tokens_neox': 1348, 'n_words': 349}