export-csv

simple way for export csv

Usage no npm install needed!

<script type="module">
  import exportCsv from 'https://cdn.skypack.dev/export-csv';
</script>

README

export-csv

Artwork by i5ting.

Deps npm GitHub license npm

Install

[sudo]npm install --save export-csv

Usages

默认使用gbk编码

var export_csv = require('.')

var data = [
  {a:1,b:2},
  {a:2,b:2},
  {a:3,b:2}
]
export_csv(data, 'test1.csv')

过滤item,重写数据

var export_csv = require('.')

var data = [
  { a: 1, b: 2 },
  { a: 2, b: 2 },
  { a: 3, b: 2 }
]
export_csv(data, 'test3.csv', function (item) {
  for (var key in item) {
    item[key] = 'yy +' + item[key];
  }
  return item;
})

指定回调函数

var export_csv = require('.')

var data = [
  {a:1,b:2},
  {a:2,b:2},
  {a:3,b:2}
]
export_csv(data, 'test2.csv', function (item) {
  return item;
}, function () {
  console.log('end...');
})

指定回调函数,并生成header

var export_csv = require('.')

var data = [
  {a:1,b:2},
  {a:2,b:2},
  {a:3,b:2}
]
export_csv(data, 'test2.csv', function (item) {
  return item;
}, function () {
  console.log('end...');
}, true)

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

版本历史

  • v1.0.0 初始化版本

欢迎fork和反馈

  • write by i5ting i5ting@126.com

如有建议或意见,请在issue提问或邮件

License

this repo is released under the MIT License.