<commit_before>const Path = require('path')
const {stat} = require('fs/promises')
const {cranRoot} = require('./config')

const isChildOf = (parent, dir) => {
    const relative = Path.relative(parent, dir)
    return relative && !relative.startsWith('..') && !Path.isAbsolute(relative)
}

const isCranRepoPath = path =>
    isChildOf(cranRoot, path)

const getRepoPath = path => {
    const repoPath = Path.join(cranRoot, path)
    if (!isCranRepoPath(repoPath)) {
        throw new Error('Illegal path:', path)
    }
    return repoPath
}

const getPackageInfo = path => {
    const {dir, base} = Path.parse(path)
    const VERSION_REGEX = /(.*?)(?:_([\d\.]+))?(\..*)/
    const result = base.match(VERSION_REGEX)<commit_msg>Allowed dashes in version number.<commit_after>const Path = require('path')
const {stat} = require('fs/promises')
const {cranRoot} = require('./config')

const isChildOf = (parent, dir) => {
    const relative = Path.relative(parent, dir)
    return relative && !relative.startsWith('..') && !Path.isAbsolute(relative)
}

const isCranRepoPath = path =>
    isChildOf(cranRoot, path)

const getRepoPath = path => {
    const repoPath = Path.join(cranRoot, path)
    if (!isCranRepoPath(repoPath)) {
        throw new Error('Illegal path:', path)
    }
    return repoPath
}

const getPackageInfo = path => {
    const {dir, base} = Path.parse(path)
    const VERSION_REGEX = /(.*?)(?:_([\d\.-]+))?(\..*)/
    const result = base.match(VERSION_REGEX)
{'fraction_non_alphanumeric': 0.17084745762711864, 'fraction_numerical': 0.0, 'mean_word_length': 3.7766990291262137, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '6180854', 'n_tokens_mistral': 494, 'n_tokens_neox': 499, 'n_words': 113}