@jsforce/jsforce-node
Version:
Salesforce API Library for JavaScript
41 lines (40 loc) • 1.3 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.serializeCSVStream = exports.parseCSVStream = exports.toCSV = exports.parseCSV = void 0;
const csv_parse_1 = require("csv-parse");
const sync_1 = require("csv-parse/sync");
const csv_stringify_1 = require("csv-stringify");
const sync_2 = require("csv-stringify/sync");
// The following column delimiters are supported by the Bulk V2 API:
// https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/create_job.htm
//
// BACKQUOTE, CARET, COMMA, PIPE, SEMICOLON, TAB
const csvDelimiters = ['`', '^', ',', '|', ';', ' '];
/**
* @private
*/
function parseCSV(str, options) {
return (0, sync_1.parse)(str, { ...options, columns: true, delimiter: csvDelimiters });
}
exports.parseCSV = parseCSV;
/**
* @private
*/
function toCSV(records, options) {
return (0, sync_2.stringify)(records, { ...options, header: true });
}
exports.toCSV = toCSV;
/**
* @private
*/
function parseCSVStream(options) {
return new csv_parse_1.Parser({ ...options, columns: true });
}
exports.parseCSVStream = parseCSVStream;
/**
* @private
*/
function serializeCSVStream(options) {
return (0, csv_stringify_1.stringify)({ ...options, header: true });
}
exports.serializeCSVStream = serializeCSVStream;
;