Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fast-csv

Package Overview
Dependencies
Maintainers
2
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-csv - npm Package Compare versions

Comparing version 3.3.0 to 3.4.0

2

.mocharc.js

@@ -8,3 +8,3 @@ module.exports = {

slow: 75,
timeout: 2000,
timeout: 5000,
recursive: true,

@@ -11,0 +11,0 @@ ui: 'bdd'

@@ -8,2 +8,3 @@ /// <reference types="node" />

private rowFormatter;
private hasWrittenBOM;
constructor(formatterOptions: FormatterOptions);

@@ -10,0 +11,0 @@ transform(transformFunction: RowTransformFunction): CsvFormatterStream;

@@ -8,4 +8,8 @@ "use strict";

super({ objectMode: formatterOptions.objectMode });
this.hasWrittenBOM = false;
this.formatterOptions = formatterOptions;
this.rowFormatter = new RowFormatter_1.default(formatterOptions);
// if writeBOM is false then set to true
// if writeBOM is true then set to false by default so it is written out
this.hasWrittenBOM = !formatterOptions.writeBOM;
}

@@ -19,2 +23,6 @@ transform(transformFunction) {

try {
if (!this.hasWrittenBOM) {
this.push(this.formatterOptions.BOM);
this.hasWrittenBOM = true;
}
this.rowFormatter.format(row, (err, rows) => {

@@ -21,0 +29,0 @@ if (err) {

@@ -34,5 +34,7 @@ "use strict";

const { formatterOptions } = this;
const shouldEscape = preparedField.indexOf(formatterOptions.quote) !== -1;
if (shouldEscape) {
return this.quoteField(preparedField.replace(this.REPLACE_REGEXP, formatterOptions.escapedQuote));
if (formatterOptions.quote !== '') {
const shouldEscape = preparedField.indexOf(formatterOptions.quote) !== -1;
if (shouldEscape) {
return this.quoteField(preparedField.replace(this.REPLACE_REGEXP, formatterOptions.escapedQuote));
}
}

@@ -39,0 +41,0 @@ const hasEscapeCharacters = preparedField.search(this.ESCAPE_REGEXP) !== -1;

@@ -10,3 +10,3 @@ import { RowTransformFunction } from './types';

rowDelimiter?: string;
quote?: string;
quote?: string | boolean;
escape?: string;

@@ -17,2 +17,3 @@ quoteColumns?: QuoteColumns;

includeEndRowDelimiter?: boolean;
writeBOM?: boolean;
transform?: RowTransformFunction;

@@ -32,5 +33,7 @@ }

readonly shouldWriteHeaders: boolean;
readonly writeBOM: boolean;
readonly escapedQuote: string;
readonly BOM: string;
constructor(opts?: FormatterOptionsArgs);
}
export {};

@@ -15,2 +15,4 @@ "use strict";

this.transform = null;
this.writeBOM = false;
this.BOM = '\ufeff';
if (opts) {

@@ -21,2 +23,8 @@ Object.assign(this, opts);

}
if (opts.quote === true) {
this.quote = '"';
}
else if (opts.quote === false) {
this.quote = '';
}
if (typeof opts.escape !== 'string') {

@@ -23,0 +31,0 @@ this.escape = this.quote;

@@ -14,4 +14,4 @@ /**

fromStream: (stream: NodeJS.ReadableStream, options?: import("./parser").ParserOptionsArgs | undefined) => import("./parser").CsvParserStream;
parseFile: (location: string, options?: {}) => import("./parser").CsvParserStream;
fromPath: (location: string, options?: {}) => import("./parser").CsvParserStream;
parseFile: (location: string, options?: import("./parser").ParserOptionsArgs) => import("./parser").CsvParserStream;
fromPath: (location: string, options?: import("./parser").ParserOptionsArgs) => import("./parser").CsvParserStream;
format: (options?: import("./formatter").FormatterOptionsArgs | undefined) => import("./formatter").CsvFormatterStream;

@@ -18,0 +18,0 @@ write: (rows: import("./formatter").Row[], options?: import("./formatter").FormatterOptionsArgs | undefined) => import("./formatter").CsvFormatterStream;

@@ -9,3 +9,3 @@ /// <reference types="node" />

export declare const parseStream: (stream: NodeJS.ReadableStream, options?: ParserOptionsArgs | undefined) => CsvParserStream;
export declare const parseFile: (location: string, options?: {}) => CsvParserStream;
export declare const parseFile: (location: string, options?: ParserOptionsArgs) => CsvParserStream;
export declare const parseString: (string: string, options?: ParserOptionsArgs | undefined) => CsvParserStream;

@@ -36,7 +36,13 @@ # Formatting

* `rowDelimiter: {string} = '\n'`: Specify an alternate row delimiter (i.e `\r\n`)
* `quote: {string} = '"'`: The character to use to quote fields that contain a delimiter. If you set to `null` then all quoting will be ignored.
* `"first,name",last name`
* `quote: {string|boolean} = '"'`:
* If provided as a string it will be used to quote fields that contain a delimiter.
* `"first,name",last name`
* If `quote` is set to `true` the default quote will be used.
* **NOTE** This is the same as not providing the option
* If `quote` false then quoting will be disabled
* **CAUTION** If your field could contain a delimiter then you may end up with extra columns
* `escape: {string} = '"'`: The character to use when escaping a value that is `quoted` and contains a `quote` character that is not the end of the field.
* `i.e`: `First,"Name"' => '"First,""Name"""`
* `includeEndRowDelimiter: {boolean} = false`: Set to `true` to include a row delimiter at the end of the csv.
* `writeBOM: {boolean} = false`: Set to true if you want the first character written to the stream to be a utf-8 BOM character.
* `headers: {null|boolean|string[]} = null`:

@@ -43,0 +49,0 @@ * If true then the headers will be auto detected from the first row.

@@ -0,1 +1,9 @@

# v3.4.0
* [FIXED] formatter.js: Disabling quote doesn't work [#97](https://github.com/C2FO/fast-csv/issues/97)
* Changed to allow the `quote` option to be provided as a boolean so when set to false all quoting is ignored.
* [ADDED] `writeBOM` option when formatting a csv [#180](https://github.com/C2FO/fast-csv/issues/180)
* Added tests for [#102](https://github.com/C2FO/fast-csv/issues/102)
# v3.3.0

@@ -2,0 +10,0 @@

{
"name": "fast-csv",
"version": "3.3.0",
"version": "3.4.0",
"description": "CSV parser and writer",

@@ -5,0 +5,0 @@ "main": "./build/src/index.js",

@@ -11,2 +11,4 @@ import { Transform, TransformCallback } from 'stream';

private hasWrittenBOM: boolean = false;
public constructor(formatterOptions: FormatterOptions) {

@@ -16,2 +18,5 @@ super({ objectMode: formatterOptions.objectMode });

this.rowFormatter = new RowFormatter(formatterOptions);
// if writeBOM is false then set to true
// if writeBOM is true then set to false by default so it is written out
this.hasWrittenBOM = !formatterOptions.writeBOM;
}

@@ -27,2 +32,6 @@

try {
if (!this.hasWrittenBOM) {
this.push(this.formatterOptions.BOM);
this.hasWrittenBOM = true;
}
this.rowFormatter.format(row, (err, rows): void => {

@@ -29,0 +38,0 @@ if (err) {

@@ -45,7 +45,9 @@ import { isBoolean, isNil, escapeRegExp } from 'lodash';

const { formatterOptions } = this;
const shouldEscape = preparedField.indexOf(formatterOptions.quote) !== -1;
if (shouldEscape) {
return this.quoteField(
preparedField.replace(this.REPLACE_REGEXP, formatterOptions.escapedQuote)
);
if (formatterOptions.quote !== '') {
const shouldEscape = preparedField.indexOf(formatterOptions.quote) !== -1;
if (shouldEscape) {
return this.quoteField(
preparedField.replace(this.REPLACE_REGEXP, formatterOptions.escapedQuote)
);
}
}

@@ -52,0 +54,0 @@ const hasEscapeCharacters = preparedField.search(this.ESCAPE_REGEXP) !== -1;

@@ -13,3 +13,3 @@ import { RowTransformFunction } from './types';

rowDelimiter?: string;
quote?: string;
quote?: string | boolean;
escape?: string;

@@ -20,2 +20,3 @@ quoteColumns?: QuoteColumns;

includeEndRowDelimiter?: boolean;
writeBOM?: boolean;
transform?: RowTransformFunction;

@@ -47,4 +48,8 @@ }

public readonly writeBOM: boolean = false;
public readonly escapedQuote: string;
public readonly BOM: string = '\ufeff';
public constructor(opts: FormatterOptionsArgs = {}) {

@@ -56,2 +61,7 @@ if (opts) {

}
if (opts.quote === true) {
this.quote = '"';
} else if (opts.quote === false) {
this.quote = '';
}
if (typeof opts.escape !== 'string') {

@@ -58,0 +68,0 @@ this.escape = this.quote;

@@ -15,3 +15,3 @@ import * as fs from 'fs';

export const parseFile = (location: string, options = {}): CsvParserStream => fs
export const parseFile = (location: string, options: ParserOptionsArgs = {}): CsvParserStream => fs
.createReadStream(location)

@@ -18,0 +18,0 @@ .pipe(new CsvParserStream(new ParserOptions(options)));

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc