<commit_before>import {BadTypeError, BaseError, MissingValueError} from './errors';
import {Visitable as ASTVisitable} from './parser/ast';


export class FuncParams {
    named: any;
    body: ASTVisitable = null;

    constructor(public passed: any[], params: FuncParam[]) {
        this.named = {};
        if (params === null) {
            return;
        }

        var i = 0;
        params.forEach((param) => {
            if (param.fromVar) {
                this.named[param.name] = passed[i];
                i++;
            } else {
                this.named[param.name] = param.value;
            }
        });
    }

    has(name: string): boolean {
        if (this.named.hasOwnProperty(name)) {
            return true;
        }
        return false;
    }

    get(name: string, missing?: any): any {
        if (this.has(name)) {
            return this.named[name];
        }
        return missing;
    }

    choose<T>(name: string, values: T[], missing?: T): T {
        if (this.has(name)) {
            return values[this.named[name]];
        }
        return missing;
    }

    hasNumber(name: string): boolean {
        return this.has(name) && (typeof this.named[name] == 'number');
    }

    getNumber(name: string): number {
        if (!this.hasNumber(name)) {
            throw new BadTypeError(this.named[name], 'number');
        }
        return this.named[name];
    }

    hasString(name: string): boolean {
        return this.has(name) && (typeof this.named[name] == 'string');
    }

    getString(name: string): string {
        if (!this.hasString(name)) {
            throw new BadTypeError(this.named[name], 'string');
        }
        return this.named[name];
    }

    hasObject(name: string): boolean {
        return this.has(name) && (this.named[name] !== null) && (this.named[name] !== undefined);
    }

    getObject(name: string): string {
        if (!this.hasObject(name)) {
            throw new MissingValueError(this.named[name]);
        }
        return this.named[name];
    }
}


export class FuncParam {
    constructor(public name: string, public value: any, public fromVar: boolean) {
    }

    withValue(value: any): FuncParam {
        return new FuncParam(this.name, value, this.fromVar);
    }<commit_msg>Fix return type for FuncParams~getObject<commit_after>import {BadTypeError, BaseError, MissingValueError} from './errors';
import {Visitable as ASTVisitable} from './parser/ast';


export class FuncParams {
    named: any;
    body: ASTVisitable = null;

    constructor(public passed: any[], params: FuncParam[]) {
        this.named = {};
        if (params === null) {
            return;
        }

        var i = 0;
        params.forEach((param) => {
            if (param.fromVar) {
                this.named[param.name] = passed[i];
                i++;
            } else {
                this.named[param.name] = param.value;
            }
        });
    }

    has(name: string): boolean {
        if (this.named.hasOwnProperty(name)) {
            return true;
        }
        return false;
    }

    get(name: string, missing?: any): any {
        if (this.has(name)) {
            return this.named[name];
        }
        return missing;
    }

    choose<T>(name: string, values: T[], missing?: T): T {
        if (this.has(name)) {
            return values[this.named[name]];
        }
        return missing;
    }

    hasNumber(name: string): boolean {
        return this.has(name) && (typeof this.named[name] == 'number');
    }

    getNumber(name: string): number {
        if (!this.hasNumber(name)) {
            throw new BadTypeError(this.named[name], 'number');
        }
        return this.named[name];
    }

    hasString(name: string): boolean {
        return this.has(name) && (typeof this.named[name] == 'string');
    }

    getString(name: string): string {
        if (!this.hasString(name)) {
            throw new BadTypeError(this.named[name], 'string');
        }
        return this.named[name];
    }

    hasObject(name: string): boolean {
        return this.has(name) && (this.named[name] !== null) && (this.named[name] !== undefined);
    }

    getObject(name: string): any {
        if (!this.hasObject(name)) {
            throw new MissingValueError(this.named[name]);
        }
        return this.named[name];
    }
}


export class FuncParam {
    constructor(public name: string, public value: any, public fromVar: boolean) {
    }

    withValue(value: any): FuncParam {
        return new FuncParam(this.name, value, this.fromVar);
    }
{'fraction_non_alphanumeric': 0.1427637314734089, 'fraction_numerical': 0.00043591979075850045, 'mean_word_length': 1.9973873285434356, 'pattern_counts': {'":': 0, '<': 5, '<?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': '7015011', 'n_tokens_mistral': 1386, 'n_tokens_neox': 1342, 'n_words': 308}