<commit_before>"use strict";

const { homedir } = require( `os` );
const { resolve } = require( `path` );

const rBoolean = /^(?:false|(true))$/;
const rDir = /\/$/;

module.exports = {
    "castBoolean": v => {
        if ( typeof v === `boolean` ) {
            return v;
        }
        const tmp = rBoolean.exec( String( v ).trim() );
        return tmp ? Boolean( tmp[ 1 ] ) : null;
    },
    "castNumber": v => {
        if ( typeof v === `number` ) {
            return v;
        }
        const sv = String( v ).trim();
        return sv ? Number( sv ) : NaN;
    },
    "castString": String,
    "fallback":
        ( v, e ) => ( ( ( v === `` ) || ( v == null ) || ( ( typeof v === `number` ) && isNaN( v ) ) ) ? e : v ),
    "getEnv": v => ( v ? process.env[ v ] : process.env ),
    "inCWD": v => {
        const sv = String( v );
        const tmp = resolve( process.cwd(), sv );
        return rDir.test( sv ) ? `${ tmp }/` : tmp;
    },
    "inDir": ( v, dir ) => {
        const sv = String( v );
        const tmp = resolve( dir, sv );
        return rDir.test( sv ) ? `${ tmp }/` : tmp;
    },
    "inHome": v => {
        const sv = String( v );
        const tmp = resolve( homedir(), sv );
        return rDir.test( sv ) ? `${ tmp }/` : tmp;
    },
    "inParentDir": ( v, dir ) => {
        const sv = String( v );
        const tmp = resolve( dir, `..`, sv );
        return rDir.test( sv ) ? `${ tmp }/` : tmp;
    },
    "join": ( ...v ) => v.join( `` ),
};<commit_msg>Simplifies code.<commit_after>"use strict";

const { dirname, join } = require( `path` );

const rBoolean = /^\s*(?:false|(true))\s*$/;

const cwd = process.cwd();
const { env } = process;
const homedir = require( `os` ).homedir();

const empty = new Set( [ ``, null, undefined ] );

module.exports = {
    "castBoolean": v => {
        if ( typeof v === `boolean` ) {
            return v;
        }
        const tmp = rBoolean.exec( String( v ) );
        return tmp ? Boolean( tmp[ 1 ] ) : null;
    },
    "castNumber": v => {
        if ( typeof v === `number` ) {
            return v;
        }
        const sv = String( v ).trim();
        return sv ? Number( sv ) : NaN;
    },
    "castString": String,
    "fallback": ( v, e ) => ( ( empty.has( v ) || ( ( typeof v === `number` ) && isNaN( v ) ) ) ? e : v ),
    "getEnv": v => ( v ? env[ v ] : env ),
    "inCWD": v => join( cwd, String( v ) ),
    "inDir": ( v, dir ) => join( dir, String( v ) ),
    "inHome": v => join( homedir, String( v ) ),
    "inParentDir": ( v, dir ) => join( dirname( dir ), String( v ) ),
    "join": ( ...v ) => v.join( `` ),
};
{'fraction_non_alphanumeric': 0.21619556913674562, 'fraction_numerical': 0.0007639419404125286, 'mean_word_length': 1.8436482084690553, 'pattern_counts': {'":': 20, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1271641', 'n_tokens_mistral': 914, 'n_tokens_neox': 909, 'n_words': 260}