Code Monkey home page Code Monkey logo

node-csv-stringify's Introduction

CSV Stringify for Node.js has been merged into Node.js CSV monorepo!

You can find the latest version of the source code inside the Node.js CSV repository, where it will continue to be developed.

Please report any bugs to the Node.js CSV issue tracker directly.

The approach used for merging this repository into monorepo is described in this article.

An archive of the source code before the merge is available here.

node-csv-stringify's People

Contributors

autopp avatar behroozk avatar bkw avatar brunomachadob avatar cmbuckley avatar daguej avatar denisfrezzato avatar derekaug avatar drdmitry avatar igor-savin-ht avatar jmarca avatar jpage-godaddy avatar kevinoid avatar kibertoad avatar rauno56 avatar sergkudinov avatar shackbarth avatar tomyam1 avatar wdavidw avatar yonilerner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-csv-stringify's Issues

Escaping formula (CSV Injection)

We're a happy users of your library but it has recently been highlighted to us that we have issues with "CSV Injection". I haven't come across this before but it seems it means that we make no effort to escape any formula, commands or | characters in the inputs and that means that people could create CSV files that cause trouble when opened in Excel.

I can't tell if a library such as yours should trouble itself with such a thing. I also can't tell if it is possible to use some of the available options to mitigate the problem. The advice we were given was that we should make sure:

The input does not start with “=”, “+”, “-“ or “@”
The input does not contain the pipe “|” character.

Some blogs about the topic suggest that prefixing the cell value with a single quote or a tab character is sufficient to avoid the problem.

I have tried to use the quote & escape options but I don't feel like it is enough. If I force double quotes around everything, then LibreOffice ignores them (I guess that is part of the CSV spec?). If I force single quotes then they are displayed in the spreadsheet in an unappealing manner.

I feel that from some experimentation that double quotes with an extra space at the front ahead of any entries with =, +, - or @ might be the way forward. Unfortunately it is not possible to provide a string formatter so I don't believe I can do that.

That's kind of a summary of where I'm at. Sorry if this is all super basic and I'm missing something. I assume this has come up before but I'm not seeing anything in the docs or issues though I often miss things, so sorry if I have.

