<commit_before>export class ObjectParser<T> {
    private properties: Map<string, IParserProperty> = new Map();

    public constructor(public targetFactory: () => T) { };

    public parse(object: Object): T {
        let target = this.targetFactory();
        for(const property of this.properties.values()) {
            if(object[property.name]) {
                target[property.name] = property.handler(object[property.name]);
            } else if((typeof(property.required) === 'function' && property.required(object, property.name))
                   || (typeof(property.required) === 'boolean' && property.required)) {
                throw new Error(`Missing property: ${property.name}`);
            }
        }
        return target;<commit_msg>allow empty object and add properties argument to parser constructor as syntactic sugar<commit_after>export class ObjectParser<T> {
    private properties: Map<string, IParserProperty> = new Map();

    public constructor(public targetFactory: () => T, ...properties: IParserProperty[]) {
        if(properties)
            this.addProperties.apply(this, properties);
    };

    public parse(object: Object): T {
        object = object || { };

        let target = this.targetFactory();
        for(const property of this.properties.values()) {
            if(object[property.name]) {
                target[property.name] = property.handler(object[property.name]);
            } else if((typeof(property.required) === 'function' && property.required(object, property.name))
                   || (typeof(property.required) === 'boolean' && property.required)) {
                throw new Error(`Missing property: ${property.name}`);
            }
        }
        return target;
{'fraction_non_alphanumeric': 0.134902411021814, 'fraction_numerical': 0.0, 'mean_word_length': 2.661764705882353, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '216152', 'n_tokens_mistral': 433, 'n_tokens_neox': 422, 'n_words': 102}