Socket
Socket
Sign inDemoInstall

fast-csv

Package Overview
Dependencies
Maintainers
2
Versions
73
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.5.0 to 3.6.0

7

build/src/formatter/formatter/index.d.ts

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

import RowFormatter from './RowFormatter';
declare const _default: {
RowFormatter: typeof RowFormatter;
};
export default _default;
export { default as RowFormatter } from './RowFormatter';
export { default as FieldFormatter } from './FieldFormatter';
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const RowFormatter_1 = __importDefault(require("./RowFormatter"));
exports.default = {
RowFormatter: RowFormatter_1.default,
};
var RowFormatter_1 = require("./RowFormatter");
exports.RowFormatter = RowFormatter_1.default;
var FieldFormatter_1 = require("./FieldFormatter");
exports.FieldFormatter = FieldFormatter_1.default;
//# sourceMappingURL=index.js.map

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

export * from './FormatterOptions';
export * from './formatter';
export declare const format: (options?: FormatterOptionsArgs | undefined) => CsvFormatterStream;

@@ -11,0 +12,0 @@ export declare const write: (rows: FormatterRow[], options?: FormatterOptionsArgs | undefined) => CsvFormatterStream;

@@ -24,2 +24,3 @@ "use strict";

__export(require("./FormatterOptions"));
__export(require("./formatter"));
exports.format = (options) => new CsvFormatterStream_1.default(new FormatterOptions_1.FormatterOptions(options));

