_EtagSupport__etag
ts82088872.62
__name__
README.md
content_type
text/x-markdown
data
# csv.js\n \n A simple CSV parser in JavaScript for the browser (and nodejs)\n \n ## Features\n \n * Parse CSV to 2-dimension String array\n * Specify column names or use the first row as column names\n * Custom delimeter, quote character and row delimeter\n \n ## Example\n \n See [test.js](https://github.com/henix/csv.js/blob/master/test.js)\n \n ## Low-level API\n \n ### CSV.CSVParser(String str, Object options)\n \n Construct a CSVParser. A CSVParser hold some parser states.\n \n `options` is an object that can have 3 properties: \'delim\', \'quote\', \'rowdelim\'\n \n Example:\n \n ```js\n var parser = new CSV.CSVParser(\'a\\tb\\tc\', {delim:\'\\t\',quote:\'"\',rowdelim:\'\\r\\n\'});\n while (parser.hasNext()) {\n \tvar row = parser.nextRow();\n \t// do something with row\n }\n ```\n \n Every time you call `nextRow`, the parser will parse next portion of input. This allows you parse only front part of a string with the remainder untouched. You can stop anywhere.\n \n ### boolean CSVParser.hasNext()\n \n ### String[] CSVParser.nextRow()\n \n ## High-level API\n \n All high-level APIs are implemented by the low-level API in a few lines. See bottom part of [csv.js](https://github.com/henix/csv.js/blob/master/csv.js)\n \n ### String[][] CSV.parse(String str, Object options)\n \n ### String[] CSV.parseOne(String str, Object options)\n \n ### Object[] CSV.bindColumns(String[][] rows, String[] columns)\n \n If specified, use `columns` as column names. Otherwise use the first row.\n \n ## Dependency\n \n * runtime: no\n * test: nodejs\n \n ## Run test\n \n \tnode test.js\n \tfirefox test.htm\n \n ## Performance Benchmark\n \n [CSV.js vs jquery-csv](http://jsperf.com/csv-parsing-jquery-csv-and-csv-js/2)\n \n ## Compatibility\n \n csv.js can be used with:\n \n * browser\n * nodejs\n * AMD / CMD / require.js\n \n ## Standard compliance\n \n This implementation is compliant to [RFC4180](http://tools.ietf.org/html/rfc4180), except for the default line delimeter: this implementation use `\\n`, but RFC4180 states it should be `\\r\\n`.\n \n Use the following code if you want strict RFC4180 behavior:\n \n \tCSV.DefaultOptions.rowdelim = \'\\r\\n\';\n \n ## Under the hood\n \n This is a PEG (Parsing Expression Grammar) parser, written in recursive descent style.\n \n The PEG I use is taken from [lpeg\'s homepage](http://www.inf.puc-rio.br/~roberto/lpeg/) (in Lua):\n \n ```lua\n field = \'"\' * ((lpeg.P(1) - \'"\') + lpeg.P\'""\')^0 * \'"\' +\n \t\t(1 - lpeg.S\',\\n"\')^0\n record = field * (\',\' * field)^0 * (lpeg.P\'\\n\' + -1)\n ```\n \n ## Links\n \n * [写了个简单的 javascript CSV parser](http://www.douban.com/note/255897820/)\n
precondition
size
2434
title