fs 正在读取第一个 CSV 属性 作为字符串。打字稿
fs is reading the first CSV property as string. Typescript
我在 Typescript 中使用 fs 来读取 CSV 文件,它读起来很好,除了因为我得到第一个 属性 作为字符串。对于任何一行,我都会得到这个输出:
{
'Cliente': 'text',
nom_cli: 'text',
sexo: '-',
fec_nac: 'date',
e_mail: '0',
ind_leal: '1',
Id_externo: '052'
}
我正在使用这个界面来分隔字段:
export interface clientCSV {
'Cliente': string;
'nom_cli': string;
'sexo': string;
'fec_nac': string;
'e_mail': string;
'ind_leal': string;
'Id_externo':string;
}
并像这样读取文件:
fs.createReadStream(path)
.pipe(csv())
.on('data', (row: clientCSV) => {
console.log(row);
})
.on('end', async () => { ... })
有什么建议吗?
因为Cliente
中第一个特殊字符:
在浏览器控制台中尝试:
var a = {
'Cliente': 'text',
nom_cli: 'text',
sexo: '-',
fec_nac: 'date',
e_mail: '0',
ind_leal: '1',
Id_externo: '052'
}
a
Id_externo: "052"
e_mail: "0"
fec_nac: "date"
ind_leal: "1"
nom_cli: "text"
sexo: "-"
"\ufeffCliente": "text"
我在 Typescript 中使用 fs 来读取 CSV 文件,它读起来很好,除了因为我得到第一个 属性 作为字符串。对于任何一行,我都会得到这个输出:
{
'Cliente': 'text',
nom_cli: 'text',
sexo: '-',
fec_nac: 'date',
e_mail: '0',
ind_leal: '1',
Id_externo: '052'
}
我正在使用这个界面来分隔字段:
export interface clientCSV {
'Cliente': string;
'nom_cli': string;
'sexo': string;
'fec_nac': string;
'e_mail': string;
'ind_leal': string;
'Id_externo':string;
}
并像这样读取文件:
fs.createReadStream(path)
.pipe(csv())
.on('data', (row: clientCSV) => {
console.log(row);
})
.on('end', async () => { ... })
有什么建议吗?
因为Cliente
中第一个特殊字符:
在浏览器控制台中尝试:
var a = {
'Cliente': 'text',
nom_cli: 'text',
sexo: '-',
fec_nac: 'date',
e_mail: '0',
ind_leal: '1',
Id_externo: '052'
}
a
Id_externo: "052"
e_mail: "0"
fec_nac: "date"
ind_leal: "1"
nom_cli: "text"
sexo: "-"
"\ufeffCliente": "text"