dist/@ajsf/core/esm2015/lib/shared/utility.functions.js
/**
 * 'forEachCopy' function
 *
 * Iterates over all items in the first level of an object or array
 * and calls an iterator function on each item. Returns a new object or array
 * with the same keys or indexes as the original, and values set to the results
 * of the iterator function.
 *
 * Does NOT recursively iterate over items in sub-objects or sub-arrays.
 *
 * // {Object | Array} object - The object or array to iterate over
 * // {function} fn - The iterator funciton to call on each item
 * // {boolean = false} errors - Show errors?
 * // {Object | Array} - The resulting object or array
 */
'forEachCopy' function
Iterates over all items in the first level of an object or array
and calls an iterator function on each item. Returns a new object or array
with the same keys or indexes as the original, and values set to the results
of the iterator function.

Does NOT recursively iterate over items in sub-objects or sub-arrays.

{Object | Array} object - The object or array to iterate over
{function} fn - The iterator funciton to call on each item
{boolean = false} errors - Show errors.
{Object | Array} - The resulting object or array
' forEachCopy ' function Iterates over all items in the first level of an object or array and calls an iterator function on each item . Returns a new object or array with the same keys or indexes as the original and values set to the results of the iterator function . Does NOT recursively iterate over items in sub - objects or sub - arrays . { Object | Array } object - The object or array to iterate over { function } fn - The iterator funciton to call on each item { boolean = false } errors - Show errors . { Object | Array } - The resulting object or array
function forEachCopy(object, fn, errors = false) {
    if (!hasValue(object)) {
        return;
    }
    if ((isObject(object) || isArray(object)) && typeof object !== 'function') {
        const newObject = isArray(object) ? [] : {};
        for (const key of Object.keys(object)) {
            newObject[key] = fn(object[key], key, object);
        }
        return newObject;
    }
    if (errors) {
        if (typeof fn !== 'function') {
            console.error('forEachCopy error: Iterator must be a function.');
            console.error('function', fn);
        }
        if (!isObject(object) && !isArray(object)) {
            console.error('forEachCopy error: Input object must be an object or array.');
            console.error('object', object);
        }
    }
}
function forEachCopy ( object , fn , errors = false ) { if ( ! hasValue ( object ) ) { return ; } if ( ( isObject ( object ) || isArray ( object ) ) && typeof object !== 'function' ) { const newObject = isArray ( object ) ? [ ] : { } ; for ( const key of Object . keys ( object ) ) { newObject [ key ] = fn ( object [ key ] , key , object ) ; } return newObject ; } if ( errors ) { if ( typeof fn !== 'function' ) { console . error ( 'forEachCopy error: Iterator must be a function.' ) ; console . error ( 'function' , fn ) ; } if ( ! isObject ( object ) && ! isArray ( object ) ) { console . error ( 'forEachCopy error: Input object must be an object or array.' ) ; console . error ( 'object' , object ) ; } } }
'forEachCopy' function
 Iterates over all items in the first level of an object or array
 and calls an iterator function on each item.
' forEachCopy ' function Iterates over all items in the first level of an object or array and calls an iterator function on each item .