<commit_before>// src/dice-roller.js
'use strict';

const facesMatcher = /^(?:\[(\s*(?:[^|[\]]+\s*)+(?:\s*\|\s*(?:[^|[\]]+\s*)+)+\s*)\])$/;
const diceMatcher = /^(?:(\d*)d(\d+|%)([+-]\d+)?)$/;

/* private helpers */
let rollDice = (input) => {
    let diceMatch = diceMatcher.exec(input);

    if (diceMatch === null) {
        return new InvalidInputError(input);
    }

    let diceCount = parseInt(diceMatch[1], 10) || 1;
    let dieFaces = diceMatch[2] === '%' ? 100 : parseInt(diceMatch[2], 10);
    let modifier = diceMatch.length > 3 ? parseInt(diceMatch[3]) || 0 : 0;

    // another invalid check just in case
    if (isNaN(dieFaces)) {
        return new InvalidInputError(input);
    }

    let result = modifier || 0;
    let rolls = [];

    for (let i = 0; i < diceCount; i++) {
        let resultFace = getFaceIndex(dieFaces);
        result += resultFace;
        rolls.push(resultFace);
    }

    return {
        result,
        faces: dieFaces,
        rolls,
        modifier
    };
};

let rollFaces = (input) => {
    let faceMatch = facesMatcher.exec(input);

    if (faceMatch === null) {
        return new InvalidInputError(input);
    }

    let faces = faceMatch[1].split('|').map(face => face.trim());
    let faceIndex = getFaceIndex(faces.length - 1);
    let result = faces[faceIndex - 1].trim();

    return {
        result,
        faces
    };
};

/** Get an integer from [1-max] inclusive */
let getFaceIndex = (max) => {
    return Math.floor(Math.random() * max) + 1;
};

/* DiceRoller */
class DiceRoller {
    roll(input) {<commit_msg>Fixed faces off by 1 error<commit_after>// src/dice-roller.js
'use strict';

const facesMatcher = /^(?:\[(\s*(?:[^|[\]]+\s*)+(?:\s*\|\s*(?:[^|[\]]+\s*)+)+\s*)\])$/;
const diceMatcher = /^(?:(\d*)d(\d+|%)([+-]\d+)?)$/;

/* private helpers */
let rollDice = (input) => {
    let diceMatch = diceMatcher.exec(input);

    if (diceMatch === null) {
        return new InvalidInputError(input);
    }

    let diceCount = parseInt(diceMatch[1], 10) || 1;
    let dieFaces = diceMatch[2] === '%' ? 100 : parseInt(diceMatch[2], 10);
    let modifier = diceMatch.length > 3 ? parseInt(diceMatch[3]) || 0 : 0;

    // another invalid check just in case
    if (isNaN(dieFaces)) {
        return new InvalidInputError(input);
    }

    let result = modifier || 0;
    let rolls = [];

    for (let i = 0; i < diceCount; i++) {
        let resultFace = getFaceIndex(dieFaces);
        result += resultFace;
        rolls.push(resultFace);
    }

    return {
        result,
        faces: dieFaces,
        rolls,
        modifier
    };
};

let rollFaces = (input) => {
    let faceMatch = facesMatcher.exec(input);

    if (faceMatch === null) {
        return new InvalidInputError(input);
    }

    let faces = faceMatch[1].split('|').map(face => face.trim());
    let faceIndex = getFaceIndex(faces.length);
    let result = faces[faceIndex - 1].trim();

    return {
        result,
        faces
    };
};

/** Get an integer from [1-max] inclusive */
let getFaceIndex = (max) => {
    return Math.floor(Math.random() * max) + 1;
};

/* DiceRoller */
class DiceRoller {
    roll(input) {
{'fraction_non_alphanumeric': 0.1925387290546949, 'fraction_numerical': 0.013910844135314574, 'mean_word_length': 2.5510662177328842, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '7442950', 'n_tokens_mistral': 1124, 'n_tokens_neox': 1075, 'n_words': 248}