CSVJS Allows CSV, Comma-Separated values, in JS.
Use this script to get the script
<script src="https://cdn.jsdelivr.net/gh/XHiddenProjects/[email protected]/csv.min.js"></script>
To start the object use the csvJS()
using a custom splicer and EOF(End of Line)
/**
* Creates a CSV object to configure
* @param {String} splice [Optional] - Character to splice in row
* @param {String} EOF [Optional] - Character to split each column
*/
const csv = new csvJS(splice=',', EOF='\n')
To import CSV, use the fromFile method
/**
* Converts CSV file to an Object
* @param {String} file CSV File path to return as
* @param {Number|Number[]} [ignoreLines=0] Ignore lines. Use 0 to use no-ignore lines
* @returns {Object[]} CSV Object
*/
const myCSV = csv.fromFile({file_path},ignoreLines=0);
To use a string version of CSV to create an object us the fromString method
/**
* Converts CSV from string to object
* @param {String} str CSV string
* @param {Number|Number[]} ignoreLines Lines to ignore
* @returns {Object[]} CSV object
*/
const myCSV = csv.fromString(str, ignoreLines=0);
Use the ignoreLines parameter of either a Number | Number[]. Numbers must be start from 1..., 0 means no-ignore or skip
To load up the table from an object, use the toTable method
/**
* Creates a table off the object
* @param {Element} elem Element to target the CSV
*/
csv.toTable({element});
To convert objects to SQL insert CMD line:
/**
* Converts CSV Object to SQL
* @returns {String} SQL String
*/
csv.toSQL();
To convert objects to CSV, use the toCSV() method
/**
* Converts Object to CSV
* @returns {String} CSV String
*/
csv.toCSV();
To convert objects to JSON format, use toJSON() method
/**
* Converts CSV Object to JSON
* @param {Number} opt Options. JSON_OPTION_REGULAR | JSON_OPTION_TRANSPOSE
* @returns {String} JSON object
*/
csv.toJSON(opt)