CSV.js
======
Simple, blazing-fast CSV parsing/encoding in JavaScript. Full [RFC 4180](http://tools.ietf.org/html/rfc4180) compliance.
Compatible with browsers, AMD, and NodeJS.
Installation
------------
Download `csv.min.js` and reference to it using your preferred method.
If you use **Bower**, or **npm**, install the `comma-separated-values` package.
Instantiation
-------------
Create a CSV instance with `var csv = new CSV(data);`, where `data` is the plain-text CSV file you want to work with. You can supply options with the format `var csv = new CSV(data, { option: value });`.
Options
-------
- **`cast`**: `true` to automatically cast numbers and booleans to their JavaScript equivalents. `false` otherwise. Defaults to `true`.
- **`line`**: The `string` that separates lines from one another. If parsing, defaults to autodetection. If encoding, defaults to `'\r\n'`.
- **`delimiter`**: A 1-character-long `string` that separates values from one another. If parsing, defaults to autodetection. If encoding, defaults to `','`.
- **`header`**: `true` if the first row of the CSV contains header values, or supply your own `array`. Defaults to `false`.
You can update an option's value any time after instantiation with `csv.set(option, value)`.
Parsing
-------
By default CSV.js will return an `array of arrays`.
```javascript
var data = '\
1850,20,0,1,1017281\r\n\
1850,20,0,2,1003841\r\n\
...
';
new CSV(data).parse();
/*
Returns:
[
[1850, 20, 0, 1, 1017281],
[1850, 20, 0, 2, 1003841]
...
]
*/
```
If the CSV's first row is a header, set `header` to `true`, and CSV.js will return an `array of objects`.
```javascript
var data = '\
year,age,status,sex,population\r\n\
1850,20,0,1,1017281\r\n\
1850,20,0,2,1003841\r\n\
...
';
new CSV(data, { header: true }).parse();
/*
Returns:
[
{ year: 1850, age: 20, status: 0, sex: 1, population: 1017281 },
{ year: 1850, age: 20, status: 0, sex: 2, population: 1003841 }
...
]
*/
```
You may also supply your own header values, if the text does not contain them, by setting `header` to an `array` of field values.
```javascript
var data = '\
1850,20,0,1,1017281\r\n\
1850,20,0,2,1003841\r\n\
...
';
new CSV(data, {
header: ['year', 'age', 'status', 'sex', 'population']
}).parse();
/*
Returns:
[
{ year: 1850, age: 20, status: 0, sex: 1, population: 1017281 },
{ year: 1850, age: 20, status: 0, sex: 2, population: 1003841 }
...
]
*/
```
Encoding
--------
CSV.js accepts an `array of arrays` or an `array of objects`.
```javascript
var data = [[1850, 20, 0, 1, 1017281], [1850, 20, 0, 2, 1003841]...];
new CSV(data).encode();
/*
Returns:
1850,20,0,1,1017281\r\n\
1850,20,0,2,1003841\r\n\
...
*/
```
To add headers to an `array of arrays`, set `header` to an `array` of header field values.
```javascript
var data = [[1850, 20, 0, 1, 1017281], [1850, 20, 0, 2, 1003841]];
new CSV(data, { header: ["year", "age", "status", "sex", "population"] }).encode();
/*
Returns:
"year","age","status","sex","population"\r\n\
1850,20,0,1,1017281\r\n\
1850,20,0,2,1003841\r\n\
*/
```
To add headers to an `array of objects`, just set `header` to `true`.
```javascript
var data = [
{ year: 1850, age: 20, status: 0, sex: 1, population: 1017281 },
{ year: 1850, age: 20, status: 0, sex: 2, population: 1003841 }
];
new CSV(data, { header: true }).encode();
/*
Returns:
"year","age","status","sex","population"\r\n\
1850,20,0,1,1017281\r\n\
1850,20,0,2,1003841\r\n\
*/
```
Streaming
---------
If 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.
```javascript
var data = '\
1850,20,0,1,1017281\r\n\
1850,20,0,2,1003841\r\n\
...
';
new CSV(data).forEach(function(array) {
/*
* do something with the incoming array
* array example:
* [1850, 20, 0, 1, 1017281]
*/
});
```
Likewise, if you've requested an `array of objects`, you can still call `CSV.prototype.forEach`:
```javascript
var data = '\
year,age,status,sex,population\r\n\
1850,20,0,1,1017281\r\n\
1850,20,0,2,1003841\r\n\
...
';
new CSV(data, { header: true }).forEach(function(object) {
/*
* do something with the incoming object
* object example:
* { year: 1850, age: 20, status: 0, sex: 1, population: 1017281 }
*/
});
```
If 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:
```javascript
var data = [[1850, 20, 0, 1, 1017281], [1850, 20, 0, 2, 1003841]];
new CSV(data).forEach(function(line) {
/*
* do something with the incoming line
* line example:
* "1850,20,0,1,1017281\r\n\""
*/
});
```
Special Thanks
--------------
- [Benjamin Gruenbaum](https://github.com/benjamingr) for helping improve performance.
没有合适的资源?快使用搜索试试~ 我知道了~
毕设&课程作业_基于空间众包的动态物流配送路径智能规划系统.zip
共138个文件
js:45个
css:15个
scss:11个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 26 浏览量
2024-02-05
11:37:24
上传
评论
收藏 27.38MB ZIP 举报
温馨提示
计算机类毕业设计、课程作业,系统源码!!!
资源推荐
资源详情
资源评论
收起资源包目录
毕设&课程作业_基于空间众包的动态物流配送路径智能规划系统.zip (138个子文件)
bootstrap.css 143KB
bootstrap.css 143KB
bootstrap.min.css 118KB
bootstrap.min.css 118KB
bootstrap-theme.css 26KB
bootstrap-theme.css 26KB
demo.css 24KB
bootstrap-theme.min.css 23KB
bootstrap-theme.min.css 23KB
jquery.datetimepicker.css 18KB
jquery.datetimepicker.css 18KB
dropify.css 13KB
dropify.min.css 10KB
app.css 4KB
ol.css 4KB
90Tdis.csv 50KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.eot 20KB
dropify.eot 5KB
dropify.eot 5KB
.gitignore 42B
index.html 8KB
index.html 7KB
index.html 6KB
scroll.html 2KB
index.html 1KB
index.html 62B
flask_sc.iml 758B
test-image-2.jpg 174KB
test-image-1.jpg 134KB
cover.jpg 17KB
ol-debug.js 2.53MB
ol-debug.js 2.53MB
ol.js 522KB
ol.js 522KB
jquery.js 278KB
jquery.datetimepicker.full.js 111KB
jquery.js 91KB
jquery4.js 91KB
jquery-3.2.1.min.js 85KB
require.js 84KB
jquery.datetimepicker.js 82KB
bootstrap.js 68KB
bootstrap.js 68KB
jquery.datetimepicker.full.min.js 55KB
jquery.datetimepicker.min.js 47KB
jquery.datetimepicker.min.js 44KB
bootstrap.min.js 36KB
bootstrap.min.js 36KB
panel.js 26KB
dropify.js 17KB
dropify.js 16KB
mapbox-streets-v6-style.js 12KB
mapbox-streets-v6-style.js 12KB
csv.js 11KB
dropify.min.js 10KB
jquery.mousewheel.js 7KB
jquery-mousewheel.js 7KB
toolkit.js 7KB
csv.min.js 3KB
test.js 3KB
inputTask.js 3KB
Task.js 2KB
benchmark.js 2KB
main.js 2KB
inputWorker.js 2KB
member.js 2KB
inputTID.js 2KB
Route.js 2KB
Collect_Workers.js 2KB
Collect_Tasks.js 1KB
Worker.js 967B
Menu.js 909B
npm.js 484B
npm.js 484B
app.js 477B
package.json 760B
bower.json 599B
bootstrap.min.css.map 529KB
bootstrap.min.css.map 529KB
bootstrap.css.map 380KB
bootstrap.css.map 380KB
bootstrap-theme.css.map 47KB
bootstrap-theme.css.map 47KB
bootstrap-theme.min.css.map 25KB
bootstrap-theme.min.css.map 25KB
README.md 5KB
README.md 1KB
fig5.png 741KB
fig1.png 715KB
fig4.png 448KB
fig2.png 444KB
fig3.png 302KB
tabu_search.py 9KB
initi_algorithm.py 9KB
coord_transform.py 5KB
get_dismatrix.py 3KB
flask_sc.py 2KB
initi_algorithm.cpython-36.pyc 7KB
tabu_search.cpython-36.pyc 6KB
共 138 条
- 1
- 2
资源评论
学术菜鸟小晨
- 粉丝: 1w+
- 资源: 4941
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功