/** @format */
/**
 * 生成十六进制的随机颜色值
 * params {number} num
 *
 */
export const getRandomColor = () => {
    return '#' + ((Math.random() * 0xffffff) << 0).toString(16);
};
/**
 * 千位数字格式化
 */
const options = {style: 'decimal', useGrouping: true};
const numberFormat = new Intl.NumberFormat('hanidec', options);
export const formatNumer: (num: number) => string = numberFormat.format;

/**
 * 计算百分比
 */
const numberFormatToRate = new Intl.NumberFormat('hanidec', {
    style: 'percent',
});

export const reduceRate: (num: number) => string = numberFormatToRate.format;

//增加id
export const addId = (arr: any[], prefix: string) => {
    return arr.map((element, index) => {
        let currentArr = element;
        element.child = element.child || [];
        if (element.child.length) {
            currentArr.child = addId(element.child, prefix + '-' + index);
        }
        return {
            ...element,
            id: prefix + '-' + index,
        };
    });
};
