xxxxxxxxxx
const { csv2json } = require('json-2-csv')
const fs = require('fs')
const { parse } = require('csv-parse')
function reformatString(str) {
const obj = {}
const pemindahanRegex = /PEMINDAHAN KE\s+(\d+)\s+(.+?)\s*\|/
const pemindahanMatch = str.match(pemindahanRegex)
if (pemindahanMatch) {
obj.address = pemindahanMatch[1].trim()
obj.addressName = pemindahanMatch[2].trim()
}
const notesRegex = /([a-zA-Z0-9]+)$/
const notesMatch = str.match(notesRegex)
if (notesMatch) {
obj.notes = notesMatch[0].trim()
}
return obj
}
let data = new Promise((resolve, reject) => {
const readFile = fs.readFileSync('./bni2.csv')
let pr = parse(readFile, { delimiter: ';' })
let csvString = ''
pr.on('data', (chunk) => {
csvString += '\n' + chunk.toString()
})
pr.on('end', () => {
resolve(csvString.trim())
})
})
data.then((data) => {
data = data.replace(/(\b\d{1,3}(,\d{3})*\.\d{2}\b)/g, function (match) {
return match.replace(/,/g, '.')
})
const reformatCsvData = csv2json(data).map((v) => {
let reformat = reformatString(v.Description)
return {
addressName: reformat.addressName,
address: reformat.address,
journalNo: v['Journal No.'],
amount: v.Debit,
notes: reformat.notes,
date: v['Post Date']
}
})
console.log(reformatCsvData)
})
xxxxxxxxxx
const { csv2json } = require('json-2-csv')
const fs = require('fs')
const { parse } = require('csv-parse')
function reformatString(str) {
const obj = {}
const pemindahanRegex = /PEMINDAHAN KE\s+(\d+)\s+(.+?)\s*\|/
const pemindahanMatch = str.match(pemindahanRegex)
if (pemindahanMatch) {
obj.address = pemindahanMatch[1].trim()
obj.addressName = pemindahanMatch[2].trim()
}
const notesRegex = /([a-zA-Z0-9]+)$/
const notesMatch = str.match(notesRegex)
if (notesMatch) {
obj.notes = notesMatch[0].trim()
}
return obj
}
let data = new Promise((resolve, reject) => {
const readFile = fs.readFileSync('./bni2.csv')
let pr = parse(readFile, { delimiter: ';' })
let csvString = ''
pr.on('data', (chunk) => {
csvString += '\n' + chunk.toString()
})
pr.on('end', () => {
resolve(csvString.trim())
})
})
data.then((data) => {
data = data.replace(/(\d+),(\d+)\.(\d+)/g, '$1.$2.$3')
const reformatCsvData = csv2json(data).map((v) => {
let reformat = reformatString(v.Description)
return {
addressName: reformat.addressName,
address: reformat.address,
journalNo: v['Journal No.'],
amount: v.Debit,
notes: reformat.notes,
date: v['Post Date']
}
})
console.log(reformatCsvData)
})
xxxxxxxxxx
const { csv2json } = require('json-2-csv')
const fs = require('fs')
const { parse } = require('csv-parse')
function reformatString(str) {
const obj = {}
const pemindahanRegex = /PEMINDAHAN KE\s+(\d+)\s+(.+?)\s*\|/
const pemindahanMatch = str.match(pemindahanRegex)
if (pemindahanMatch) {
obj.address = pemindahanMatch[1].trim()
obj.addressName = pemindahanMatch[2].trim()
}
const notesRegex = /([a-zA-Z0-9]+)$/
const notesMatch = str.match(notesRegex)
if (notesMatch) {
obj.notes = notesMatch[0].trim()
}
return obj
}
let data = new Promise((resolve, reject) => {
let csvString = ''
fs.createReadStream('./bni2.csv')
.pipe(parse({ delimiter: ';' }))
.on('data', (chunk) => {
csvString += '\n' + chunk.toString()
})
.on('end', () => {
resolve(csvString.trim())
})
})
data.then((data) => {
data = data.replace(/(\d+),(\d+)\.(\d+)/g, '$1.$2.$3')
const reformatCsvData = csv2json(data).map((v) => {
let reformat = reformatString(v.Description)
return {
addressName: reformat.addressName,
address: reformat.address,
journalNo: v['Journal No.'],
amount: v.Debit,
notes: reformat.notes,
date: v['Post Date']
}
})
console.log(reformatCsvData)
})
xxxxxxxxxx
const csv = require('csvtojson')
const fs = require('fs')
const Papa = require('papaparse')
function reformatString(str) {
const obj = {}
const pemindahanRegex = /PEMINDAHAN KE\s+(\d+)\s+(.+?)\s*\|/
const pemindahanMatch = str.match(pemindahanRegex)
if (pemindahanMatch) {
obj.address = pemindahanMatch[1].trim()
obj.addressName = pemindahanMatch[2].trim()
}
const notesRegex = /([a-zA-Z0-9]+)$/
const notesMatch = str.match(notesRegex)
if (notesMatch) {
obj.notes = notesMatch[0].trim()
}
return obj
}
const readFile = fs.readFileSync('./bni3.csv')
let pr = Papa.parse(readFile.toString(), { delimiter: ';' })
let csvString = ''
csvString += pr.data[0].toString() + '\n' + pr.data.slice(1, pr.data.length).join('\n')
data = csvString.replace(/(\b\d{1,3}(,\d{3})*\.\d{2}\b)/g, function (match) {
return match.replace(/,/g, '.')
})
// reformat
;(async () => {
const csvData = await csv().fromString(data)
let reformatCsvData = csvData.map((v) => {
let reformat = reformatString(v.Description)
return {
addressName: reformat.addressName,
address: reformat.address,
journalNo: v['Journal No.'],
amount: v.Debit,
notes: reformat.notes,
date: v['Post Date']
}
})
console.log(reformatCsvData)
})()
xxxxxxxxxx
function extractionDataFromStringDeposit(str: string): Record<string, any> {
const obj: { address: string; addressName: string } = {
address: '',
addressName: '',
};
let pemindahanRegex = /(\d+)\s+([^|]+)\s*\|/;
if (str.includes('PEMINDAHAN DARI')) {
pemindahanRegex = /PEMINDAHAN DARI\s+(\d+)\s+(.+?)\s*\|/;
}
const pemindahanMatch: RegExpMatchArray | null = str.match(pemindahanRegex);
if (pemindahanMatch) {
obj.address = pemindahanMatch[1].trim();
obj.addressName = pemindahanMatch[2].trim();
} else {
const parts: string[] = str.split('|');
if (parts.length >= 4) {
obj.address = parts[1].trim();
obj.addressName = parts[2].trim();
}
}
const vaNumberRegex = /\s*([^|]+)$/;
const vaNumberMatch = str.match(vaNumberRegex);
if (vaNumberMatch) {
let data = vaNumberMatch[0].replace(/(\d+)\s(.+)/, '$1, $2').split(',');
obj.address = data[0].trim();
obj.addressName = data[1].trim();
}
return obj;
}