node-csv
node-csv copied to clipboard
How to generate emoji content correctly?
I need to transfer emoji into csv, but it doesn't work ,and I have already set the bom of UTF-8.
The result is :

Hi @jiahao-si, this is not related to the parser. Your emoji is made of bytes just like any other information. The parser doesn't modify it and return it, just in a different format. If you want more help, share with us some sample code of your input, your desired output, and without any image or screenshot.
Hi @wdavidw , I just wrote a demo, and the result is what the screenshot show.
` // Import the package main module import * as csv from 'csv' import { createWriteStream } from 'fs';
// Generate 20 records const generator = csv.generate({ delimiter: '|', length: 20 }) // Transform CSV data into records const parser = csv.parse({ delimiter: '|' }) // Transform each value into uppercase const transformer = csv.transform((record) => { return record.map((value) => { return value.toUpperCase() }); }) // Convert objects into a stream const stringifier= csv.stringify({ cast: { string: (value, context) => { // to test emoji return context.index % 2 ? '🤔' : value.toUpperCase(); } }, quoted: true, // add bom_utf8 bom: true })
const writeCsv = createWriteStream('1.csv');
// Run the pipeline generator .pipe(parser) .pipe(transformer) .pipe(stringifier) .pipe(writeCsv)
`
By the way , I opened the csv file using Excel
Please, if you want any help:
- a much more simplified example with only the minimal necessary code with
input -> parse or (not and) stringifiy > expected output - no screenshot
- no excel, this library is not doing anything directly with Excel, I don't even have it. If you want to know how emoji are rendered within excel, create a file, open it in Excel and see if it work.
Closing for lack of activity