SOURCE

const demoStr = `
areaCode (string, optional): 区域编码 ,
areaName (string, optional): 区域名称 ,
createTime (string, optional): 创建时间 ,
creator (string, optional): 创建人 ,
creatorName (string, optional): 创建人姓名 ,
doNo (string, optional): 发运单号 ,
doStatus (string, optional): 发运单状态 ,
driverName (string, optional): 司机姓名 ,
driverTel (string, optional): 司机电话 ,
dtNo (string, optional): 发运任务号 ,
dtStatus (string, optional): 发运任务状态 ,
equipmentName (string, optional): 运输设备类型 ,
estimatedArrivalTime (string, optional): 预计到达时间 ,
id (integer, optional): 主键Id ,
modifier (string, optional): 修改人 ,
modifierName (string, optional): 修改人姓名 ,
modifyTime (string, optional): 修改时间 ,
pickQty (integer, optional): 商品数量 ,
realtimeTemperature (string, optional): 温度 ,
shopCode (string, optional): 门店编码 ,
shopName (string, optional): 门店名称 ,
stationCode (string, optional): 物流中心编码 ,
stationName (string, optional): 物流中心名称 ,
vehiclePlateNumber (string, optional): 车牌号
`


function str2pt(swaggerModelStr) {
    const lines = swaggerModelStr.replaceAll(',', '').trim().split('\n')
    console.log(lines)
    const propTypes = lines.map((cur) => {
        const [_, propName, propType, propDesc] = cur.trim().match(/^(\w+)\s\((\w+)\s.*:\s(.*)$/)
        let pt = 'PropTypes.any'
        switch (propType) {
            case 'string':
                pt = 'PropTypes.string'
                break
            case 'integer':
            case 'float':
                pt = 'PropTypes.number'
                break
            case 'boolean':
                pt = 'PropTypes.bool'
                break
            default:
                pt = 'PropTypes.any'
        }
        return `${propName}: ${pt}, // ${propDesc}`
    })
    console.log(propTypes.join('\n'))
}
str2pt(demoStr)
console 命令行工具 X clear

                    
>
console