godkimchi-read-line
v1.0.3
Published
kimchi style's read line module
Downloads
13
Maintainers
Readme
godkimchi-read-line
kimchi style's read line moudle.
Example
const readline = require('godkimchi-read-line')
readline('your file path', { encoding: 'utf8', type: 'file' }, (err, response) => {
if (err) {
throw err
} else {
const { line, lineCount } = response
consoel.log(`${lineCount} - ${line}`)
return false
}
})
readline(path, [options], callback)
path
stringoptions
object
skipHeader
boolean default falseencoding
string default utf8 check iconv-litetype
string option [file, csv] default filequote
string default empty stringdelimiter
string default ,
callback
function
err
Errorresponse
objectline
stringlineCount
numberfields
array only type iscsv
Handle readline
'finish' event
readline
function is AsyncFunction
. so you can handle readline finish event.
const readline = require('godkimchi-read-line')
readline('your file path', { encoding: 'utf8', type: 'file' }, (err, response) => {
if (err) {
throw err
} else {
...
}
})
.then(response => console.log(response))
.catch(error => console.error(error)
.finally(() => {
process.exit()
})
Continue read line or not
const readline = require('godkimchi-read-line')
readline('your file path', { encoding: 'utf8', type: 'file' }, (err, response) => {
if (err) {
throw err
} else {
...
// return false // stop read line
return true // continue
}
})
Wait until readline
function read whole file
const readline = require('godkimchi-read-line')
async function readWholeFile () {
const { lineCount } = await readline('your file path', { encoding: 'utf8', type: 'file' }, (err, response) => {
if (err) {
throw err
} else {
...
// return false // stop read line
return true // continue
}
})
console.log('@@DONE@@ - file line count is ' + lineCount)
}
Read csv file
const readline = require('godkimchi-read-line')
readline('your file path', { encoding: 'utf8', type: 'csv', quote: '', delimiter: '|' }, (err, response) => {
if (err) {
throw err
} else {
const { line, lineCount, fields } = response
console.log(fields)
return false
}
})
License
MIT