{"_id":"@afzalimdad9/comma-separated-values","_rev":"1-b8044876de72e1ca07184d2afacd6648","name":"@afzalimdad9/comma-separated-values","dist-tags":{"latest":"4.0.1"},"versions":{"4.0.0":{"name":"@afzalimdad9/comma-separated-values","version":"4.0.0","keywords":["csv","csv parse","csv encode","csv rfc","tsv","tsv parse","tsv encode","tsv rfc"],"author":{"url":"http://afzalimdad9.vercel.app/","name":"Afzal Imdad","email":"afzalimdad9@gmail.com"},"license":"MIT","_id":"@afzalimdad9/comma-separated-values@4.0.0","maintainers":[{"name":"afzalimdad9","email":"afzalimdad9@gmail.com"}],"homepage":"https://github.com/afzalimdad9/CSV.js","bugs":{"url":"https://github.com/afzalimdad9/CSV.js/issues"},"dist":{"shasum":"fae3d6d5e7a958ce5189457f717ea193f5b199ea","tarball":"https://registry.npmjs.org/@afzalimdad9/comma-separated-values/-/comma-separated-values-4.0.0.tgz","fileCount":16,"integrity":"sha512-JqA1H3rFvCTE/OWyJWLa6qfxwxAXu7teLemRAJiWN0WN4PbkSCegK7A9HGXp15+G5SddPT00iKYqSao9NlDjTQ==","signatures":[{"sig":"MEQCIHlxJJQhjRRMbLWadFjfGphM3Os3XT6BIA0SsMnZbSv+AiAz7TVHsVfGpFEMdu1W7n3BLHUeTSebcqqVN356E0ItJw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":70762},"main":"dist/csv.js","types":"csv.d.ts","source":"csv.ts","gitHead":"9bb43fbc8053152024788f959f4f1b51ed2ea7cc","scripts":{"repl":"node -e \"let {CSV,data,reload} = require('./repl')\" -i","test":"mocha test.js","bench":"node benchmark.js","build":"buble csv.src.js > csv.js"},"_npmUser":{"name":"afzalimdad9","email":"afzalimdad9@gmail.com"},"repository":{"url":"git+https://github.com/afzalimdad9/CSV.js.git","type":"git"},"_npmVersion":"10.8.2","description":"Simple, blazing-fast CSV parsing/encoding in JavaScript. Full RFC 4180 compliance.","directories":{},"_nodeVersion":"18.20.5","_hasShrinkwrap":false,"devDependencies":{"buble":"^0.8.4","mocha":"~2.4.5","d3-dsv":"^0.3.2","babyparse":"^0.4.6","benchmark":"~2.1.0","deep-equal":"~1.0.1","typescript":"^5.7.3","@types/jest":"^29.5.14","@types/node":"^22.10.6","@types/mocha":"^10.0.10","require-reload":"^0.2.2"},"_npmOperationalInternal":{"tmp":"tmp/comma-separated-values_4.0.0_1736969500757_0.9994311335211004","host":"s3://npm-registry-packages-npm-production"}},"4.0.1":{"name":"@afzalimdad9/comma-separated-values","version":"4.0.1","description":"Simple, blazing-fast CSV parsing/encoding in JavaScript. Full RFC 4180 compliance.","main":"csv.js","scripts":{"repl":"node -e \"let {CSV,data,reload} = require('./repl')\" -i","build":"buble csv.src.js > csv.js","test":"mocha test.js","bench":"node benchmark.js"},"repository":{"type":"git","url":"git+https://github.com/afzalimdad9/CSV.js.git"},"keywords":["csv","csv parse","csv encode","csv rfc","tsv","tsv parse","tsv encode","tsv rfc"],"author":{"name":"Afzal Imdad","email":"afzalimdad9@gmail.com","url":"http://afzalimdad9.vercel.app/"},"license":"MIT","bugs":{"url":"https://github.com/afzalimdad9/CSV.js/issues"},"homepage":"https://github.com/afzalimdad9/CSV.js","devDependencies":{"babyparse":"^0.4.6","benchmark":"~2.1.0","buble":"^0.8.4","d3-dsv":"^0.3.2","deep-equal":"~1.0.1","mocha":"~2.4.5","require-reload":"^0.2.2"},"_id":"@afzalimdad9/comma-separated-values@4.0.1","gitHead":"757bbcf815206e3f537500895d005991336c32c4","_nodeVersion":"18.20.5","_npmVersion":"10.8.2","dist":{"integrity":"sha512-RFrkHf30M05emjT/LwtgT3PhnaH2ekitmP7loy24uXIysCb19bj8MYREEJ5WhV5pcYL+ppzqR8sECgjEShj3sQ==","shasum":"0b17b03bad5cd149a2e23d1d0aba59c4d933feaa","tarball":"https://registry.npmjs.org/@afzalimdad9/comma-separated-values/-/comma-separated-values-4.0.1.tgz","fileCount":9,"unpackedSize":34848,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDH+szAcTPcOunwSqXL2dt6JP7/V7gJdvKyM0G2edPzSAiEA/YGUadCGdIjvM04uXv9lQD3F0xmpKR52kojjMIrQWp4="}]},"_npmUser":{"name":"afzalimdad9","email":"afzalimdad9@gmail.com"},"directories":{},"maintainers":[{"name":"afzalimdad9","email":"afzalimdad9@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/comma-separated-values_4.0.1_1736969629094_0.465272218268723"},"_hasShrinkwrap":false}},"time":{"created":"2025-01-15T19:31:40.611Z","modified":"2025-01-15T19:33:49.481Z","4.0.0":"2025-01-15T19:31:41.081Z","4.0.1":"2025-01-15T19:33:49.309Z"},"bugs":{"url":"https://github.com/afzalimdad9/CSV.js/issues"},"author":{"name":"Afzal Imdad","email":"afzalimdad9@gmail.com","url":"http://afzalimdad9.vercel.app/"},"license":"MIT","homepage":"https://github.com/afzalimdad9/CSV.js","keywords":["csv","csv parse","csv encode","csv rfc","tsv","tsv parse","tsv encode","tsv rfc"],"repository":{"type":"git","url":"git+https://github.com/afzalimdad9/CSV.js.git"},"description":"Simple, blazing-fast CSV parsing/encoding in JavaScript. Full RFC 4180 compliance.","maintainers":[{"name":"afzalimdad9","email":"afzalimdad9@gmail.com"}],"readme":"CSV.js\r\n======\r\n\r\nSimple, blazing-fast CSV parsing/encoding in JavaScript. Full [RFC 4180](http://tools.ietf.org/html/rfc4180) compliance.\r\n\r\nCompatible with browsers (>IE8), AMD, and NodeJS.\r\n\r\n\r\nInstallation\r\n------------\r\n\r\n**MASTER is currently under development. As such, `csv.src.js` and `csv.js` are both unusable. Make sure you download `csv.min.js`.**\r\n\r\nDownload `csv.min.js` and reference to it using your preferred method.\r\n\r\nIf you use **Bower**, or **npm**, install the `@afzalimdad9/comma-separated-values` package.\r\n\r\n\r\nInstantiation\r\n-------------\r\n\r\nCreate a CSV instance with `var csv = new CSV(data);`, where `data` is a plain-text CSV string. You can supply options with the format `var csv = new CSV(data, { option: value });`.\r\n\r\n\r\nOptions\r\n-------\r\n\r\n- **`cast`**: `true` to automatically cast numbers and booleans to their JavaScript equivalents. `false` otherwise. Supply your own `array` to override autocasting. Defaults to `true`.\r\n- **`lineDelimiter`**: The `string` that separates lines from one another. If parsing, defaults to autodetection. If encoding, defaults to `'\\r\\n'`.\r\n- **`cellDelimiter`**: A 1-character-long `string` that separates values from one another. If parsing, defaults to autodetection. If encoding, defaults to `','`.\r\n- **`header`**: `true` if the first row of the CSV contains header values, or supply your own `array`. Defaults to `false`.\r\n\r\nYou can update an option's value any time after instantiation with `csv.set(option, value)`.\r\n\r\n\r\nQuickstart\r\n----------\r\n\r\nFor those accustomed to JavaScript, the CSV.js API:\r\n\r\n```javascript\r\n// The instance will set itself up for parsing or encoding on instantiation,\r\n// which means that each instance can only either parse or encode.\r\n// The `options` object is optional\r\nvar csv = new CSV(data, [options]);\r\n\r\n// If the data you've supplied is an array,\r\n// CSV#encode will return the encoded CSV.\r\n// It will otherwise fail silently.\r\nvar encoded = csv.encode();\r\n\r\n// If the data you've supplied is a string,\r\n// CSV#parse will return the parsed CSV.\r\n// It will otherwise fail silently.\r\nvar parsed = csv.parse();\r\n\r\n// The CSV instance can return the record immediately after\r\n// it's been encoded or parsed to prevent storing the results\r\n// in a large array by calling CSV#forEach and passing in a function.\r\ncsv.forEach(function(record) {\r\n  // do something with the record\r\n});\r\n\r\n// CSV includes some convenience class methods:\r\nCSV.parse(data, options); // identical to `new CSV(data, options).parse()`\r\nCSV.encode(data, options); // identical to `new CSV(data, options).encode()`\r\nCSV.forEach(data, options, callback); // identical to `new CSV(data, options).forEach(callback)`\r\n\r\n// For overriding automatic casting, set `options.cast` to an array.\r\n// For `parsing`, valid array values are: 'Number', 'Boolean', and 'String'.\r\nCSV.parse(data, { cast: ['String', 'Number', 'Number', 'Boolean'] });\r\n// For `encoding`, valid array values are 'Array', 'Object', 'String', 'Null', and 'Primitive'.\r\nCSV.encode(data, { cast: ['Primitive', 'Primitive', 'String'] });\r\n```\r\n\r\n\r\nParsing\r\n-------\r\n\r\nBy default CSV.js will return an `array of arrays`.\r\n\r\n```javascript\r\nvar data = '\\\r\n1850,20,0,1,1017281\\r\\n\\\r\n1850,20,0,2,1003841\\r\\n\\\r\n...\r\n';\r\nnew CSV(data).parse()\r\n/*\r\nReturns:\r\n[\r\n  [1850, 20, 0, 1, 1017281],\r\n  [1850, 20, 0, 2, 1003841]\r\n  ...\r\n]\r\n*/\r\n```\r\n\r\n\r\nIf the CSV's first row is a header, set `header` to `true`, and CSV.js will return an `array of objects`.\r\n\r\n```javascript\r\nvar data = '\\\r\nyear,age,status,sex,population\\r\\n\\\r\n1850,20,0,1,1017281\\r\\n\\\r\n1850,20,0,2,1003841\\r\\n\\\r\n...\r\n';\r\nnew CSV(data, { header: true }).parse();\r\n/*\r\nReturns:\r\n[\r\n  { year: 1850, age: 20, status: 0, sex: 1, population: 1017281 },\r\n  { year: 1850, age: 20, status: 0, sex: 2, population: 1003841 }\r\n  ...\r\n]\r\n*/\r\n```\r\n\r\n\r\nYou may also supply your own header values, if the text does not contain them, by setting `header` to an `array` of field values.\r\n\r\n```javascript\r\nvar data = '\\\r\n1850,20,0,1,1017281\\r\\n\\\r\n1850,20,0,2,1003841\\r\\n\\\r\n...\r\n';\r\nnew CSV(data, {\r\n  header: ['year', 'age', 'status', 'sex', 'population']\r\n}).parse();\r\n/*\r\nReturns:\r\n[\r\n  { year: 1850, age: 20, status: 0, sex: 1, population: 1017281 },\r\n  { year: 1850, age: 20, status: 0, sex: 2, population: 1003841 }\r\n  ...\r\n]\r\n*/\r\n```\r\n\r\n\r\nEncoding\r\n--------\r\n\r\nCSV.js accepts an `array of arrays` or an `array of objects`.\r\n\r\n```javascript\r\nvar data = [[1850, 20, 0, 1, 1017281], [1850, 20, 0, 2, 1003841]...];\r\nnew CSV(data).encode();\r\n/*\r\nReturns:\r\n1850,20,0,1,1017281\\r\\n\\\r\n1850,20,0,2,1003841\\r\\n\\\r\n...\r\n*/\r\n```\r\n\r\n\r\nTo add headers to an `array of arrays`, set `header` to an `array` of header field values.\r\n\r\n```javascript\r\nvar data = [[1850, 20, 0, 1, 1017281], [1850, 20, 0, 2, 1003841]];\r\nnew CSV(data, { header: [\"year\", \"age\", \"status\", \"sex\", \"population\"] }).encode();\r\n/*\r\nReturns:\r\n\"year\",\"age\",\"status\",\"sex\",\"population\"\\r\\n\\\r\n1850,20,0,1,1017281\\r\\n\\\r\n1850,20,0,2,1003841\\r\\n\\\r\n*/\r\n```\r\n\r\n\r\nTo add headers to an `array of objects`, just set `header` to `true`.\r\n\r\n```javascript\r\nvar data = [\r\n  { year: 1850, age: 20, status: 0, sex: 1, population: 1017281 },\r\n  { year: 1850, age: 20, status: 0, sex: 2, population: 1003841 }\r\n];\r\nnew CSV(data, { header: true }).encode();\r\n/*\r\nReturns:\r\n\"year\",\"age\",\"status\",\"sex\",\"population\"\\r\\n\\\r\n1850,20,0,1,1017281\\r\\n\\\r\n1850,20,0,2,1003841\\r\\n\\\r\n*/\r\n```\r\n\r\n\r\nStreaming\r\n---------\r\n\r\nIf the dataset that you've provided is to be parsed, calling `CSV.prototype.forEach` and supplying a function will call your function and supply it with the parsed record immediately after it's been parsed.\r\n\r\n```javascript\r\nvar data = '\\\r\n1850,20,0,1,1017281\\r\\n\\\r\n1850,20,0,2,1003841\\r\\n\\\r\n...\r\n';\r\nnew CSV(data).forEach(function(array) {\r\n  /*\r\n   * do something with the incoming array\r\n   * array example:\r\n   *   [1850, 20, 0, 1, 1017281]\r\n   */\r\n});\r\n```\r\n\r\nLikewise, if you've requested an `array of objects`, you can still call `CSV.prototype.forEach`:\r\n\r\n```javascript\r\nvar data = '\\\r\nyear,age,status,sex,population\\r\\n\\\r\n1850,20,0,1,1017281\\r\\n\\\r\n1850,20,0,2,1003841\\r\\n\\\r\n...\r\n';\r\nnew CSV(data, { header: true }).forEach(function(object) {\r\n  /*\r\n   * do something with the incoming object\r\n   * object example:\r\n   *   { year: 1850, age: 20, status: 0, sex: 1, population: 1017281 }\r\n   */\r\n});\r\n```\r\n\r\n\r\nIf you're dataset is to be encoded, `CSV.prototype.forEach` will call your function and supply the CSV-encoded line immediately after the line has been encoded:\r\n\r\n```javascript\r\nvar data = [[1850, 20, 0, 1, 1017281], [1850, 20, 0, 2, 1003841]];\r\nnew CSV(data).forEach(function(line) {\r\n  /*\r\n   * do something with the incoming line\r\n   * line example:\r\n   *   \"1850,20,0,1,1017281\\r\\n\\\"\"\r\n   */\r\n});\r\n```\r\n\r\nCasting\r\n-------\r\n\r\n```javascript\r\n// For overriding automatic casting, set `options.cast` to an array.\r\n// For `parsing`, valid array values are: 'Number', 'Boolean', and 'String'.\r\nCSV.parse(data, { cast: ['String', 'Number', 'Number', 'Boolean'] });\r\n// For `encoding`, valid array values are 'Array', 'Object', 'String', 'Null', and 'Primitive'.\r\nCSV.encode(data, { cast: ['Primitive', 'Primitive', 'String'] });\r\n```\r\n\r\n\r\nConvenience Methods\r\n-------------------\r\n\r\n```javascript\r\nCSV.parse(data, options) // identical to `new CSV(data, options).parse()`\r\nCSV.encode(data, options) // identical to `new CSV(data, options).encode()`\r\nCSV.forEach(data, options, callback) // identical to `new CSV(data, options).forEach(callback)`\r\n```\r\n","readmeFilename":"README.md"}