Update csv.js

This commit is contained in:
Aleksandr Statciuk 2022-02-17 17:33:24 +03:00
parent a109031125
commit af21b368bd

View file

@ -1,4 +1,6 @@
const csv2json = require('csvtojson') const csv2json = require('csvtojson')
const chalk = require('chalk')
const logger = require('./logger')
const fs = require('mz/fs') const fs = require('mz/fs')
const { const {
Parser, Parser,
@ -10,6 +12,7 @@ const csv2jsonOptions = {
checkColumn: true, checkColumn: true,
trim: true, trim: true,
delimiter: ',', delimiter: ',',
eol: '\r\n',
colParser: { colParser: {
countries: listParser, countries: listParser,
languages: listParser, languages: listParser,
@ -32,10 +35,14 @@ const json2csv = new Parser({
const csv = {} const csv = {}
csv.load = async function (filepath) { csv.fromFile = async function (filepath) {
return csv2json(csv2jsonOptions).fromFile(filepath) return csv2json(csv2jsonOptions).fromFile(filepath)
} }
csv.fromString = async function (filepath) {
return csv2json(csv2jsonOptions).fromString(filepath)
}
csv.save = async function (filepath, data) { csv.save = async function (filepath, data) {
const string = json2csv.parse(data) const string = json2csv.parse(data)