Incorrect response when an escaped quote(") is present in the input

Using [email protected]

the result doesn't have the escaped quote, but instead has two quotes.

function print(input) {
    var stringify = require('csv-stringify');
    stringify(input, function(err, data) {console.log(data)})
}

> var input = [["first col", "second \"col", "third col"]]
undefined
> print(input)
undefined
> first col,"second ""col",third col


undefined
>

TypeError: Cannot read property 'prototype' of undefined

Hi

I am having trouble getting this module to load. At this point, I have everything commented out, except for var stringify = require('csv-stringify');. When I run it, I get this:


node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
TypeError: Cannot read property 'prototype' of undefined
    at Object.inherits (util.js:511:43)
    at Object.<anonymous> (/root/node_modules/csv-stringify/lib/index.js:81:6)
    at Module._compile (module.js:441:26)
    at Object..js (module.js:459:10)
    at Module.load (module.js:348:32)
    at Function._load (module.js:308:12)
    at Module.require (module.js:354:17)
    at require (module.js:370:17)
    at Object.<anonymous> (/root/streaming_client.js:2:17)
    at Module._compile (module.js:441:26)

I am using version 0.0.2 of csv-stringify. Is there something else I need to do?

Thanks!

typeerror cannot read property 'prototype' of undefined

Hi

I am having trouble getting an error when i upload .csv file. this error occurrs only in ubuntu server,in normal machine it working fine,

TypeError: Cannot read property 'prototype' of undefined
at Object.exports.inherits (util.js:538:43)
at Object.<anonymous> (/var/apps/node_modules/csvtojson/libs/core/Result.js:9:6)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object.<anonymous> (/var/apps/node_modules/csvtojson/libs/core/csvConverter.js:8:14)
at Module._compile (module.js:449:26)

Escape Character Does Not Get Escaped

When using the escape option, if the provided escape character is present in the input, it is not escaped.

Here's an example.

var stream = require('stream'),
    stringify = require('csv-stringify'),
    parse = require('csv-parse');

var stringifier = stringify({"header":true, "quoted":true, "escape":"\\"});

var parser = parse({"columns": true, "escape":'\\'});

var input = { "one": "test", "two": 'This a string with \\"backslashes\\" in it'};

var rs = new stream.Readable({ objectMode: true });

rs.push(input);
rs.push(null);
rs.pipe(stringifier)
    .pipe(parser);

This is a little hard to follow but this string, 'This a string with \\"backslashes\\" in it', has a single backslash (escaped in javascript) followed by a quote, which occurs two times.

When you console.log it, it looks like this:
'This a string with \"backslashes\" in it'

Expected

What should happen is that this string gets turned into a string like this:
'This a string with \\\"backslashes\\\" in it'

That's one escape character for the already present \ and a second for the ".

Observed

What actually happens is that it gets turned into a string like this:
'This a string with \\"backslashes\\" in it'

one escape character for the delimiter " and nothing for the already existing escape character.

Error in code

var stringify = require('csv-stringify');

stringify(items, function(err, output) { // array of Mongoose documents
  if (err) {
    throw new Error(err);
  } else {
    console.log(output);
  }
});

I get the error:

csv-stringify/lib/index.js:250
        containsdelimiter = field.indexOf(delimiter) >= 0;
                                  ^
TypeError: Object #<InternalCache> has no method 'indexOf'
    at Stringifier.stringify (csv-stringify/lib/index.js:250:35)
    at Stringifier.write (csv-stringify/lib/index.js:182:20)
    at module.exports.chunks (csv-stringify/lib/index.js:43:21)
    at process._tickCallback (node.js:419:13)

does not implement quote disablement

Hello,

Is there a particular reason why this library doesn't allow one to disable quoting and therefore escape the delimiter and newline characters?

If not, would you be willing to accept a PR?

Looking at a couple of other reputable encoders for node, this feature does not seem to be common. In fact, I've not found one that allows me to disable quotes all together.

unexpected line break at end

stringify([['a','b'],['c','d']], function(err, output) {
    console.log(JSON.stringify(output));
});

results in "a,b\nc,d\n"

whereas I expected "a,b\nc,d"

Sync version

Is it hard to provide synchronous version of that?

Row Limit

I've notice that when compiling my CSV the file is always truncated to 1089 rows even with different data being steamed. Any idea why that would be happening?

how to handle nested objects

Hi,
Thanks for this nice module, helps me stream export large JSON data sets to csv.

Was wondering what't your take on nested object i.e.

{ 
  "name": "Michael",
  "address": {
    "street": "baker st",
    "city": "bla bla"
  }
}

How would you recommend exporting this document to csv ?

Missing License

Instead of filing issues everywhere, I'll put them here :)

You forgot to add a license to these new modules:

  • csv-generate
  • csv-parse
  • stream-transform
  • csv-stringify

Can I assume that they will all be BSD like the original csv module is?

[email protected] Quoted strings get extra double quotes."1" -> """1"""

Extra double quotes are generated when the string is already enclosed in double quotes.
So "1" is output as """1""".

input = [ [ '"1"', '2', '3', '4' ], [ 'a', 'b', 'c', 'd' ] ];
stringify(input,function(output)
{
        console.log(output);
});

I expected the output to be

"1",2,3,4
a,b,c,d

Actual result was:

"""1""",2,3,4
a,b,c,d

Possible culprit is in index.js lines 264:

 if (containsQuote) {
          regexp = new RegExp(quote, 'g');
          field = field.replace(regexp, escape + quote);
        }
        if (shouldQuote) {
          field = quote + field + quote;
        }

shouldQuote is always true when the string contains a quote. So the first statement escapes the double quote by adding another double quote. The second statement wraps it in another set of double quotes.

Promise support

It would be much more convenient to use csv-stringify if it supported returning result via promise.

We can provide PR if this change is approved.

False treated as null

When stringifying array which includes boolean value, false treated as null and generates empty output.

Invalid string length error

Debug: internal, implementation, error 
    RangeError: Invalid string length
    at Array.join (native)
    at null.<anonymous> (/Users/collumj/work/crdb/xxx-xxxx-utilities/node_modules/csv-stringify/lib/index.js:64:36)
    at emitNone (events.js:72:20)
    at emit (events.js:166:7)
    at endReadableNT (_stream_readable.js:913:12)
    at nextTickCallbackWith2Args (node.js:442:9)
    at process._tickDomainCallback (node.js:397:17)

It does seem relevant to your library though, since other people may run into this issue. The solution was to pull in fewer records from SQL before stringifying them.

csv-stringify Node JS Sample programs not running

Hi,

I have downloaded the latest ["csv-stringify": "^2.0.0"] node libraries and while running the samples I am getting below issues:

/home/ec2-user/tpco.it.rclog/node_modules/csv-stringify/lib/index.js:86
Stringifier = function(opts = {}) {
^

SyntaxError: Unexpected token =
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:387:25)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object. (/home/ec2-user/tpco.it.rclog/node_modules/csv-stringify/samples/api.stream.js:3:17)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)

