https://github.com/imjuni/simple-csv
Simple CSV generator for Node.js
https://github.com/imjuni/simple-csv
Last synced: about 1 year ago
JSON representation
Simple CSV generator for Node.js
- Host: GitHub
- URL: https://github.com/imjuni/simple-csv
- Owner: imjuni
- License: mit
- Created: 2016-02-16T06:14:40.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-05-10T04:40:56.000Z (about 10 years ago)
- Last Synced: 2024-10-25T04:11:28.141Z (over 1 year ago)
- Language: JavaScript
- Size: 12.7 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Simple-CSV
====
Simple csv generator for Node.js. Simple CSV is super simple and easy.
# Function
* `append` - set data on buffer and array
* `write` - write file on disk
* `Data` - get data array
* `Buf` - get Buffer
# Options
* `encoding` - Encoding for Buffer class. If you don't set this value, then the default is 'utf8'
* `sep` - Column separation character. If you want tsv file, set '\t'. If you don't set this value, then the default is
','
* `surrounder` - Surrounder for specific case, has linefeed or comma etc
* `EOL` - Row separation character. If you don't set this value, then the default is require('os').EOL
* `interval` - If you set huge size data using append method, append method use setInterval
instead of for, while loop. Because If you using on Express or http server, not blocking response.
interval set setInterval interval
* excel - If you use csv file in excel, enable this flag true. That is prevent long number,
for example 1006201603211027052281012300 is automatic covert scientific notation. If
this flag enable set true, converted ="1006201603211027052281012300" so that is prevent
conversion to scientific notation. But default value is false.
# Example
If you more example, see below examples directory.
```
'use strict';
var co = require('co');
var debug = require('debug')('ssc:example');
var SimpleCSV = require('../lib/csv.js');
let data = [
[1, 2, 3, 4],
['a', 'b', 'c', 'd'],
['a', ',b,', 'c', 'd'],
['a', 'b,""', 'c""', 'd'],
['e', 'f', 'g', 'h\nh\nh'],
['한', '글', '입', '력'],
['한', '글', '입', '력']
];
let csv = new SimpleCSV();
co(function* a () {
yield csv.append(data);
yield csv.write('test.csv');
}).then(function () {
debug('Complete, ... generated test.csv')
}).catch(function (err) {
debug('Error caused, ...');
debug(err.message);
debug(err.stack);
});
```