Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// check if there is any error
let isError = false;
data.forEach((module) => {
if (module.isError) {
isError = true;
console.error(`module: '${module.name}@${module.version}'. ${module.errorMessage}`, module);
}
});
if (isError) {
process.exit(-1);
}
csv.stringify(data, {
header: true,
columns: {
'_': '', // placeholder
name: 'name',
groupId: 'groupId', // not a field we have
artifactId: 'artifactId', // not a field we have
version: 'version',
repository: 'url',
licenses: 'license',
'in distribution': 'in distribution', // not a field we have
checked: 'checked', // not a field we have
text: 'text', // not a field we have
copyright: 'notice',
comment: 'comment' // placeholder
}
}, (error, cvsText) => {
function arrayToCsv(csvArray)
{
csv.stringify(csvArray, (err, output) =>
{
writeFile(outputFileName, output, "utf8").then(() =>
{
// eslint-disable-next-line no-console
console.log(`${outputFileName} is created`);
}).catch((error) =>
{
console.error(error);
});
});
}
const tsvFile = fs.createWriteStream(tsvPath)
const columns = [
'Label',
'Name',
'Network',
'Program',
'Air Date',
'Air Time',
'Duration',
'Archive ID',
'URL',
'Model ID',
]
// Set up the CSV Pipeline
const csvStringifier = csv.stringify({
header: true,
columns,
})
csvStringifier.on('readable', () => {
let data = null
// eslint-disable-next-line no-cond-assign
while (data = csvStringifier.read()) {
csvFile.write(data)
}
})
// Set up the TSV Pipeline
const tsvStringifier = csv.stringify({
header: true,
columns,
delimiter: '\t',
stringify: function(options, callback) {
console.log(clc.yellowBright('\n tasks.helpers.csv.stringify'));
if(!options.filepath) {
return callback(' Please specify the output csv file path with --filepath=path/to/source.tsv');
}
csv.stringify(options.records, {
delimiter: options.delimiter || '\t',
columns: options.fields,
header: true
}, function (err, data) {
fs.writeFile(options.filepath,
data, function (err) {
if(err) {
callback(err);
return
}
console.log(clc.blackBright(' file created successfully:', clc.cyanBright(options.filepath), 'containing', clc.magentaBright(options.records.length),'records'));
callback(null, options);
})
});
},
//const formatted = '/home/silei/Workspace/mturk/acl18/batch_3/paraphrase_out_formatted.csv'
//const cleaned = '/home/silei/Workspace/mturk/acl18/batch_3/paraphrase_out_cleaned.tsv'
const task = process.argv[2];
const parser = csv.parse();
if (task === 'clean') {
const formatted = process.argv[3];
const cleaned = process.argv[4]
const input = fs.createReadStream(formatted).pipe(parser);
const output = csv.stringify({ header: true, delimiter: '\t' });
output.pipe(fs.createWriteStream(cleaned));
clean_paraphrase(input, output);
} else if (task === 'mark') {
const raw = process.argv[3];
const marked = process.argv[4];
const input = fs.createReadStream(raw).pipe(parser);
const output = csv.stringify({ header: true, delimiter: ','});
output.pipe(fs.createWriteStream(marked));
mark_paraphrase(input, output);
}
}
var outputItemsAsCsv = function(response, items, mapper, columns) {
var options = {
delimiter: ',',
quote: '"',
quoted: true,
rowDelimiter: 'unix'
};
if (_.isArray(columns)) {
options.header = true;
options.columns = columns;
}
if (_.isFunction(mapper)) {
items = _.map(items, mapper);
}
var stringify = csv.stringify(items, options);
response.header('Content-Type', 'text/csv');
stringify.pipe(response);
};
let outputItemsAsCsv = function(response, items, mapper, columns) {
let options = {
delimiter: ',',
quote: '"',
quoted: true,
rowDelimiter: 'unix'
};
if (_.isArray(columns)) {
options.header = true;
options.columns = columns;
}
if (_.isFunction(mapper)) {
items = _.map(items, mapper);
}
let stringify = csv.stringify(items, options);
response.header('Content-Type', 'text/csv');
stringify.pipe(response);
};
function main() {
const input = byline(process.stdin);
input.setEncoding('utf8');
const output = csv.stringify({ header: true, delimiter: '\t' });
const file = fs.createWriteStream(process.argv[2]);
output.pipe(file);
const by_signature = false;
const compound_only = false;
if (by_signature)
prepare_sample_by_sig(input, output);
else
prepare_sample_by_code(input, output, compound_only);
}
main();
function processResponse (res, input) {
var headers = {
uid: 'uid',
type: 'type',
priority: 'priority',
status: 'status',
created: 'created',
subject: 'subject',
requester: 'requester',
group: 'group',
assignee: 'assignee',
tags: 'tags'
}
csv.stringify(input, { header: true, columns: headers }, function (err, output) {
if (err) return res.status(400).json({ success: false, error: err })
res.setHeader('Content-disposition', 'attachment; filename=report_output.csv')
res.set('Content-Type', 'text/csv')
res.send(output)
})
}