@@ -26,0 +27,0 @@ exports.write = (rows, options) => {

@@ -8,6 +8,6 @@ /**

/// <reference types="node" />
export { format, write, writeToStream, writeToBuffer, writeToString, writeToPath } from './formatter';
export { parse, parseString, parseStream, parseFile } from './parser';
export { format, write, writeToStream, writeToBuffer, writeToString, writeToPath, FormatterOptionsArgs, Row as FormatterRow, RowMap as FormatterRowMap, RowArray as FormatterRowArray, RowHashArray as FormatterRowHashArray, RowTransformCallback as FormatterRowTransformCallback, RowTransformFunction as FormatterRowTransformFunction, } from './formatter';
export { parse, parseString, parseStream, parseFile, ParserOptionsArgs, Row as ParserRow, RowMap as ParserRowMap, RowArray as ParserRowArray, RowValidateCallback as ParserRowValidateCallback, SyncRowValidate as ParserSyncRowValidate, AsyncRowValidate as ParserAsyncRowValidate, RowValidate as ParserRowValidate, RowTransformCallback as ParserRowTransformCallback, SyncRowTransform as ParserSyncRowTransform, AsyncRowTransform as ParserAsyncRowTransform, RowTransformFunction as ParserRowTransformFunction, } from './parser';
export declare const fromString: (string: string, options?: import("./parser").ParserOptionsArgs | undefined) => import("./parser").CsvParserStream;
export declare const fromStream: (stream: NodeJS.ReadableStream, options?: import("./parser").ParserOptionsArgs | undefined) => import("./parser").CsvParserStream;
export declare const fromPath: (location: string, options?: import("./parser").ParserOptionsArgs) => import("./parser").CsvParserStream;

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

private rowCount;
private parsedRowCount;
private parsedLineCount;
private endEmitted;
constructor(parserOptions: ParserOptions);
private get hasHitRowLimit();
private get shouldEmitRows();
private get shouldSkipLine();
transform(transformFunction: RowTransformFunction): CsvParserStream;

@@ -24,2 +29,3 @@ validate(validateFunction: RowValidate): CsvParserStream;

private transformRow;
private pushRow;
}

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

this.rowCount = 0;
this.parsedRowCount = 0;
this.parsedLineCount = 0;
this.endEmitted = false;

@@ -20,2 +22,11 @@ this.parserOptions = parserOptions;

}
get hasHitRowLimit() {
return this.parserOptions.limitRows && this.rowCount >= this.parserOptions.maxRows;
}
get shouldEmitRows() {
return this.parsedRowCount > this.parserOptions.skipRows;
}
get shouldSkipLine() {
return this.parsedLineCount <= this.parserOptions.skipLines;
}
transform(transformFunction) {

@@ -41,2 +52,6 @@ this.rowTransformerValidator.rowTransform = transformFunction;

_transform(data, encoding, done) {
// if we have hit our maxRows parsing limit then skip parsing
if (this.hasHitRowLimit) {
return done();
}
try {

@@ -46,16 +61,20 @@ const { lines } = this;

const rows = this.parse(newLine, true);
this.processRows(rows, done);
return this.processRows(rows, done);
}
catch (e) {
done(e);
return done(e);
}
}
_flush(done) {
// if we have hit our maxRows parsing limit then skip parsing
if (this.hasHitRowLimit) {
return done();
}
try {
const newLine = this.lines + this.decoder.end();
const rows = this.parse(newLine, false);
this.processRows(rows, done);
return this.processRows(rows, done);
}
catch (e) {
done(e);
return done(e);
}

@@ -74,7 +93,14 @@ }

const iterate = (i) => {
if (i >= rowsLength) {
// if we have emitted all rows or we have hit the maxRows limit option
// then end
if (i >= rowsLength || this.hasHitRowLimit) {
return cb();
}
this.parsedLineCount += 1;
if (this.shouldSkipLine) {
return iterate(i + 1);
}
const row = rows[i];
this.rowCount += 1;
this.parsedRowCount += 1;
const nextRowCount = this.rowCount;

@@ -92,11 +118,5 @@ return this.transformRow(row, (err, transformResult) => {

}
else if (!transformResult.row) {
this.rowCount -= 1;
else if (transformResult.row) {
this.pushRow(transformResult.row);
}
else if (!this.parserOptions.objectMode) {
this.push(JSON.stringify(transformResult.row));
}
else {
this.push(transformResult.row);
}
if (i % 100 === 0) {

@@ -125,4 +145,12 @@ // incase the transform are sync insert a next tick to prevent stack overflow

if (withHeaders.row) {
return this.rowTransformerValidator.transformAndValidate(withHeaders.row, cb);
if (this.shouldEmitRows) {
return this.rowTransformerValidator.transformAndValidate(withHeaders.row, cb);
}
// skipped because of skipRows option remove from total row count
this.rowCount -= 1;
return cb(null, { row: null, isValid: true });
}
// this is a header row dont include in the rowCount or parsedRowCount
this.rowCount -= 1;
this.parsedRowCount -= 1;
return cb(null, { row: null, isValid: true });

@@ -135,4 +163,12 @@ });

}
pushRow(row) {
if (!this.parserOptions.objectMode) {
this.push(JSON.stringify(row));
}
else {
this.push(row);
}
}
}
exports.default = CsvParserStream;
//# sourceMappingURL=CsvParserStream.js.map

@@ -7,2 +7,4 @@ /// <reference types="node" />

export * from './ParserOptions';
export * from './parser';
export * from './transforms';
export declare const parse: (args?: ParserOptionsArgs | undefined) => CsvParserStream;

@@ -9,0 +11,0 @@ export declare const parseStream: (stream: NodeJS.ReadableStream, options?: ParserOptionsArgs | undefined) => CsvParserStream;

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

__export(require("./ParserOptions"));
__export(require("./parser"));
__export(require("./transforms"));
exports.parse = (args) => new CsvParserStream_1.default(new ParserOptions_1.ParserOptions(args));

@@ -26,0 +28,0 @@ exports.parseStream = (stream, options) => stream.pipe(new CsvParserStream_1.default(new ParserOptions_1.ParserOptions(options)));

export { default as Parser } from './Parser';
export { default as RowParser } from './RowParser';
export { Scanner } from './Scanner';
export { Token, MaybeToken } from './Token';
export { ColumnParser, NonQuotedColumnParser, QuotedColumnParser } from './column';

@@ -7,2 +7,10 @@ "use strict";

exports.RowParser = RowParser_1.default;
var Scanner_1 = require("./Scanner");
exports.Scanner = Scanner_1.Scanner;
var Token_1 = require("./Token");
exports.Token = Token_1.Token;
var column_1 = require("./column");
exports.ColumnParser = column_1.ColumnParser;
exports.NonQuotedColumnParser = column_1.NonQuotedColumnParser;
exports.QuotedColumnParser = column_1.QuotedColumnParser;
//# sourceMappingURL=index.js.map

@@ -16,2 +16,5 @@ export interface ParserOptionsArgs {

encoding?: string;
maxRows?: number;
skipLines?: number;
skipRows?: number;
}

@@ -38,3 +41,7 @@ export declare class ParserOptions {

readonly encoding: string;
readonly limitRows: boolean;
readonly maxRows: number;
readonly skipLines: number;
readonly skipRows: number;
constructor(opts?: ParserOptionsArgs);
}

@@ -28,2 +28,6 @@ "use strict";

this.encoding = 'utf8';
this.limitRows = false;
this.maxRows = 0;
this.skipLines = 0;
this.skipRows = 0;
Object.assign(this, opts || {});

@@ -37,2 +41,5 @@ if (this.delimiter.length > 1) {

this.NEXT_TOKEN_REGEXP = new RegExp(`([^\\s]|\\r\\n|\\n|\\r|${this.escapedDelimiter})`);
if (this.maxRows > 0) {
this.limitRows = true;
}
}

@@ -39,0 +46,0 @@ }

@@ -5,3 +5,3 @@ export interface RowMap {

export declare type RowArray = string[];
export declare type Row = string[] | object;
export declare type Row = RowMap | RowArray;
export interface RowValidationResult {

@@ -8,0 +8,0 @@ row: Row | null;

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

# v3.6.0
* [ADDED] `maxRows` option to limit the number of rows parsed. [#275](https://github.com/C2FO/fast-csv/issues/275) [#277](https://github.com/C2FO/fast-csv/pull/277) - [@cbrittingham](https://github.com/cbrittingham)
* [ADDED] `skipRows` to allow skipping parsed rows see [parsing.md](./docs/parsing.md)
* [ADDED] `skipLines` to allow skipping entire lines of a csv [parsing.md](./docs/parsing.md) [#267](https://github.com/C2FO/fast-csv/issues/267)
* Exported formatting and parsing types.
* Removed `.npmignore` in favor of `package.json` files
# v3.5.0

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

{
"name": "fast-csv",
"version": "3.5.0",
"version": "3.6.0",
"description": "CSV parser and writer",

@@ -8,3 +8,3 @@ "main": "./build/src/index.js",

"scripts": {
"prepublish": "npm run build",
"prepare": "npm run build",
"build": "tsc",

@@ -18,2 +18,3 @@ "mocha": "nyc mocha",

},
"files": ["build/src/**"],
"repository": {

@@ -20,0 +21,0 @@ "type": "git",

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

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