1 |
|
2 | # Stream transformation for Node.js and the web
|
3 |
|
4 | [![Build Status](https://img.shields.io/github/workflow/status/adaltas/node-csv/Node.js)](https://github.com/adaltas/node-csv/actions)
|
5 | [![NPM](https://img.shields.io/npm/dm/stream-transform)](https://www.npmjs.com/package/stream-transform)
|
6 | [![NPM](https://img.shields.io/npm/v/stream-transform)](https://www.npmjs.com/package/stream-transform)
|
7 |
|
8 | The [`stream-transform` project](https://csv.js.org/transform/) is a simple object transformation framework. It is part of the [CSV project](https://csv.js.org/).
|
9 |
|
10 | The Node.js [`stream.Transform` API](http://nodejs.org/api/stream.html#stream_class_stream_transform) is implemented for scalability. The callback-based and sync APIs are also available for convenience. It is both easy to use and powerful.
|
11 |
|
12 | ## Documentation
|
13 |
|
14 | * [Project homepage](https://csv.js.org/transform/)
|
15 | * [API](https://csv.js.org/transform/api/)
|
16 | * [Options](https://csv.js.org/transform/options/)
|
17 | * [Handler](https://csv.js.org/transform/handler/)
|
18 | * [State properties](https://csv.js.org/transform/state/)
|
19 | * [Examples](https://csv.js.org/transform/examples/)
|
20 |
|
21 | ## Main features
|
22 |
|
23 | * Extends the native Node.js [transform stream API](http://nodejs.org/api/stream.html#stream_class_stream_transform)
|
24 | * Simplicity with the optional callback and sync API
|
25 | * Pipe transformations between readable and writable streams
|
26 | * Synchronous versus asynchronous user functions
|
27 | * Sequential and parallel execution
|
28 | * Accept object, array or JSON as input and output
|
29 | * Sequential or user-defined concurrent execution
|
30 | * Skip and multiply records
|
31 | * Alter or clone input records
|
32 | * MIT License
|
33 |
|
34 | ## Usage
|
35 |
|
36 | Run `npm install csv` to install the full csv module or run `npm install csv-transform` if you are only interested by the CSV stringifier.
|
37 |
|
38 | The module is built on the Node.js Stream API. Use the callback and sync APIs for simplicity or the stream based API for scalability.
|
39 |
|
40 | ## Example
|
41 |
|
42 | The [API](https://csv.js.org/transform/api/) is available in multiple flavors. This example illustrates the sync API.
|
43 |
|
44 | ```js
|
45 | import { transform } from 'stream-transform/sync';
|
46 | import assert from 'assert';
|
47 |
|
48 | const records = transform([
|
49 | [ 'a', 'b', 'c', 'd' ],
|
50 | [ '1', '2', '3', '4' ]
|
51 | ], function(record){
|
52 | record.push(record.shift());
|
53 | return record;
|
54 | });
|
55 |
|
56 | assert.deepEqual(records, [
|
57 | [ 'b', 'c', 'd', 'a' ],
|
58 | [ '2', '3', '4', '1' ]
|
59 | ]);
|
60 | ```
|
61 |
|
62 | ## Development
|
63 |
|
64 | Tests are executed with mocha. To install it, simple run `npm install` followed by `npm test`. It will install mocha and its dependencies in your project "node_modules" directory and run the test suite. The tests run against the CoffeeScript source files.
|
65 |
|
66 | To generate the JavaScript files, run `npm run coffee`.
|
67 |
|
68 | The test suite is run online with [Travis](http://travis-ci.org/wdavidw/node-stream-transform). See the [Travis definition file](https://github.com/adaltas/node-stream-transform/blob/master/.travis.yml) to view the tested Node.js version.
|
69 |
|
70 | ## Contributors
|
71 |
|
72 | The project is sponsored by [Adaltas](https://www.adaltas.com), an Big Data consulting firm based in Paris, France.
|
73 |
|
74 | * David Worms: <https://github.com/wdavidw>
|