It looks like the library has some issue

Please help in resolving the same

Inline content disposition

Hello, I am using this module to generate CSV (surprisingly), but I want it to be displayed in the browser instead of being downloaded as a file. From what I can see, there is no control over this. I have tried setting the Content-Disposition header manually to inline but to no avail.

Any thoughts? Current code is:

    //Create stringifier
    const stringifier = csvStringify(options);

    //Pipe to response
    res.set('Content-Type', 'text/csv; charset=utf-8');
    res.set('Content-Disposition', 'inline');
    stringifier.on('finish', () => res.end());
    stringifier.on('error', next);
    stringifier.pipe(res);

Then looping items, writing lines and finishing with stringifier.end();.

Is it memory leak?

Hi!
I have an example bellow. When /test request has arrived application memory usage fast grows and finally app crashes with out of memory error. I tried to do small amount of iteration to try to release memory through stringifier.end(), but after I've called /stop memory is not released. My question is it a real leak, or I just forgot something to do? I doubt because in description said that "It was first released in 2010 and is used against big data sets by a large community". But I did not find anything useful in the documentation.

I've tested on Win x64, node 4.4.7 and 4.2.2, csv 1.1.0

var express = require('express');
var app = express();
var http = require("http");
var csv = require('csv');
var server = http.createServer(app);
var stringifier = csv.stringify();

server.listen(1111);

app.get('/test', function (request, response) {
  for(var i = 0; i < 10000000; ++i) {
    stringifier.write("Hello world");
  }
  response.end('ok');
});

app.get('/stop', function (request, response) {
    stringifier.end();
    response.end('ok stop');
});

can't output European format numbers

I need numbers to be output in format 1.000.000,00 EU format and not 1,000,000.00 (US)

It doesn't seem possible for the moment

Maybe use number.toLocaleString() or simply add an option for a specific number formatter so we can overload the number format

\t for delimeter produces \ and t instead of real tabs

stringify results[0], {delimiter: '\t', header: true}, (err, output) -> 

Expected things like:

1   2   3

But I got:

1\t2\t3

Using \\t did not fix it. The actual fix was to replace the \t directly:

output.replace(/\\t/, '\t')

How to use the sync version?

I see that there is a sync version. How do I use it? I looked for but do not see any documentation.

I tried: require('csv-stringify/sync') without success.

Documentation unclear for CSV Stringifier options: lineBreaks and rowDelimiter

On the documentation page, the following options have the same description:

  • lineBreaks: String used to delimit record rows or a special value; special values are 'auto', 'unix', 'mac', 'windows', 'unicode'; defaults to 'auto' (discovered in source or 'unix' if no source is specified).
  • rowDelimiter: String used to delimit record rows or a special value; special values are 'auto', 'unix', 'mac', 'windows', 'unicode'; defaults to 'auto' (discovered in source or 'unix' if no source is specified).

Do these options serve different purposes? If so, could you please clarify what each option does?

order of headers

I noticed that the header value only takes true, but it just takes the keys of the columns. You can't enforce the order of the keys in an object so I was wondering if there was anyway to enforce a specific order for the headers. If there isn't, I am willing to put in some work to get this feature out. (As they will probably ask me to order it anyway :P)

