<commit_before>'use strict';

module.exports = function defineCompactProperty(that, opt) {

    if (_.isArray(opt)) {

        opt.forEach(o => defineCompactProperty(that, o));
        return;
    }

    var value = opt.startValue,
        name = opt.name,
        history = opt.history,
        evtName = opt.evtName || 'change.' + name;

    if (history) {
        if (typeof(history) !== 'object') history = {};
        if (!history.hasOwnProperty('tag')) history.tag = 'change ' + name;
        if (!history.hasOwnProperty('chainId')) history.chainId = Symbol();
    }

    Object.defineProperty(that, name, {

        set: set,
        get: () => value,
    });

    return {
        name: name,
        evtName: evtName,
    };


    ///////////////////////////////////////////////////////////////

    function set(v) {

        v = fixType(v);

        if (v === value || isInvalidValue(v)) {
            return;
        }

        save(value, v);

        value = v;

        this.emit(evtName, value);
    }

    function save(oldValue, newValue) {

        if (!history) return;

        am.history.saveChain(history.chainId, [set, oldValue], [set, newValue], history.tag, 312);
    }

    function fixType(v) {

        switch (opt.type) {
            case 'float': v = parseFloat(v); break;
            case 'int': v = parseInt(v); break;
            case 'boolean': v = !!v; break;
            case 'string': v = '' + v; break;
        }

        return v;<commit_msg>fix value sotring<commit_after>'use strict';

module.exports = function defineCompactProperty(proto, opt) {

    if (_.isArray(opt)) {

        opt.forEach(o => defineCompactProperty(proto, o));
        return;
    }

    var valMap = new WeakMap(),
        name = opt.name,
        history = opt.history,
        evtName = opt.evtName || 'change.' + name;

    if (history) {
        if (typeof(history) !== 'object') history = {};
        if (!history.hasOwnProperty('tag')) history.tag = 'change ' + name;
        if (!history.hasOwnProperty('chainId')) history.chainId = Symbol();
    }

    Object.defineProperty(proto, name, {set: set, get: get});

    return {
        name: name,
        evtName: evtName,
    };


    ///////////////////////////////////////////////////////////////

    function get() {
        return valMap.has(this) ? valMap.get(this) : opt.startValue;
    }

    function set(v) {

        v = fixType(v);
        var value = get.call(this);

        if (v === value || isInvalidValue(v)) {
            return;
        }

        save(value, v);

        value = v;

        valMap.set(this, value);

        this.emit(evtName, value);
    }

    function save(oldValue, newValue) {

        if (!history) return;

        am.history.saveChain(history.chainId, [set, oldValue], [set, newValue], history.tag, 312);
    }

    function fixType(v) {

        switch (opt.type) {
            case 'float': v = parseFloat(v); break;
            case 'int': v = parseInt(v); break;
            case 'boolean': v = !!v; break;
            case 'string': v = '' + v; break;
        }

        return v;
{'fraction_non_alphanumeric': 0.18415969092079845, 'fraction_numerical': 0.0019317450096587251, 'mean_word_length': 1.71353711790393, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '3618747', 'n_tokens_mistral': 953, 'n_tokens_neox': 919, 'n_words': 219}