@procedures/json 0.5.0 → 0.7.0

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
@@ -1,5 +1,31 @@
1
1
  # @procedures/json
2
2
 
3
+ ## 0.7.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [841d083]
8
+ - Updated dependencies [389b054]
9
+ - @procedures/client@0.7.0
10
+ - @procedures/compiler@0.7.0
11
+
12
+ ## 0.6.0
13
+
14
+ ### Minor Changes
15
+
16
+ - f3e23e3: New CSV reader and writer (RFC 4180). The functions `parseCsv(text, options)` and `stringifyCsv(rows, options)` and the pure procedures `csv.parse` and `csv.stringify` read and write CSV text.
17
+
18
+ - The parse reads a quoted field with the delimiter, line breaks and doubled quotes (`""`). It reads CRLF, LF and CR, and it removes a byte order mark at the start.
19
+ - The options of the parse are `delimiter`, `header` (an object for each row), `trim` and `skipEmptyLines`.
20
+ - The writer writes arrays or objects. A field gets quotes only when it needs them. Each row ends with CRLF, or with LF when `lineBreak` is `"\n"`.
21
+ - Bad text and bad rows throw a `JsonError` with the new code `INVALID_CSV`.
22
+ - The MCP server of `@procedures/bundle-mcp` does not show the `csv` procedures as tools.
23
+
24
+ ### Patch Changes
25
+
26
+ - @procedures/client@0.6.0
27
+ - @procedures/compiler@0.6.0
28
+
3
29
  ## 0.5.0
4
30
 
5
31
  ### Patch Changes
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  npm install @procedures/json
7
7
  ```
8
8
 
9
- Transforms of JSON values as procedures: a query, a patch, a diff, a merge, a schema check, and YAML to JSON and back. Each procedure is pure. Its output comes only from its input, and it changes nothing.
9
+ Transforms of JSON values as procedures: a query, a patch, a diff, a merge and a schema check. Other procedures change YAML and CSV to JSON and back. Each procedure is pure. Its output comes only from its input, and it changes nothing.
10
10
 
11
11
  ## The procedures
12
12
 
@@ -19,8 +19,10 @@ Transforms of JSON values as procedures: a query, a patch, a diff, a merge, a sc
19
19
  | `json.validate` | It examines a value against a JSON Schema. |
20
20
  | `yaml.parse` | It parses YAML text into a JSON value. |
21
21
  | `yaml.stringify` | It writes a JSON value as YAML text. |
22
+ | `csv.parse` | It parses CSV text into rows: arrays of fields, or objects with a header. |
23
+ | `csv.stringify` | It writes rows as CSV text. |
22
24
 
23
- Each procedure declares `PURE_EFFECTS`, so a read-only host can start it.
25
+ Each procedure declares `PURE_EFFECTS`, so a read-only host can start it. The MCP server of `@procedures/bundle-mcp` does not show the `csv` procedures as tools.
24
26
 
25
27
  ```ts
26
28
  import "@procedures/json/register";
@@ -84,6 +86,42 @@ The check ignores `format` and the other annotations, as the standard tells. The
84
86
  - `yaml.parse` of the text of `yaml.stringify` gives the value again. A property test with random JSON values examines this rule.
85
87
  - A strict YAML 1.1 reader reads a number with an exponent and without a fraction as a string, for example `1e+21`.
86
88
 
89
+ ## CSV
90
+
91
+ The functions `parseCsv(text, options)` and `stringifyCsv(rows, options)` read and write CSV text (RFC 4180). The procedures `csv.parse` and `csv.stringify` use them.
92
+
93
+ ```ts
94
+ import { parseCsv, stringifyCsv } from "@procedures/json";
95
+
96
+ parseCsv('date,note\n2026-10-01,"Shop ""A"", Main St"\n', { header: true });
97
+ // [{ date: "2026-10-01", note: 'Shop "A", Main St' }]
98
+
99
+ stringifyCsv([{ date: "2026-10-01", amount: -4.5 }]);
100
+ // "date,amount\r\n2026-10-01,-4.5\r\n"
101
+ ```
102
+
103
+ The parse:
104
+
105
+ - A field in double quotes can have the delimiter, a line break and a quote. Two quotes (`""`) in the field give one quote.
106
+ - A line break is CRLF, LF or CR. A line break at the end of the text does not start a row.
107
+ - The parse removes a byte order mark at the start of the text.
108
+ - A quote in a field without quotes is a normal character.
109
+ - The parse skips each empty line. With `skipEmptyLines: false`, an empty line gives a row with one empty field.
110
+ - `delimiter` sets the character between two fields, for example `;` or a tab. The default is a comma.
111
+ - With `trim: true`, the parse removes the white space at the start and at the end of each field, also in quotes.
112
+ - With `header: true`, the first row gives the names of the columns, and each other row is an object.
113
+ - A row with fewer fields than the header gets empty text for the missing columns. A row with more fields is an error.
114
+ - A column `__proto__` stays data in the object.
115
+
116
+ The text of `stringifyCsv`:
117
+
118
+ - The rows are all arrays or all objects. A field is a string, a finite number, a boolean or null. Null gives an empty field.
119
+ - A field gets quotes only when it has the delimiter, a quote or a line break.
120
+ - For objects, the first row has the names of the columns. The default columns are the keys, in the order that the rows first give them.
121
+ - `columns` selects the keys and gives their order. For arrays, `columns` is the first row. `header: false` removes the row of names.
122
+ - Each row ends with CRLF, as RFC 4180 tells. `lineBreak: "\n"` writes LF.
123
+ - `parseCsv` of the text gives the rows again, with the same `delimiter`. A property test with random rows examines this rule.
124
+
87
125
  ## Errors
88
126
 
89
127
  Each error is a `JsonError`. A server sends it with its code and its message, and HTTP gives it the status 500. The field `code` tells the kind:
@@ -97,6 +135,7 @@ Each error is a `JsonError`. A server sends it with its code and its message, an
97
135
  | `TEST_FAILED` | A `test` operation found another value. |
98
136
  | `INVALID_YAML` | The YAML text is not correct, or it has a value that JSON does not have. |
99
137
  | `INVALID_SCHEMA` | The schema is not an object or a boolean. |
138
+ | `INVALID_CSV` | The CSV text is not correct, for example a quote without its closing quote. A row, a field or a delimiter of the writer is not correct. The message tells the line or the row. |
100
139
 
101
140
  ## Related packages
102
141