<commit_before>/*****************/
/***** UTILS *****/
/*****************/
function isArray(obj) {
    return Array.isArray(obj);
}

function isArrayOrObsArray(obj) {
    return isArray(obj) || isObservableArray(obj);
}

function isEmptyObject(obj) {
    if (!isObject(obj)) {
        return false;
    }

    var name;
    for (name in obj) {
        return false;
    }

    return true;
}

function isFuncNotObsArray(obj) {
    return isFunction(obj) && !ko.isObservable(obj);
}

function isFunction(obj) {
    return typeof obj === "function";
}


function promisify(value)
{
    if (!isPromise(value))
    {
        return Promise.resolve(value);
    }
    return value;
}

function isObject(obj) {
    return obj !== null && typeof obj === 'object' && !isArray(obj);
}

function isObservableArray(obj) {
    return ko.isObservable(obj) && 'push' in obj;
}

function isPromise(obj) {
    return obj && typeof obj === "object" && typeof obj.then === "function";
}

/************************/
/***** KO EXTENDERS *****/
/************************/
ko.extenders.nssgSingleSelect = function (target, option) {
    // Before change clears the array before the new value is set
    target.subscribe(function (oldVal) {
        if (oldVal && oldVal.length) {
            oldVal.length = 0;
        }
    }, null, 'beforeChange');

    target.subscribe(function (newVal) {
        if (newVal && newVal.length > 1) {
            newVal.splice(0, newVal.length - 1);
        }
    });<commit_msg>Adding deepReplace and walkObject util functions<commit_after>/*****************/
/***** UTILS *****/
/*****************/

//All properties in objTarget which also occur in objSource will be replaced with the versions
//from objSource.  Nested objects will be processed recursively.  Arrays will be replaced, not merged.
function deepReplace(objTarget, objSource)
{
    for(var key in objSource)
    {
        var value = objSource[key];
        if (typeof value === "object" && !Array.isArray(value))
        {
            objTarget[key] = objTarget[key] || {};
            deepReplace(objTarget[key], value);
        }
        else
        {
            objTarget[key] = value;
        }
    }
}

function isArray(obj) {
    return Array.isArray(obj);
}

function isArrayOrObsArray(obj) {
    return isArray(obj) || isObservableArray(obj);
}

function isEmptyObject(obj) {
    if (!isObject(obj)) {
        return false;
    }

    var name;
    for (name in obj) {
        return false;
    }

    return true;
}

function isFuncNotObsArray(obj) {
    return isFunction(obj) && !ko.isObservable(obj);
}

function isFunction(obj) {
    return typeof obj === "function";
}


function promisify(value)
{
    if (!isPromise(value))
    {
        return Promise.resolve(value);
    }
    return value;
}

function isObject(obj) {
    return obj !== null && typeof obj === 'object' && !isArray(obj);
}

function isObservableArray(obj) {
    return ko.isObservable(obj) && 'push' in obj;
}

function isPromise(obj) {
    return obj && typeof obj === "object" && typeof obj.then === "function";
}

//Recursively walks through objects, invoking the supplied predicate whenever
//the condition function returns true
//
// condition/predicate signature: (value, key, obj)
function walkObject(obj, condition, predicate)
{
    for(var key in obj)
    {
        var value = obj[key];
        if (condition(value, key, obj))
        {
            predicate(value, key, obj);
        }
        if (typeof value === "object" && !Array.isArray(value))
        {
            walkObject(value, condition, predicate);
        }
    }
}

/************************/
/***** KO EXTENDERS *****/
/************************/
ko.extenders.nssgSingleSelect = function (target, option) {
    // Before change clears the array before the new value is set
    target.subscribe(function (oldVal) {
        if (oldVal && oldVal.length) {
            oldVal.length = 0;
        }
    }, null, 'beforeChange');

    target.subscribe(function (newVal) {
        if (newVal && newVal.length > 1) {
            newVal.splice(0, newVal.length - 1);
        }
    });
{'fraction_non_alphanumeric': 0.17484215638659542, 'fraction_numerical': 0.001942690626517727, 'mean_word_length': 2.7479526842584168, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2926755', 'n_tokens_mistral': 1273, 'n_tokens_neox': 1239, 'n_words': 315}