<commit_before>/**
 * truncate text to a specified length.
 *
 * {{ 'this is a big city!' | truncate 10 '...' }} => this is...
 */

function truncate(str, length, ellipses) {
    length = length || 30;
    if(ellipses === undefined){
        ellipses = '...';
    }
    ellipses = '' + ellipses;
    return (str.length > length ? str.slice(0, length - ellipses.length) + ellipses : str);
}

export default truncate;<commit_msg>add ability to preserve words from being cut<commit_after>/**
 * truncate text to a specified length.
 *
 * {{ 'this is a big city!' | truncate 11 '...' true }} => this is...
 */

function truncate(str, length, ellipses, preserveWords) {
    length = length || 30;
    str = (str.length > length) ? str.slice(0, length) : str;

    if (preserveWords) {
        str = str.substr(0, Math.min(str.length, str.lastIndexOf(' ')));
    }

    if (ellipses === undefined) {
        ellipses = '...';
    }
    ellipses = '' + ellipses;

    return str + ellipses;
}

export default truncate;
{'fraction_non_alphanumeric': 0.1671612265084075, 'fraction_numerical': 0.010880316518298714, 'mean_word_length': 2.6934306569343067, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1035996', 'n_tokens_mistral': 347, 'n_tokens_neox': 331, 'n_words': 94}