저는 신용 카드 식별 및 유효성 검사를위한 프로젝트를 진행하고 있습니다. 노드 파일을 사용하여 다른 파일에 쓰기를 시도하고 있습니다. 배열을 사용하고,이 함수가 출력하는 각 행을 채 웁니다. 전체 코드 블록은 다음과 같습니다.어떻게하면이 신용 카드 유효성 검사기/식별자 출력을 배열로 만들 수 있습니까?
import { createReadStream } from 'fs'
import { createInterface } from 'readline'
import { getCompanyName } from './cardType'
import cardValidator from './cardValidator'
import * as fs from 'fs'
const lineReader = createInterface({
input: createReadStream('data/input.txt')
})
const output: string[] = []
lineReader.on('line', (creditCard: string) => {
var company = `${getCompanyName(creditCard)}: ${creditCard} (${
cardValidator(creditCard) ? 'valid' : 'invalid'
})`
//make company output an array called results then use results to
//wright lines to the output file
fs.writeFile('./data/output.txt', results[0, 1, 2, 3, etc], err => {
if (err) throw err && console.log('it broke as heck')
console.log('The file has been saved!')
})
})
어떻게하면됩니까?
완료 이벤트가 무슨 뜻인지 이해할 수 없기 때문에이 기능이 작동하지 않습니다. 검색 한 결과 아무것도 찾을 수 없습니다. –