Skip to content

Commit 6db53fb

Browse files
authored
fix: minor rewording of cast.md for clarity (#137)
1 parent 2cdf580 commit 6db53fb

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/md/parse/options/cast.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,29 @@ keywords: ['csv', 'parse', 'options', 'cast', 'context', 'lines', 'quoting']
77

88
# Option `cast`
99

10-
The `cast` option alter a value. It works at the field level of a record. It is possible to transform its value or change its type.
10+
The `cast` option works at the field-level to alter its value. It is possible to transform the field's value or change its type.
1111

1212
* Type: `function`
1313
* Optional
1414
* Default: `undefined`
1515
* Since: 2.2.0
1616
* Related: `cast_date`, [`info`](/parse/options/info/), [`on_record`](/parse/options/on_record/) — see [Available Options](/parse/options/#available-options)
1717

18-
Its value is expected to be a function which receives a context rich of information. It gives full control over a field. The [`test/option.cast.coffee`](https://github.com/adaltas/node-csv/blob/master/packages/csv-parse/test/option.cast.coffee) test provides insights on how to use it and its supported functionalities.
18+
The `cast` value is expected to be a function that receives context-rich information. The function has full control over a field. The [`test/option.cast.coffee`](https://github.com/adaltas/node-csv/blob/master/packages/csv-parse/test/option.cast.coffee) test provides insights on how to use it and its supported functionalities.
1919

2020
## Context
2121

22-
The function is called with 2 arguments: the field value and a context object. The context object expose the following properties:
22+
The `cast` function is called with 2 arguments: the field `value` and the `context` object.
2323

24+
The `context` object exposes the following properties:
2425
* `column` (number|string)
25-
The column name if the `columns` options is defined or the field position.
26+
The column name if the `columns` options is defined, or the field position.
2627
* `empty_lines` (number)
2728
Internal counter of empty lines encountered until this field.
2829
* `header` (boolean)
2930
A boolean indicating if the provided value is a part of the header.
3031
* `index` (number)
31-
The field position starting at 0.
32+
The field position within the current record starting at 0.
3233
* `invalid_field_length` (number)
3334
Number of records with a non uniform length when [`relax_column_count`](/parse/options/relax_column_count/) is true. It was named `skipped_lines` until version 3.
3435
* `lines` (number)
@@ -38,15 +39,15 @@ The function is called with 2 arguments: the field value and a context object. T
3839
* `records` (number)
3940
The number of records which have been fully parsed. It was named `count` until version 3.
4041

41-
The [cast example](https://github.com/adaltas/node-csv/blob/master/packages/csv-parse/samples/option.cast.js) uses the context to transform the first filed into a date and replace the second field with the injected context:
42+
The [cast example](https://github.com/adaltas/node-csv/blob/master/packages/csv-parse/samples/option.cast.js) uses the context to transform the first field into a date and replace the second field with the injected context:
4243

4344
`embed:packages/csv-parse/samples/option.cast.js`
4445

4546
## Using the `cast` and `columns` functions conjointly
4647

47-
The `cast` function is called field by field, whether it is considered a header or not. The `columns` function is called once the first record is created (if treated as a header). For this reason, `cast` is executed before `columns`.
48+
The `cast` function is called for each and every field, whether it is considered a header or not. The `columns` function is called once the first record is created (if treated as a header). For this reason, `cast` is executed before `columns`.
4849

49-
To distinguish a header field from a data field in the `cast` function, use the [`context.header` property](https://github.com/adaltas/node-csv/blob/master/packages/csv-parse/samples/option.cast.header.column.fn.js) in the second argument of the `cast` function:
50+
To distinguish a header field from a data field in the `cast` function, use the [`context.header` property](https://github.com/adaltas/node-csv/blob/master/packages/csv-parse/samples/option.cast.header.column.fn.js) from the second argument to the `cast` function:
5051

5152
`embed:packages/csv-parse/samples/option.cast.header.column.fn.js`
5253

0 commit comments

Comments
 (0)