@reventlessdev/rescript-fast-csv 2.0.0-alpha.10 → 2.0.0-alpha.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # 2.0.0-alpha.11 (2026-09-09)
7
+
8
+ **Note:** Version bump only for package @reventlessdev/rescript-fast-csv
9
+
10
+
11
+
12
+
13
+
6
14
  # 2.0.0-alpha.10 (2026-09-08)
7
15
 
8
16
  **Note:** Version bump only for package @reventlessdev/rescript-fast-csv
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@reventlessdev/rescript-fast-csv",
3
- "version": "2.0.0-alpha.10",
3
+ "version": "2.0.0-alpha.11",
4
4
  "description": "ReScript bindings for fast-csv",
5
5
  "license": "Apache-2.0",
6
6
  "dependencies": {
7
7
  "fast-csv": "^5.0.5",
8
- "@reventlessdev/rescript-node": "2.0.0-alpha.10"
8
+ "@reventlessdev/rescript-node": "2.0.0-alpha.11"
9
9
  },
10
10
  "devDependencies": {
11
11
  "rescript": "12.3.0"
@@ -10,11 +10,16 @@ let toError: (FastCSV.callback, FastCSV.reason) => FastCSV.calledBack = (cb, rea
10
10
  cb(Nullable.make(FastCSV.makeError(reason)), false, Some(reason))
11
11
 
12
12
  /** Call the transformation-callback function for a valid transformation */
13
- let toValidTransformation: (FastCSV.transformCallback, FastCSV.row) => FastCSV.transformCalledBack = (cb, row) =>
14
- cb(Nullable.null, Some(row))
13
+ let toValidTransformation: (
14
+ FastCSV.transformCallback,
15
+ FastCSV.row,
16
+ ) => FastCSV.transformCalledBack = (cb, row) => cb(Nullable.null, Some(row))
15
17
 
16
18
  /** Call the transformation-callback function for an error in the transformation */
17
- let toErrorTransformation: (FastCSV.transformCallback, FastCSV.reason) => FastCSV.transformCalledBack = (cb, reason) =>
19
+ let toErrorTransformation: (
20
+ FastCSV.transformCallback,
21
+ FastCSV.reason,
22
+ ) => FastCSV.transformCalledBack = (cb, reason) =>
18
23
  cb(Nullable.make(FastCSV.makeError(reason)), None)
19
24
 
20
25
  /** Add callback for validation to Result - to be used in validation function */
@@ -26,22 +31,24 @@ let fromImporterValidation: FastCSV.importerValidation => FastCSV.validation = v
26
31
  }
27
32
 
28
33
  /** Register multiple validation-functions, which will be called separately */
29
- let validateMultiple: (array<FastCSV.validation>, FastCSV.csvParserStream) => FastCSV.csvParserStream = (
30
- validations,
31
- parser,
32
- ) => validations->Array.reduce(parser, (parser', validation) => parser'->FastCSV.validate(validation))
34
+ let validateMultiple: (
35
+ array<FastCSV.validation>,
36
+ FastCSV.csvParserStream,
37
+ ) => FastCSV.csvParserStream = (validations, parser) =>
38
+ validations->Array.reduce(parser, (parser', validation) => parser'->FastCSV.validate(validation))
33
39
 
34
40
  /** Register a single validation function based on result */
35
- let validateResult: (FastCSV.csvParserStream, FastCSV.importerValidation) => FastCSV.csvParserStream = (
36
- parser,
37
- validation,
38
- ) => parser->FastCSV.validate(validation->fromImporterValidation)
41
+ let validateResult: (
42
+ FastCSV.csvParserStream,
43
+ FastCSV.importerValidation,
44
+ ) => FastCSV.csvParserStream = (parser, validation) =>
45
+ parser->FastCSV.validate(validation->fromImporterValidation)
39
46
 
40
47
  /** Register multiple result based validation functions, which will be called separately */
41
- let validateMultipleResults: (FastCSV.csvParserStream, array<FastCSV.importerValidation>) => FastCSV.csvParserStream = (
42
- parser,
43
- validations,
44
- ) =>
48
+ let validateMultipleResults: (
49
+ FastCSV.csvParserStream,
50
+ array<FastCSV.importerValidation>,
51
+ ) => FastCSV.csvParserStream = (parser, validations) =>
45
52
  validations
46
53
  ->Array.map(validation => validation->fromImporterValidation)
47
54
  ->validateMultiple(parser)
@@ -0,0 +1,28 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as FastCsv from "fast-csv";
4
+ import * as Stdlib_Dict from "@rescript/runtime/lib/es6/Stdlib_Dict.js";
5
+ import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
6
+ import * as FastCSV_Helpers from "../FastCSV_Helpers.res.mjs";
7
+
8
+ FastCsv.parseFile("x.csv", {
9
+ delimiter: ";",
10
+ headers: true
11
+ }).transform((row, cb) => {
12
+ Stdlib_Dict.$$delete(row, "");
13
+ return FastCSV_Helpers.toValidTransformation(cb, row);
14
+ }).on("data", row => {
15
+ console.log("parsed line:", row);
16
+ }).on("data-invalid", (row, rowNumber, reason) => {
17
+ if (reason !== undefined) {
18
+ console.log(`line (` + rowNumber.toString() + `) is invalid: ` + reason, row);
19
+ } else {
20
+ console.log(`line (` + rowNumber.toString() + `) has too many/view records:`, row);
21
+ }
22
+ }).on("error", err => {
23
+ console.log("error during parsing:", Stdlib_JsExn.message(err));
24
+ }).on("end", rowCount => {
25
+ console.log(rowCount.toString() + ` rows parsed`);
26
+ });
27
+
28
+ /* Not a pure module */