Socket
Socket
Sign inDemoInstall

csv-writer

Package Overview
Dependencies
0
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.2 to 0.0.3

.codeclimate.yml

5

CHANGELOG.md
### 0.0.3: 9 November 2016
* Fixed the bug that fields were not always surrounded by double quotes
* Fixed the bug that white space characters on the edge of fields were trimmed
### 0.0.2: 15 October 2016

@@ -3,0 +8,0 @@

4

lib/field-stringifier.js

@@ -8,3 +8,3 @@

if (typeof value === 'undefined' || value === null) return '';
const str = String(value).trim();
const str = String(value);
return this._needsQuote(str) ? `"${str.replace(/"/g, '""')}"` : str;

@@ -14,3 +14,3 @@ }

_needsQuote(str) {
return str.includes(',') || str.includes('\n') || str.startsWith('"') || str.endsWith('"');
return str.includes(',') || str.includes('\n') || str.includes('"');
}

@@ -17,0 +17,0 @@

{
"name": "csv-writer",
"version": "0.0.2",
"version": "0.0.3",
"description": "Convert objects/arrays into a CSV string or write them into a CSV file",

@@ -16,3 +16,5 @@ "main": "index.js",

"keywords": [
"csv", "writer", "stringify"
"csv",
"writer",
"stringify"
],

@@ -27,2 +29,3 @@ "author": "Ryuichi Inagaki",

"chai": "^3.5.0",
"codeclimate-test-reporter": "^0.4.0",
"eslint": "^3.3.1",

@@ -29,0 +32,0 @@ "eslint-config-xo": "^0.15.3",

@@ -0,1 +1,2 @@

[![Build Status](https://travis-ci.org/ryu1kn/csv-writer.svg?branch=master)](https://travis-ci.org/ryu1kn/csv-writer) [![Code Climate](https://codeclimate.com/github/ryu1kn/csv-writer/badges/gpa.svg)](https://codeclimate.com/github/ryu1kn/csv-writer) [![Test Coverage](https://codeclimate.com/github/ryu1kn/csv-writer/badges/coverage.svg)](https://codeclimate.com/github/ryu1kn/csv-writer/coverage)

@@ -41,4 +42,4 @@ # CSV Writer

You can keep writing records into the same file by calling `writeRecords` multiple times (but need to wait for the fulfillment
of the `promise` of the previous `writeRecords` call)
You can keep writing records into the same file by calling `writeRecords` multiple times
(but need to wait for the fulfillment of the `promise` of the previous `writeRecords` call).

@@ -52,2 +53,6 @@ ```js

However, if you need to keep writing large data to a certain file, you would want to create
node's transform stream and use `CsvStringifier`, which is explained later, inside it
, and pipe the stream into a file write stream.
If you don't want to write a header line, don't give `title` to header elements and just give field ids as a string.

@@ -54,0 +59,0 @@

require('../index'); // Include all source files into coverage report
global.expect = require('chai').expect;
global.sinon = require('sinon');

@@ -11,2 +11,7 @@

it('preserves the whitespace characters', () => {
const stringifier = new FieldStringifier();
expect(stringifier.stringify(' VALUE\tA ')).to.eql(' VALUE\tA ');
});
it('wraps a field value with double quotes if the field contains comma', () => {

@@ -22,10 +27,10 @@ const stringifier = new FieldStringifier();

it('escapes double quotes if it is used on the edge of the field value', () => {
it('wraps a field value with double quotes and escape the double quotes if they are used in the field', () => {
const stringifier = new FieldStringifier();
expect(stringifier.stringify('"VALUE')).to.eql('"""VALUE"');
expect(stringifier.stringify('VALUE"A')).to.eql('"VALUE""A"');
});
it('does not double quote or escape double quotes if it is used not on the edge of the field value', () => {
it('escapes double quotes even if double quotes are only on the both edges of the field', () => {
const stringifier = new FieldStringifier();
expect(stringifier.stringify('VALUE"A')).to.eql('VALUE"A');
expect(stringifier.stringify('"VALUE"')).to.eql('"""VALUE"""');
});

@@ -66,3 +71,3 @@

it('escapes double quotes in a toString-ed field value if the value has double quotes on the edge', () => {
it('escapes double quotes in a toString-ed field value if the value has double quotes', () => {
const stringifier = new FieldStringifier();

@@ -69,0 +74,0 @@ const obj = {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc