<commit_before>    /* eslint no-unused-vars: 0 */

/***************/
/** Data Sort **/
/***************/
gridState.processors['data-sort'] = {
    input: 'sortFunctions',
    watches: ['sort', 'data'],
    runs: function (options) {
        var originalData = options.changed.data ? options.model.data : options.cache.data;
        options.cache.data = originalData;

        if (options.model.logging) {
            console.log('Sorting the data');
        }

        var sort = options.model.sort;
        var columnsById = options.model.columnsById;

        options.model.data = sort.length === 0 ? originalData : originalData.slice().sort(function (rowA, rowB) {
            for (var i = 0; i < sort.length; i++) {
                var criteria = sort[i];
                var column = columnsById[criteria.sortBy];
                if (!column) {
                    console.warn("Tried to sort on a column that wasn't present in the data", criteria.sortBy);
                    continue;
                }
                var sortFn = gridState.sortFunctions[column.type];
                if (!sortFn) {
                    console.warn('No comparator available for the specified column type, using generic compare', column.type);
                    sortFn = gridState.sortFunctions.generic;
                }
                var valueA = rowA[column.id];
                var valueB = rowB[column.id];
                var result = sortFn(valueA, valueB);
                if (result !== 0) {
                    return criteria.sortAsc ? result : 0 - result;
                }
            }
            return 0;
        });
    }
};

function genericCompare(valueA, valueB) {
    if (valueA === valueB) {
        return 0;
    }
    else {
        return valueA < valueB ? -1 : 1;
    }
}

gridState.sortFunctions = {
    generic: genericCompare,
    text: genericCompare
};
<commit_msg>Allow individual columns to override their sort functions<commit_after>    /* eslint no-unused-vars: 0 */

/***************/
/** Data Sort **/
/***************/
gridState.processors['data-sort'] = {
    input: 'sortFunctions',
    watches: ['sort', 'data'],
    runs: function (options) {
        var originalData = options.changed.data ? options.model.data : options.cache.data;
        options.cache.data = originalData;

        if (options.model.logging) {
            console.log('Sorting the data');
        }

        var sort = options.model.sort;
        var columnsById = options.model.columnsById;

        options.model.data = sort.length === 0 ? originalData : originalData.slice().sort(function (rowA, rowB) {
            for (var i = 0; i < sort.length; i++) {
                var criteria = sort[i];
                var column = columnsById[criteria.sortBy];
                if (!column) {
                    console.warn("Tried to sort on a column that wasn't present in the data", criteria.sortBy);
                    continue;
                }
                var sortFn = column.sortFunction || gridState.sortFunctions[column.type];
                if (!sortFn) {
                    console.warn('No comparator available for the specified column type, using generic compare', column.type);
                    sortFn = gridState.sortFunctions.generic;
                }
                var valueA = rowA[column.id];
                var valueB = rowB[column.id];
                var result = sortFn(valueA, valueB);
                if (result !== 0) {
                    return criteria.sortAsc ? result : 0 - result;
                }
            }
            return 0;
        });
    }
};

function genericCompare(valueA, valueB) {
    if (valueA === valueB) {
        return 0;
    }
    else {
        return valueA < valueB ? -1 : 1;
    }
}

gridState.sortFunctions = {
    generic: genericCompare,
    text: genericCompare
};

{'fraction_non_alphanumeric': 0.12957673331602182, 'fraction_numerical': 0.004674110620618021, 'mean_word_length': 1.7184191954834156, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4249754', 'n_tokens_mistral': 1071, 'n_tokens_neox': 1018, 'n_words': 262}