import {validatePhone,validateIdcar} from "./validateUtil.js"

export const phoneNumber = (number) => {
	if(!number || !validatePhone(number)) return number
	var tel = number
	var reg = /^(\d{3})\d{4}(\d{4})$/;
	return tel.replace(reg, "$1****$2");
}


export const bankNumber = (number) => {
	if(!number ) return number
	let numberStr = `${number}`
	return numberStr.replace(/^(.{4})(?:\d+)(.{4})$/,"$1******$2");
	return numberStr.substr(0, 4) + '****' + numberStr.substr(numberStr.length-4, 4);
}

export const idcarNumber =(number)=>{
	if(!number || !validateIdcar(number))return number
	return number.replace(/^(.{6})(?:\d+)(.{2})$/,"$1**********$2");
}


export const sectionToChinese = (section) =>{
	let chnNumChar = ["零","一","二","三","四","五","六","七","八","九"];
	let chnUnitSection = ["","万","亿","万亿","亿亿"];
	let chnUnitChar = ["","十","百","千"];
    let strIns = '', chnStr = '';
    let unitPos = 0;
    let zero = true;
    while(section > 0){
        let v = section % 10;
        if(v === 0){
            if(!zero){
                zero = true;
                chnStr = chnNumChar[v] + chnStr;
            }
        }else{
            zero = false;
            strIns = chnNumChar[v];
            strIns += chnUnitChar[unitPos];
            chnStr = strIns + chnStr;
        }
        unitPos++;
        section = Math.floor(section / 10);
    }
    return chnStr;
}
