Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('JSON and CSV files are written and match with input data', (t) => {
writeFile(notesStub, true, 'bar');
const jsonFileContent = fs.readFileSync('bar.json', 'utf-8');
t.deepEqual(JSON.parse(jsonFileContent), notesStub);
t.notThrows(() => {
fs.lstatSync('bar.csv');
});
const csvFileContent = fs.readFileSync('bar.csv', 'utf-8');
t.is(csvFileContent, json2csv({ data: notesStub }));
});
const fields = ["firstName", "lastName", "cell", "companyName", "city", "zip"];
const numContacts = 10000;
const data = [];
for (let index = 0; index < numContacts; index++) {
data.push({
firstName: faker.name.firstName(),
lastName: faker.name.lastName(),
cell: `1-${faker.phone.phoneNumberFormat()}`,
companyName: faker.company.companyName(),
city: faker.address.city(),
zip: faker.address.zipCode()
});
}
const csvFile = json2csv({ data, fields });
console.log(csvFile);
export() {
const data = json2csv({ data: this.state.rows, fields: ['timestamp', 'message'] });
saveAs({ data, filename: 'logs.csv', type: 'text/csv;charset=utf-8' });
}
render() {
externalId: prop.externalId,
component: prop.component,
metaType: prop.metaType,
filelink: prop.filelink,
filename: prop.filename,
link: prop.link
}
})
res.header('Content-Type','application/json')
res.send(JSON.stringify(exportedProps, null, 2))
break
case 'csv':
const csv = json2csv({
fields: [
'externalId',
'component',
'displayCategory',
'displayName',
'displayValue',
'metaType',
'filelink',
'filename',
'link'
],
data: properties
})
res.header('Content-Type','application/text')
res.send(csv)
break
return async function (hook) {
if (hook.type !== 'after') {
throw new Error('The \'writeCSV\' hook should only be used as a \'after\' hook.')
}
const store = await getStoreFromHook(hook, 'writeCSV', options)
debug('Creating CSV for ' + hook.data.id)
const data = _.get(hook, options.dataPath || 'result')
const csv = json2csv({ data, fields: options.fields })
const csvName = template(hook.data, options.key || (hook.data.id + '.csv'))
await writeBufferToStore(
Buffer.from(csv, 'utf8'),
store, {
key: csvName,
params: options.storageOptions
}
)
addOutput(hook.result, csvName, options.outputType)
return hook
}
}
export() {
const { accountID } = this.props;
const data = json2csv({
data : this.state[accountID].rows,
fields: [
'id',
'timestamp',
'reference',
'contract_type',
'entry_tick',
'exit_tick',
'buy_price',
'sell_price',
'profit',
],
});
saveAs({ data, filename: 'logs.csv', type: 'text/csv;charset=utf-8' });
}
getAccountStat(accountID) {
export() {
const data = json2csv({ data: this.state.rows, fields: ['timestamp', 'message'] });
saveAs({ data, filename: 'logs.csv', type: 'text/csv;charset=utf-8' });
}
render() {
secondary
target="_blank"
style={{ margin: '5px' }}
label={strings.explorer_schema}
href="https://github.com/odota/core/blob/master/sql/create_tables.sql"
/>
<span style="{{">
{/*
*/}
field.name),
}))}`}
download="data.csv"
context={explorer}
/>
window.open(`${process.env.REACT_APP_API_HOST}/api/explorer?sql=${encodeURIComponent(getSqlString())}`, '_blank')}
context={explorer}</span>