Socket
Socket
Sign inDemoInstall

@fast-csv/parse

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fast-csv/parse - npm Package Compare versions

Comparing version 4.3.6 to 5.0.0

1

build/src/CsvParserStream.d.ts
/// <reference types="node" />
/// <reference types="node" />
import { Transform, TransformCallback } from 'stream';

@@ -3,0 +4,0 @@ import { ParserOptions } from './ParserOptions';

21

build/src/CsvParserStream.js

@@ -9,10 +9,15 @@ "use strict";

class CsvParserStream extends stream_1.Transform {
parserOptions;
decoder;
parser;
headerTransformer;
rowTransformerValidator;
lines = '';
rowCount = 0;
parsedRowCount = 0;
parsedLineCount = 0;
endEmitted = false;
headersEmitted = false;
constructor(parserOptions) {
super({ objectMode: parserOptions.objectMode });
this.lines = '';
this.rowCount = 0;
this.parsedRowCount = 0;
this.parsedLineCount = 0;
this.endEmitted = false;
this.headersEmitted = false;
this.parserOptions = parserOptions;

@@ -100,3 +105,5 @@ this.parser = new parser_1.Parser(parserOptions);

// incase the transform are sync insert a next tick to prevent stack overflow
setImmediate(() => iterate(i + 1));
setImmediate(() => {
return iterate(i + 1);
});
return undefined;

@@ -103,0 +110,0 @@ }

/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import { ParserOptionsArgs } from './ParserOptions';

@@ -8,5 +12,5 @@ import { CsvParserStream } from './CsvParserStream';

export { ParserOptions, ParserOptionsArgs } from './ParserOptions';
export declare const parse: <I extends Row<any>, O extends Row<any>>(args?: ParserOptionsArgs | undefined) => CsvParserStream<I, O>;
export declare const parseStream: <I extends Row<any>, O extends Row<any>>(stream: NodeJS.ReadableStream, options?: ParserOptionsArgs | undefined) => CsvParserStream<I, O>;
export declare const parseFile: <I extends Row<any>, O extends Row<any>>(location: string, options?: ParserOptionsArgs) => CsvParserStream<I, O>;
export declare const parseString: <I extends Row<any>, O extends Row<any>>(string: string, options?: ParserOptionsArgs | undefined) => CsvParserStream<I, O>;
export declare const parse: <I extends Row, O extends Row>(args?: ParserOptionsArgs) => CsvParserStream<I, O>;
export declare const parseStream: <I extends Row, O extends Row>(stream: NodeJS.ReadableStream, options?: ParserOptionsArgs) => CsvParserStream<I, O>;
export declare const parseFile: <I extends Row, O extends Row>(location: string, options?: ParserOptionsArgs) => CsvParserStream<I, O>;
export declare const parseString: <I extends Row, O extends Row>(string: string, options?: ParserOptionsArgs) => CsvParserStream<I, O>;
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -35,6 +39,15 @@ if (k2 === undefined) k2 = k;

Object.defineProperty(exports, "ParserOptions", { enumerable: true, get: function () { return ParserOptions_2.ParserOptions; } });
exports.parse = (args) => new CsvParserStream_1.CsvParserStream(new ParserOptions_1.ParserOptions(args));
exports.parseStream = (stream, options) => stream.pipe(new CsvParserStream_1.CsvParserStream(new ParserOptions_1.ParserOptions(options)));
exports.parseFile = (location, options = {}) => fs.createReadStream(location).pipe(new CsvParserStream_1.CsvParserStream(new ParserOptions_1.ParserOptions(options)));
exports.parseString = (string, options) => {
const parse = (args) => {
return new CsvParserStream_1.CsvParserStream(new ParserOptions_1.ParserOptions(args));
};
exports.parse = parse;
const parseStream = (stream, options) => {
return stream.pipe(new CsvParserStream_1.CsvParserStream(new ParserOptions_1.ParserOptions(options)));
};
exports.parseStream = parseStream;
const parseFile = (location, options = {}) => {
return fs.createReadStream(location).pipe(new CsvParserStream_1.CsvParserStream(new ParserOptions_1.ParserOptions(options)));
};
exports.parseFile = parseFile;
const parseString = (string, options) => {
const rs = new stream_1.Readable();

@@ -45,2 +58,3 @@ rs.push(string);

};
exports.parseString = parseString;
//# sourceMappingURL=index.js.map

@@ -5,14 +5,23 @@ "use strict";

class ColumnFormatter {
format;
constructor(parserOptions) {
if (parserOptions.trim) {
this.format = (col) => col.trim();
this.format = (col) => {
return col.trim();
};
}
else if (parserOptions.ltrim) {
this.format = (col) => col.trimLeft();
this.format = (col) => {
return col.trimLeft();
};
}
else if (parserOptions.rtrim) {
this.format = (col) => col.trimRight();
this.format = (col) => {
return col.trimRight();
};
}
else {
this.format = (col) => col;
this.format = (col) => {
return col;
};
}

@@ -19,0 +28,0 @@ }

@@ -8,2 +8,5 @@ "use strict";

class ColumnParser {
parserOptions;
nonQuotedColumnParser;
quotedColumnParser;
constructor(parserOptions) {

@@ -10,0 +13,0 @@ this.parserOptions = parserOptions;

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

class NonQuotedColumnParser {
parserOptions;
columnFormatter;
constructor(parserOptions) {

@@ -9,0 +11,0 @@ this.parserOptions = parserOptions;

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

class QuotedColumnParser {
parserOptions;
columnFormatter;
constructor(parserOptions) {

@@ -88,3 +90,3 @@ this.parserOptions = parserOptions;

const linePreview = scanner.lineFromCursor.substr(0, 10).replace(/[\r\n]/g, "\\n'");
throw new Error(`Parse Error: expected: '${parserOptions.escapedDelimiter}' OR new line got: '${nextNonSpaceToken.token}'. at '${linePreview}`);
throw new Error(`Parse Error: expected: '${parserOptions.escapedDelimiter}' OR new line got: '${nextNonSpaceToken.token}'. at '${linePreview}'`);
}

@@ -91,0 +93,0 @@ scanner.advanceToToken(nextNonSpaceToken);

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

class Parser {
constructor(parserOptions) {
this.parserOptions = parserOptions;
this.rowParser = new RowParser_1.RowParser(this.parserOptions);
}
static removeBOM(line) {

@@ -21,2 +17,8 @@ // Catches EFBBBF (UTF-8 BOM) because the buffer-to-string

}
parserOptions;
rowParser;
constructor(parserOptions) {
this.parserOptions = parserOptions;
this.rowParser = new RowParser_1.RowParser(this.parserOptions);
}
parse(line, hasMoreData) {

@@ -23,0 +25,0 @@ const scanner = new Scanner_1.Scanner({

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

class RowParser {
static isEmptyRow(row) {
return row.join(EMPTY_STRING).replace(/\s+/g, EMPTY_STRING) === EMPTY_STRING;
}
parserOptions;
columnParser;
constructor(parserOptions) {

@@ -13,5 +18,2 @@ this.parserOptions = parserOptions;

}
static isEmptyRow(row) {
return row.join(EMPTY_STRING).replace(/\s+/g, EMPTY_STRING) === EMPTY_STRING;
}
parse(scanner) {

@@ -18,0 +20,0 @@ const { parserOptions } = this;

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

class Scanner {
line;
parserOptions;
lineLength;
hasMoreData;
cursor = 0;
constructor(args) {
this.cursor = 0;
this.line = args.line;

@@ -11,0 +15,0 @@ this.lineLength = this.line.length;

import { ParserOptions } from '../ParserOptions';
export declare type MaybeToken = Token | null;
export type MaybeToken = Token | null;
export interface TokenArgs {

@@ -4,0 +4,0 @@ token: string;

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

class Token {
constructor(tokenArgs) {
this.token = tokenArgs.token;
this.startCursor = tokenArgs.startCursor;
this.endCursor = tokenArgs.endCursor;
}
static isTokenRowDelimiter(token) {

@@ -30,4 +25,12 @@ const content = token.token;

}
token;
startCursor;
endCursor;
constructor(tokenArgs) {
this.token = tokenArgs.token;
this.startCursor = tokenArgs.startCursor;
this.endCursor = tokenArgs.endCursor;
}
}
exports.Token = Token;
//# sourceMappingURL=Token.js.map

@@ -10,25 +10,26 @@ "use strict";

class ParserOptions {
escapedDelimiter;
objectMode = true;
delimiter = ',';
ignoreEmpty = false;
quote = '"';
escape = null;
escapeChar = this.quote;
comment = null;
supportsComments = false;
ltrim = false;
rtrim = false;
trim = false;
headers = null;
renameHeaders = false;
strictColumnHandling = false;
discardUnmappedColumns = false;
carriageReturn = '\r';
NEXT_TOKEN_REGEXP;
encoding = 'utf8';
limitRows = false;
maxRows = 0;
skipLines = 0;
skipRows = 0;
constructor(opts) {
var _a;
this.objectMode = true;
this.delimiter = ',';
this.ignoreEmpty = false;
this.quote = '"';
this.escape = null;
this.escapeChar = this.quote;
this.comment = null;
this.supportsComments = false;
this.ltrim = false;
this.rtrim = false;
this.trim = false;
this.headers = null;
this.renameHeaders = false;
this.strictColumnHandling = false;
this.discardUnmappedColumns = false;
this.carriageReturn = '\r';
this.encoding = 'utf8';
this.limitRows = false;
this.maxRows = 0;
this.skipLines = 0;
this.skipRows = 0;
Object.assign(this, opts || {});

@@ -38,5 +39,5 @@ if (this.delimiter.length > 1) {

}
this.escapedDelimiter = lodash_escaperegexp_1.default(this.delimiter);
this.escapeChar = (_a = this.escape) !== null && _a !== void 0 ? _a : this.quote;
this.supportsComments = !lodash_isnil_1.default(this.comment);
this.escapedDelimiter = (0, lodash_escaperegexp_1.default)(this.delimiter);
this.escapeChar = this.escape ?? this.quote;
this.supportsComments = !(0, lodash_isnil_1.default)(this.comment);
this.NEXT_TOKEN_REGEXP = new RegExp(`([^\\s]|\\r\\n|\\n|\\r|${this.escapedDelimiter})`);

@@ -43,0 +44,0 @@ if (this.maxRows > 0) {

@@ -12,8 +12,10 @@ "use strict";

class HeaderTransformer {
parserOptions;
headers = null;
receivedHeaders = false;
shouldUseFirstRow = false;
processedFirstRow = false;
headersLength = 0;
headersTransform;
constructor(parserOptions) {
this.headers = null;
this.receivedHeaders = false;
this.shouldUseFirstRow = false;
this.processedFirstRow = false;
this.headersLength = 0;
this.parserOptions = parserOptions;

@@ -26,3 +28,3 @@ if (parserOptions.headers === true) {

}
else if (lodash_isfunction_1.default(parserOptions.headers)) {
else if ((0, lodash_isfunction_1.default)(parserOptions.headers)) {
this.headersTransform = parserOptions.headers;

@@ -90,6 +92,6 @@ }

const header = headers[i];
if (!lodash_isundefined_1.default(header)) {
if (!(0, lodash_isundefined_1.default)(header)) {
const val = row[i];
// eslint-disable-next-line no-param-reassign
if (lodash_isundefined_1.default(val)) {
if ((0, lodash_isundefined_1.default)(val)) {
rowMap[header] = '';

@@ -105,7 +107,10 @@ }

setHeaders(headers) {
var _a;
const filteredHeaders = headers.filter((h) => !!h);
if (lodash_uniq_1.default(filteredHeaders).length !== filteredHeaders.length) {
const grouped = lodash_groupby_1.default(filteredHeaders);
const duplicates = Object.keys(grouped).filter((dup) => grouped[dup].length > 1);
const filteredHeaders = headers.filter((h) => {
return !!h;
});
if ((0, lodash_uniq_1.default)(filteredHeaders).length !== filteredHeaders.length) {
const grouped = (0, lodash_groupby_1.default)(filteredHeaders);
const duplicates = Object.keys(grouped).filter((dup) => {
return grouped[dup].length > 1;
});
throw new Error(`Duplicate headers found ${JSON.stringify(duplicates)}`);

@@ -115,3 +120,3 @@ }

this.receivedHeaders = true;
this.headersLength = ((_a = this.headers) === null || _a === void 0 ? void 0 : _a.length) || 0;
this.headersLength = this.headers?.length || 0;
}

@@ -118,0 +123,0 @@ }

@@ -10,9 +10,5 @@ "use strict";

class RowTransformerValidator {
constructor() {
this._rowTransform = null;
this._rowValidator = null;
}
// eslint-disable-next-line @typescript-eslint/no-shadow
static createTransform(transformFunction) {
if (types_1.isSyncTransform(transformFunction)) {
if ((0, types_1.isSyncTransform)(transformFunction)) {
return (row, cb) => {

@@ -32,3 +28,3 @@ let transformed = null;

static createValidator(validateFunction) {
if (types_1.isSyncValidate(validateFunction)) {
if ((0, types_1.isSyncValidate)(validateFunction)) {
return (row, cb) => {

@@ -50,4 +46,6 @@ cb(null, { row, isValid: validateFunction(row) });

}
_rowTransform = null;
_rowValidator = null;
set rowTransform(transformFunction) {
if (!lodash_isfunction_1.default(transformFunction)) {
if (!(0, lodash_isfunction_1.default)(transformFunction)) {
throw new TypeError('The transform should be a function');

@@ -58,3 +56,3 @@ }

set rowValidator(validateFunction) {
if (!lodash_isfunction_1.default(validateFunction)) {
if (!(0, lodash_isfunction_1.default)(validateFunction)) {
throw new TypeError('The validate should be a function');

@@ -61,0 +59,0 @@ }

@@ -1,4 +0,4 @@

export declare type RowMap<V = any> = Record<string, V>;
export declare type RowArray<V = any> = V[];
export declare type Row<V = any> = RowMap<V> | RowArray<V>;
export type RowMap<V = any> = Record<string, V>;
export type RowArray<V = any> = V[];
export type Row<V = any> = RowMap<V> | RowArray<V>;
export interface RowValidationResult<R extends Row> {

@@ -9,14 +9,14 @@ row: R | null;

}
export declare type RowValidatorCallback<R extends Row> = (error: Error | null, result?: RowValidationResult<R>) => void;
export declare type RowTransformCallback<R extends Row> = (error?: Error | null, row?: R) => void;
export declare type SyncRowTransform<I extends Row, O extends Row> = (row: I) => O;
export declare type AsyncRowTransform<I extends Row, O extends Row> = (row: I, cb: RowTransformCallback<O>) => void;
export declare type RowTransformFunction<I extends Row, O extends Row> = SyncRowTransform<I, O> | AsyncRowTransform<I, O>;
export type RowValidatorCallback<R extends Row> = (error: Error | null, result?: RowValidationResult<R>) => void;
export type RowTransformCallback<R extends Row> = (error?: Error | null, row?: R) => void;
export type SyncRowTransform<I extends Row, O extends Row> = (row: I) => O;
export type AsyncRowTransform<I extends Row, O extends Row> = (row: I, cb: RowTransformCallback<O>) => void;
export type RowTransformFunction<I extends Row, O extends Row> = SyncRowTransform<I, O> | AsyncRowTransform<I, O>;
export declare const isSyncTransform: <I extends Row<any>, O extends Row<any>>(transform: RowTransformFunction<I, O>) => transform is SyncRowTransform<I, O>;
export declare type RowValidateCallback = (error?: Error | null, isValid?: boolean, reason?: string) => void;
export declare type SyncRowValidate<R extends Row> = (row: R) => boolean;
export declare type AsyncRowValidate<R extends Row> = (row: R, cb: RowValidateCallback) => void;
export declare type RowValidate<R extends Row> = AsyncRowValidate<R> | SyncRowValidate<R>;
export type RowValidateCallback = (error?: Error | null, isValid?: boolean, reason?: string) => void;
export type SyncRowValidate<R extends Row> = (row: R) => boolean;
export type AsyncRowValidate<R extends Row> = (row: R, cb: RowValidateCallback) => void;
export type RowValidate<R extends Row> = AsyncRowValidate<R> | SyncRowValidate<R>;
export declare const isSyncValidate: <R extends Row<any>>(validate: RowValidate<R>) => validate is SyncRowValidate<R>;
export declare type HeaderArray = (string | undefined | null)[];
export declare type HeaderTransformFunction = (headers: HeaderArray) => HeaderArray;
export type HeaderArray = (string | undefined | null)[];
export type HeaderTransformFunction = (headers: HeaderArray) => HeaderArray;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isSyncValidate = exports.isSyncTransform = void 0;
exports.isSyncTransform = (transform) => transform.length === 1;
exports.isSyncValidate = (validate) => validate.length === 1;
const isSyncTransform = (transform) => {
return transform.length === 1;
};
exports.isSyncTransform = isSyncTransform;
const isSyncValidate = (validate) => {
return validate.length === 1;
};
exports.isSyncValidate = isSyncValidate;
//# sourceMappingURL=types.js.map
{
"name": "@fast-csv/parse",
"version": "4.3.6",
"description": "fast-csv parsing package",
"keywords": [
"csv",
"parse",
"fast-csv",
"parser"
],
"author": "doug-martin <doug@dougamartin.com>",
"homepage": "http://c2fo.github.com/fast-csv/packages/parse",
"license": "MIT",
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
"directories": {
"lib": "src",
"test": "__tests__"
},
"files": [
"build/src/**"
],
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "git+https://github.com/C2FO/fast-csv.git",
"directory": "packages/parse"
},
"scripts": {
"prepublishOnly": "npm run build",
"build": "npm run clean && npm run compile",
"clean": "rm -rf ./build && rm -rf tsconfig.tsbuildinfo",
"compile": "tsc"
},
"bugs": {
"url": "https://github.com/C2FO/fast-csv/issues"
},
"dependencies": {
"@types/node": "^14.0.1",
"lodash.escaperegexp": "^4.1.2",
"lodash.groupby": "^4.6.0",
"lodash.isfunction": "^3.0.9",
"lodash.isnil": "^4.0.0",
"lodash.isundefined": "^3.0.1",
"lodash.uniq": "^4.5.0"
},
"devDependencies": {
"@types/lodash.escaperegexp": "4.1.6",
"@types/lodash.groupby": "4.6.6",
"@types/lodash.isfunction": "3.0.6",
"@types/lodash.isnil": "4.0.6",
"@types/lodash.isundefined": "3.0.6",
"@types/lodash.partition": "4.6.6",
"@types/lodash.uniq": "4.5.6",
"@types/sinon": "9.0.9",
"lodash.partition": "4.6.0",
"sinon": "9.2.1"
},
"gitHead": "3dc859edb19924b315051e4c87d6273808a0de73"
"name": "@fast-csv/parse",
"version": "5.0.0",
"description": "fast-csv parsing package",
"keywords": [
"csv",
"parse",
"fast-csv",
"parser"
],
"author": "doug-martin <doug@dougamartin.com>",
"homepage": "https://c2fo.github.io/fast-csv/docs/parsing/getting-started",
"license": "MIT",
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
"directories": {
"lib": "src",
"test": "__tests__"
},
"files": [
"build/src/**"
],
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "git+https://github.com/C2FO/fast-csv.git",
"directory": "packages/parse"
},
"scripts": {
"prepublishOnly": "npm run build",
"build": "npm run clean && npm run compile",
"clean": "rm -rf ./build && rm -rf tsconfig.tsbuildinfo",
"compile": "tsc"
},
"bugs": {
"url": "https://github.com/C2FO/fast-csv/issues"
},
"dependencies": {
"lodash.escaperegexp": "^4.1.2",
"lodash.groupby": "^4.6.0",
"lodash.isfunction": "^3.0.9",
"lodash.isnil": "^4.0.0",
"lodash.isundefined": "^3.0.1",
"lodash.uniq": "^4.5.0"
},
"devDependencies": {
"@types/lodash.escaperegexp": "4.1.9",
"@types/lodash.groupby": "4.6.9",
"@types/lodash.isfunction": "3.0.9",
"@types/lodash.isnil": "4.0.9",
"@types/lodash.isundefined": "3.0.9",
"@types/lodash.partition": "4.6.9",
"@types/lodash.uniq": "4.5.9",
"@types/node": "^20.10.5",
"@types/sinon": "17.0.3",
"lodash.partition": "^4.6.0",
"sinon": "17.0.1"
},
"gitHead": "3305fb8cd9e96d65528cb396862005a737297866"
}

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

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