nodejs 如何批量替换接口文件里面的信息?
接口文件是自动生成的,生成的method为DELETE的data需要修改为[data]如何能批量的替换掉,一个文件里会有多个export async function
export async function deleteE (
data: {
app: any;
},
options?: Record<string, any>,
): Promise<CommonResult<any>> {
return axios({
method: 'DELETE',
url: `/api/app/`,
data: {
...data,
},
...(options || {}),
})
}
替换成
export async function deleteE (
data: {
app: any;
},
options?: Record<string, any>,
): Promise<CommonResult<any>> {
return axios({
method: 'DELETE',
url: `/api/app/`,
data: [data],
...(options || {}),
})
}
回复
1个回答

test
2024-07-03
const fs = require('fs');
let content = fs.readFileSync('yourfile.js', 'utf8');
// 用正则表达式替换内容
let newContent = content.replace(/data: \{\n\s+\.\.\.data,\n\s+\}/g, 'data: [data]');
fs.writeFileSync('yourfile.js', newContent);
回复

适合作为回答的
- 经过验证的有效解决办法
- 自己的经验指引,对解决问题有帮助
- 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
- 询问内容细节或回复楼层
- 与题目无关的内容
- “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容