Issue with UglifyJS

Been using this with Vue-CLI without issue until I tried to build the code and UglifyJS failed at two points,

Stringifier = function(opts = {}) { // index.js, line 97
UglifyJS expects a comma where the equals sign is. This was my fix:

    Stringifier = function(opts) {
        if(!opts){ opts = {}; }

chunk = ${chunk}; // index.js, line 260
UglifyJS doesn't like the backticks. This was my fix:
chunk = ''+ chunk;

Let me know if you see any problems with this. Happy to create a pull request if you think it beneficial.

using pipe api: delimiter option not working for array objects

I am having a bit of trouble.

when the callback of the transformer returns a multiple line output like
[ [ '1', '2', '3', '4' ], [ 'a', 'b', 'c', 'd' ] ]

(the transformer took a line from the parser and created 2 lines)

and i want to use a delimiter option other than comma:

var stringifier = require('csv-stringify')({delimiter: '\t'});

The pipe process does not seem to follow the delimiter option set, it always uses comma.

rs.pipe(parser).pipe(transformer).pipe(stringifier).pipe(process.stdout);

I noticed that in the callback api the array is iterated over, but in the pipe not sure where it iterates.

{ [Error: Command failed: ] killed: false, code: 1, signal: null }

Hi am getting an error while importing .xlsx files, pls anybody help out resolve this issue,,

{ [Error: Command failed: ] killed: false, code: 1, signal: null }

var excelParser = require('excel-parser');
        excelParser.worksheets({
          inFile: 'file'
        }, function(err, worksheets){
          if(err) console.error(err);
          console.log(worksheets);
        });

Can't get stream API to pipe

I cannot figure out how the stream API is supposed to work. This is not my first time using streams.

node v8.11.3
csv-stringify v3.1.1

My code:

const debug = require('debug')('str')
const csvStringify = require('csv-stringify')

const stringifier = csvStringify({
  header: true,
  columns: { name: 'name', locality: 'locality' }
}).pipe(process.stdout)

stringifier.on('error', function (err) {
  debug(err.message)
})
stringifier.on('finish', function () {
  debug('finish')
})

// Waiting, could just use event but lazy
setTimeout(() => {
  stringifier.write(['john', 'world']) // Error, see below
  // This produces err, see below

  // stringifier.write(JSON.stringify(['john', 'world']))
  // // ["john","world"] <- json, not csv
}, 200)

Result

net.js:704
    throw new TypeError(
    ^

TypeError: Invalid data, chunk must be a string or buffer, not object
    at WriteStream.Socket.write (net.js:704:11)
    at Timeout.setTimeout [as _onTimeout] (/Users/john/code/csv-test/str.js:17:15)
    at ontimeout (timers.js:498:11)
    at tryOnTimeout (timers.js:323:5)
    at Timer.listOnTimeout (timers.js:290:5)

I don't understand what I am supposed to call .write with, or how the options might change what I am supposed to call write with. It seems like this module is just a no-op transform stream, but that can't be right.

What is wrong with this code?

Note: the sample code // node samples/stream.js from the website produces the same error

using this module as json to csv converter

Hi, I am trying to use this to convert an array of flat json objects to csv file.

I am using the pipe example. The output I get do not contain headers (keys of the objects)

Is there any way to use this module for this functionality ?

Thanks

Wrong docs link

A link to documentation leads to something completely irrelevant. For starters, I can't even call csv().

field.indexOf Exception

Got exception whilst setting a custom bool formatter. Sample code below. Throwing TypeError: field.indexOf is not a function

var stringify = require( 'csv-stringify' );
var streamify = require( 'stream-array' );

var data = [ { a: true }, { a: false }, { a: true } ];

streamify( data )
.pipe( stringify( {
	columns: [ "a" ],
	formatters: {
		bool: value => {
			return value ? 1 : 0;
		}
	}
} ) )
.pipe( process.stdout );

Stringify with empty columns

If I have columns that act as padding, and the number of columns is greater than 1, it seems that 1 column is ignored and some of the data is shifted around. Ideally, I would like to be able to pass in ['', '', '', 'abc', '', '', ''] and have a CSV with 7 columns and only 1 filled in.

Synchronous stringify

Hello mate,

thanks for the nice parser, but it would be nice if you would document the synchronous version of your stringifiy (csv-stringify/lib/sync)

Best Regards

delimiter is ignored, output is without any delimiters

I'm reading a csv via:

csv.parse(require('fs').readFileSync(process.argv[2]).toString(), function(err, parsed) { ... });

(works great)

then adding some value to the parsed lines, and trying to write it to console line-by-line via:

console.log("before stringify: " + JSON.stringify(line))
csv.stringify(line, { delimiter : ','}, function(err, output) {
   console.log("after stringify: " + output);
});

output is:

before stringify: ["some text","true","1","0","more text"]
after stringify: some texttrue10more text

It doesn't matter if I specify options with delimiter or not, output is always without any delimiter

关于在 Windows 下打开导出的 csv 乱码问题。

这个是由于 UTF-8 的 BOM 问题导致的。

具体可自行查询什么是 BOM。

在导出的头部加上 \uFEFF 即可。

这样在 Windows 下使用 office 打开也不会乱码.

    const content = ["\uFEFF"]; //去除\uFEFF打开就会乱码
    content.push(["乱码测试"]);
    stringify(content);

Original "options" object passed to stringify is modified and shared with subsequent calls.

csv = require('csv');
result = {};
options = { header: true, quotedEmpty:true, delimiter: "|" };
data1 = [ { a:'aa', b:'bb', c:'cc', d:'dd' }, {a:1, b:2, c:3, d:4}, {a:'%', b:'$', c:'#', d:'&'} ];
data2 = [ { x:'x', y:'y', z:'z', q:'q' }, {x:11, y:22, z:33, q:44}, {x:'()', y:'{}', z:'[]', q:'<>'} ];

csv.stringify(data1, options, (e, r1) => {
  result.r1 = r1;

  csv.stringify(data2, options, (e, r2) => {
    result.r2 = r2;

    console.log("==========================\n", result.r1, "==========================");
    console.log("==========================\n", result.r2, "==========================");
  });
});

results with:

====================================
a|b|c|d
aa|bb|cc|dd
1|2|3|4
%|$|#|&
====================================
====================================
a|b|c|d
""|""|""|""
""|""|""|""
""|""|""|""
====================================

Using explicit object literal instead of "options" variable works.

Include Headers

If I have an array of objects like below, How do get the object keys included as headers?

var mergedVarients = [{
    id: 17196648071,
    product_name: '3 Star Hareem Pants',
    product_id: 5494843847,
    title: '6 - 12 months',
    price: '30.00',
    sku: '',
    cost_price: null
}, {
    id: 17196648007,
    product_name: '3 Star Hareem Pants',
    product_id: 5494843847,
    title: '3 - 6 months',
    price: '30.00',
    sku: '',
    cost_price: null
}]

I tried the code below but it does not work

var csvStringify = require('csv-stringify');

csvStringify({ header: true})(mergedVarients, function(err, output) {
        console.log('# csvStringify err', err);
        console.log('# csvStringify output', output);
    });

Thanks

Handle nested objects

If an object with nested objects inside..

{ a:1, b:2, c: { foo: 3, bar: 4 } }

...is written to the stream, a cryptic error gets thrown.

TypeError: Object #<Object> has no method 'indexOf'

This should be handled a little more gracefully. For me, simply JSON.stringifying the nested object is a good approach. Something like:

--- lib/index.js    Wed Dec  3 15:43:05 2014
+++ lib/index.js    Wed Dec  3 16:59:59 2014
@@ -248,6 +248,8 @@
         field = field ? '1' : '';
       } else if (field instanceof Date) {
         field = '' + field.getTime();
+      } else if (typeof field === 'object') {
+        field = JSON.stringify(field);
       }
       if (field) {
         containsdelimiter = field.indexOf(delimiter) >= 0;

This would give us output like:

1,2,"{""foo"":3,""bar"":4}"

While ugly and not exactly easy to work with, this is better than erroring out completely.

Changelog

npm says this package is at 2.0.0 but the changelog doesn't have any information about this. Could we please get an updated changelog with details of what changes happened between versions?

"Write after end" error

See the code below.

var csvstringify = require('csv-stringify'),
    es = require('event-stream'),
    csvstringifier = csvstringify({ 'header': true }),
    outStream = fs.createWriteStream('foo.csv', { 'flags': 'w', 'encoding': 'utf-8' }),
    inStream = es.through(function write(data) {
        this.emit('data', data);
    });
inStream.pipe(outStream);
someDataGeneratingObject = new SomeDataGeneratingObject(function (data) {
    es.readArray(events)
        .pipe(csvstringifier)
        .pipe(inStream);
});

After a few data generating events are triggered and written to the _foo.txt_file, I get this error.

Error: write after end
    at writeAfterEnd (_stream_writable.js:133:12)
    at Writable.write (_stream_writable.js:181:5)
    at Stringifier.write (/Users/giacecco/Projects/railsponsibility/node_modules/csv-stringify/lib/index.js:143:43)
    at Stream.ondata (stream.js:51:26)
    at Stream.EventEmitter.emit (events.js:95:17)
    at stream.resume (/Users/giacecco/Projects/railsponsibility/node_modules/event-stream/index.js:108:14)
    at process._tickCallback (node.js:415:13)

The same does not happen if I replace node-csv-stringify with a similar method from the event-stream library: stringify. Of course that does not do the csv conversion.

    (...)
    es.readArray(events)
        .pipe(es.stringify())
        .pipe(inStream);
    (...)

Is that a node-csv-stringify issue or I'm missing something?

Thanks,

Giacecco

Header not written

I have the following piece of code where I attempt to save dynamically generated json objects into a csv file, however the header is not appearing. Any idea what I am doing wrong?

var csvFile = fs.createWriteStream('my.csv',{
        'flags': 'a',
        'encoding': null,
        'mode': '0666'
    });

    var myColumns = {
        'technology': 'Headless Technology',
        'date': 'Data of generation',
        'url': 'Url of webpage',
        'duration': 'Duration in ms'
    };

    var stringifier = csv.stringify({ headers: true, columns: myColumns});

    stringifier.on('error', function(err){
        console.log(err.message);
    });

    for (let key of Object.keys(this.data)){

        stringifier.write({
            'technology': key,
            'date': new Date(this.data[key].time).toISOString().replace(/T/, ' ').replace(/\..+/, ''),
            'url': this.data[key].url,
            'duration': this.data[key].duration
        });
    }

    stringifier.end();
    stringifier.pipe(process.stdout);
    stringifier.pipe(csvFile);

This is the process.stdout content:

selenium-webdriver,2016-03-04 19:21:31,www.google.com,6962
phantomjs,2016-03-04 19:21:31,www.google.com,1474

Any help would be greatly appreciated! :)

Node Version: 5.0.0
CSV Version: 0.4.6

index.d.ts Options.columns type of PlainObject?

My thinking is that the type of Options.columns should incorporate something like { key:string,header?:string }[]. Am I misunderstanding the API or the definition of PlainObject? I'm receiving a type error when trying to pass something like { columns:[{ key:'a',header:'A' },{ key:'b',header:'B' }] }:

Type '{ 'key': string; 'header': string; }[]' is not assignable to type 'string[] | PlainObject<string> | undefined'.

columns names

For the following input:

[{ foo: 12, bar: 25 }]

I obtain:

12,25

but I would like:

foo,bar
12,25

Using nested columns

I ran into the follow issue:

  1. I have a data Model (Mongoose) in this case.
  2. My Model has some nested properties.
  3. Csv stringify columns do not seems to be able to find properties deeper than level 1.
  4. I would like to be able to access my nested models and map then to csv columns without the need to first mapping them to level 1 properties on the same model.
// Example Model
var model = {
  'nameOnModel' : 'myName',
  'address': {
    'street' : 'LongRoad'
  }
}

var columns = {
  'nameOnModel' : 'nameOfHeader', // This works fine
  'address.street' : 'street' // This does not
}
var stringifier = csv.stringify({columns: columns, header: true})

stringifier.write(model)
stringifier.pipe(process.stdout)

// Output
nameOfHeader, street
myName, 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.