src/utilities.client.js
function (obj, clone, keyTransformFunc) {
    // primitive types don't need to be cloned or further traversed
    if (obj === null || typeof (obj) !== 'object' || Object.prototype.toString.call(obj) === '[object Date]') return obj;

    let result;

    if (Array.isArray(obj)) {
        // obj is an array, keys are numbers and never need to be escaped
        result = clone ? new Array(obj.length) : obj;
        for (let i = 0; i < obj.length; i++) {
            const val = _traverseObject(obj[i], clone, keyTransformFunc);
            if (clone) result[i] = val;
        }
    } else {
        // obj is an object, all keys need to be checked
        result = clone ? {} : obj;
        for (const key in obj) {
            const val = _traverseObject(obj[key], clone, keyTransformFunc);
            const escapedKey = keyTransformFunc(key);
            if (key === escapedKey) {
                // key doesn't need to be renamed
                if (clone) result[key] = val;
            } else {
                // key needs to be renamed
                result[escapedKey] = val;
                if (!clone) delete obj[key];
            }
        }
    }

    return result;
}
function (obj, clone, keyTransformFunc) {
    // primitive types don't need to be cloned or further traversed
    if (obj === null || typeof (obj) !== 'object' || Object.prototype.toString.call(obj) === '[object Date]') return obj;

    let result;

    if (Array.isArray(obj)) {
        // obj is an array, keys are numbers and never need to be escaped
        result = clone ? new Array(obj.length) : obj;
        for (let i = 0; i < obj.length; i++) {
            const val = _traverseObject(obj[i], clone, keyTransformFunc);
            if (clone) result[i] = val;
        }
    } else {
        // obj is an object, all keys need to be checked
        result = clone ? {} : obj;
        for (const key in obj) {
            const val = _traverseObject(obj[key], clone, keyTransformFunc);
            const escapedKey = keyTransformFunc(key);
            if (key === escapedKey) {
                // key doesn't need to be renamed
                if (clone) result[key] = val;
            } else {
                // key needs to be renamed
                result[escapedKey] = val;
                if (!clone) delete obj[key];
            }
        }
    }

    return result;
}
function ( obj , clone , keyTransformFunc ) { // primitive types don't need to be cloned or further traversed if ( obj === null || typeof ( obj ) !== 'object' || Object . prototype . toString . call ( obj ) === '[object Date]' ) return obj ; let result ; if ( Array . isArray ( obj ) ) { // obj is an array, keys are numbers and never need to be escaped result = clone ? new Array ( obj . length ) : obj ; for ( let i = 0 ; i < obj . length ; i ++ ) { const val = _traverseObject ( obj [ i ] , clone , keyTransformFunc ) ; if ( clone ) result [ i ] = val ; } } else { // obj is an object, all keys need to be checked result = clone ? { } : obj ; for ( const key in obj ) { const val = _traverseObject ( obj [ key ] , clone , keyTransformFunc ) ; const escapedKey = keyTransformFunc ( key ) ; if ( key === escapedKey ) { // key doesn't need to be renamed if ( clone ) result [ key ] = val ; } else { // key needs to be renamed result [ escapedKey ] = val ; if ( ! clone ) delete obj [ key ] ; } } } return result ; }
Traverses an object, creates a deep clone if requested and transforms object keys using a provided function.
@param obj Object to traverse, it must not contain circular references!
@param clone If true, object is not modified but cloned.
@param keyTransformFunc Function used to transform the property names. It has one string argument and one string return value.
@returns {*}
@private
Traverses an object creates a deep clone if requested and transforms object keys using a provided function .