dist/index.js
function iterate(value, callback, accumulate, assign) {
    let breakFlag = false;
    function newIteration(index) {
        let instance = {
            'break': () => breakFlag = true,
            accKeyName: index,
            key: (name) => instance.accKeyName = name
        };
        return instance;
    }
    let iterateInstanceAsync = async (callback, val, index) => {
        let iteration = newIteration(index);
        pushRet(await callback(val, index, iteration), iteration);
    };
    let iterateInstance = (callback, val, index) => {
        let iteration = newIteration(index);
        pushRet(callback(val, index, iteration), iteration);
    };
    let ret = isObject(accumulate) ? accumulate : isArray(accumulate) ? accumulate : accumulate === true ? false : value;
    let pushRet = (val, iteration) => {
        if (isUndefined(val))
            return;
        if (isObject(accumulate)) {
            ret[iteration.accKeyName] = assign
                ? Object.assign(ret[iteration.accKeyName] || {}, val)
                : val;
        }
        if (isArray(accumulate))
            ret.push(val);
        if (accumulate === true)
            ret = ret || val;
    };
    return isAsyncFunction(callback)
        ? new Promise(async (resolve) => {
            if (isArray(value)) {
                for (let index = 0; index < value.length; ++index) {
                    if (breakFlag)
                        break;
                    await iterateInstanceAsync(callback, value[index], index);
                }
                resolve(ret);
            }
            if (isObject(value)) {
                await iterate(Object.keys(value), async (index, _, iteration) => {
                    if (breakFlag)
                        iteration.break();
                    await iterateInstanceAsync(callback, value[index], index);
                });
                resolve(ret);
            }
            if (isInteger(value)) {
                for (let index = 0; index < value; ++index) {
                    if (breakFlag)
                        break;
                    await iterateInstanceAsync(callback, index, index);
                }
                resolve(ret);
            }
            resolve(false);
        })
        : (() => {
            if (isArray(value)) {
                for (let index = 0; index < value.length; ++index) {
                    if (breakFlag)
                        break;
                    iterateInstance(callback, value[index], index);
                }
                return ret;
            }
            if (isObject(value)) {
                iterate(Object.keys(value), (index, _, iteration) => {
                    if (breakFlag)
                        iteration.break();
                    iterateInstance(callback, value[index], index);
                });
                return ret;
            }
            if (isInteger(value)) {
                for (let index = 0; index < value; ++index) {
                    if (breakFlag)
                        break;
                    iterateInstance(callback, index, index);
                }
                return ret;
            }
            return false;
        })();
}
function iterate(value, callback, accumulate, assign) {
    let breakFlag = false;
    function newIteration(index) {
        let instance = {
            'break': () => breakFlag = true,
            accKeyName: index,
            key: (name) => instance.accKeyName = name
        };
        return instance;
    }
    let iterateInstanceAsync = async (callback, val, index) => {
        let iteration = newIteration(index);
        pushRet(await callback(val, index, iteration), iteration);
    };
    let iterateInstance = (callback, val, index) => {
        let iteration = newIteration(index);
        pushRet(callback(val, index, iteration), iteration);
    };
    let ret = isObject(accumulate) ? accumulate : isArray(accumulate) ? accumulate : accumulate === true ? false : value;
    let pushRet = (val, iteration) => {
        if (isUndefined(val))
            return;
        if (isObject(accumulate)) {
            ret[iteration.accKeyName] = assign
                ? Object.assign(ret[iteration.accKeyName] || {}, val)
                : val;
        }
        if (isArray(accumulate))
            ret.push(val);
        if (accumulate === true)
            ret = ret || val;
    };
    return isAsyncFunction(callback)
        ? new Promise(async (resolve) => {
            if (isArray(value)) {
                for (let index = 0; index < value.length; ++index) {
                    if (breakFlag)
                        break;
                    await iterateInstanceAsync(callback, value[index], index);
                }
                resolve(ret);
            }
            if (isObject(value)) {
                await iterate(Object.keys(value), async (index, _, iteration) => {
                    if (breakFlag)
                        iteration.break();
                    await iterateInstanceAsync(callback, value[index], index);
                });
                resolve(ret);
            }
            if (isInteger(value)) {
                for (let index = 0; index < value; ++index) {
                    if (breakFlag)
                        break;
                    await iterateInstanceAsync(callback, index, index);
                }
                resolve(ret);
            }
            resolve(false);
        })
        : (() => {
            if (isArray(value)) {
                for (let index = 0; index < value.length; ++index) {
                    if (breakFlag)
                        break;
                    iterateInstance(callback, value[index], index);
                }
                return ret;
            }
            if (isObject(value)) {
                iterate(Object.keys(value), (index, _, iteration) => {
                    if (breakFlag)
                        iteration.break();
                    iterateInstance(callback, value[index], index);
                });
                return ret;
            }
            if (isInteger(value)) {
                for (let index = 0; index < value; ++index) {
                    if (breakFlag)
                        break;
                    iterateInstance(callback, index, index);
                }
                return ret;
            }
            return false;
        })();
}
[[include: iterate.md]]

@param value
@param callback
@param accumulate
@param assign