function ProcessNameValues(nameValues, skipEmpty = false, delimiter = "[]") {
    let result = {}, i, nameParts;

    for (i = 0; i < nameValues.length; i++) {
        const value = nameValues[i].value;
        if (skipEmpty && (value === '' || value === null)) continue;

        const name = nameValues[i].name;
        const arrName = name.substr(0, name.indexOf('['));

        // 最外层奖励字段
        if (arrName === "") {
            result[name] = value
            continue;
        }

        if (delimiter === "[]") {
            nameParts = name.match(/(?<=\[)(.*?)(?=\])/g);
        } else {
            nameParts = name.split('.')
        }

        const namePartLens = nameParts.length
        let isArr = namePartLens === 1 && nameParts[0] === ""

        // 初始化第一维字段
        result[arrName] = result[arrName] ?? (isArr ? [] : {})

        // 第一维字段是数组,赋值后跳过
        if (isArr) {
            result[arrName].push(value)
            continue;
        }

        isArr = nameParts[namePartLens - 1] === ""
        let temp = result[arrName]
        for (let j = 0; j < namePartLens; j++) {
            const key = nameParts[j]
            if (!Object.prototype.hasOwnProperty.call(temp, key)) {
                if (j === namePartLens - 1) {
                    if (isArr) {
                        temp.push(value)
                    } else {
                        temp[key] = value
                    }
                } else if (j === namePartLens - 2) {
                    if (isArr) {
                        temp[key] = []
                    } else {
                        temp[key] = {}
                    }
                } else {
                    temp[key] = {}
                }
            }
            temp = temp[key]
        }
    }

    return result;
}

function ArrayRand(arr) {
    let index = Math.floor(Math.random() * arr.length)
    return arr[index]
}

const toString = Object.prototype.toString;

function is(val, type) {
    return toString.call(val) === `[object ${type}]`;
}

function isDef(val) {
    return typeof val !== "undefined";
}

function isUnDef(val) {
    return !isDef(val);
}

function isObject(val) {
    return val !== null && is(val, "Object");
}

function isEmpty(val) {
    if (isArray(val) || isString(val)) {
        return val.length === 0;
    }

    if (val instanceof Map || val instanceof Set) {
        return val.size === 0;
    }

    if (isObject(val)) {
        return Object.keys(val).length === 0;
    }

    return !!(isNull(val) || isUnDef(val));
}

function isDate(val) {
    return is(val, "Date");
}

function isNull(val) {
    return val === null;
}

function isNullAndUnDef(val) {
    return isUnDef(val) && isNull(val);
}

function isNullOrUnDef(val) {
    return isUnDef(val) || isNull(val);
}

function isNumber(val) {
    return is(val, "Number");
}

function isPromise(val) {
    return is(val, "Promise") && isObject(val) && isFunction(val.then) && isFunction(val.catch);
}

function isString(val) {
    return is(val, "String");
}

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

function isBoolean(val) {
    return is(val, "Boolean");
}

function isArray(val) {
    return val && Array.isArray(val);
}

