<commit_before>"use strict";

import isValidPackageName from "validate-npm-package-name";
import XRegExp from "xregexp";

export default class Substituter {

    replaceAllCommands(text) {
        text = this.replaceInstallCommands(text);
        text = this.replaceConfigCommands(text);
        text = this.replaceLinkCommands(text);
        text = this.replaceRebuildCommands(text);
        text = this.replaceCacheCleanCommands(text);
        return text;
    }

    validatePackageName(packageName) {
        // TODO: Support "@josephduffy/yarn-ball@1.0.1" style packages
        let packageNameWithoutVersion = packageName.split("@")[0];
        if (!isValidPackageName(packageNameWithoutVersion).validForOldPackages) {
            throw new Error(`${packageName} is not a valid package name`);
        }
    }

    replaceInstallCommands(text) {
        const mappings = {
            "add": {
                "regex": /i(?!nit)(?:nstall)?/,
                "supportsGlobal": true,
                "minParameters": 1,
                "parameterValidator": this.validatePackageName
            },
            "remove": {
                "regex": /(?:uninstall|remove|rm|r|un|unlink)/,
                "supportsGlobal": true,
                "minParameters": 1,
                "parameterValidator": this.validatePackageName
            }
        }

        const flagMappings = {<commit_msg>Extended package name validation logic<commit_after>"use strict";

import isValidPackageName from "validate-npm-package-name";
import XRegExp from "xregexp";

export default class Substituter {

    replaceAllCommands(text) {
        text = this.replaceInstallCommands(text);
        text = this.replaceConfigCommands(text);
        text = this.replaceLinkCommands(text);
        text = this.replaceRebuildCommands(text);
        text = this.replaceCacheCleanCommands(text);
        return text;
    }

    validatePackageName(packageName) {
        let splitPackageName = packageName.split("@")[0]
        let packageNameWithoutVersion = splitPackageName[0] == '' ? '@'+splitPackageName[1] : splitPackageName[0];

        if (!isValidPackageName(packageNameWithoutVersion).validForOldPackages) {
            throw new Error(`${packageName} is not a valid package name`);
        }
    }

    replaceInstallCommands(text) {
        const mappings = {
            "add": {
                "regex": /i(?!nit)(?:nstall)?/,
                "supportsGlobal": true,
                "minParameters": 1,
                "parameterValidator": this.validatePackageName
            },
            "remove": {
                "regex": /(?:uninstall|remove|rm|r|un|unlink)/,
                "supportsGlobal": true,
                "minParameters": 1,
                "parameterValidator": this.validatePackageName
            }
        }

        const flagMappings = {
{'fraction_non_alphanumeric': 0.11430575035063113, 'fraction_numerical': 0.004207573632538569, 'mean_word_length': 2.279310344827586, 'pattern_counts': {'":': 20, '<': 3, '<?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': '6467401', 'n_tokens_mistral': 773, 'n_tokens_neox': 754, 'n_words': 144}