Skip to content

Commit 06b89eb

Browse files
authored
Merge pull request #3 from Space48/feature/add-readme
2 parents 83021cf + f4afd7e commit 06b89eb

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed

README.md

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# @space48/json-pipe
2+
3+
A powerful TypeScript library for building JSON processing pipelines with async iterables. This library makes it easy to create efficient command-line programs that process JSON data through a series of transformations, with support for streaming and backpressure.
4+
5+
## Features
6+
7+
- Process JSON data streams using async iterables
8+
- Rich set of transformation operators:
9+
- `map` and `mapAsync` with configurable concurrency
10+
- `flatMap` and `flatMapAsync` for nested transformations
11+
- `filter` for conditional processing
12+
- `distinct` for deduplication
13+
- `groupBy` and `groupWhile` for data aggregation
14+
- `batch` for processing items in chunks
15+
- `take` and `takeWhile` for limiting output
16+
- `reduce` for aggregating results
17+
- Built-in support for reading/writing JSON Lines format
18+
- Composable transformations using `pipe` and `compose`
19+
- Efficient streaming with backpressure handling
20+
- Written in TypeScript with full type safety
21+
- Node.js 8+ compatible
22+
23+
## Installation
24+
25+
```bash
26+
npm install @space48/json-pipe
27+
```
28+
29+
### Beta Versions
30+
31+
To install the latest beta version:
32+
33+
```bash
34+
npm install @space48/json-pipe@beta
35+
```
36+
37+
Beta versions are automatically published:
38+
- When code is pushed to the `develop` branch (version format: `x.y.z-beta.commit-hash`)
39+
- When a pull request is opened against `master` (version format: `x.y.z-beta.pr.number`)
40+
41+
## Usage
42+
43+
### Basic Example
44+
45+
```typescript
46+
import { pipe, readJsonLinesFrom, writeJsonLinesTo, map } from '@space48/json-pipe';
47+
48+
// Read JSON Lines from stdin, transform them, and write to stdout
49+
await pipe(
50+
readJsonLinesFrom(process.stdin),
51+
map(data => {
52+
// Your transformation logic here
53+
return transformedData;
54+
}),
55+
writeJsonLinesTo(process.stdout)
56+
);
57+
```
58+
59+
### Parallel Processing
60+
61+
```typescript
62+
import { pipe, mapAsync } from '@space48/json-pipe';
63+
64+
// Process items concurrently
65+
const transform = mapAsync(
66+
{ concurrency: 5 }, // Process 5 items at a time
67+
async item => {
68+
// Async transformation logic
69+
return processedItem;
70+
}
71+
);
72+
```
73+
74+
### Data Aggregation
75+
76+
```typescript
77+
import { pipe, groupBy, batch } from '@space48/json-pipe';
78+
79+
// Group items by a key
80+
const groupedTransform = pipe(
81+
input,
82+
groupBy(item => item.category),
83+
// Process in batches of 100
84+
batch(100)
85+
);
86+
```
87+
88+
## API Reference
89+
90+
### Core Functions
91+
92+
- `pipe(...fns)`: Compose multiple transformations
93+
- `compose(...fns)`: Compose functions from right to left
94+
- `map(fn)`: Transform each item
95+
- `mapAsync(options, fn)`: Transform items asynchronously with concurrency control
96+
- `flatMap(fn)`: Transform and flatten results
97+
- `flatMapAsync(options, fn)`: Transform and flatten asynchronously
98+
- `filter(predicate)`: Filter items based on a predicate
99+
- `distinct(compare?)`: Remove duplicates
100+
- `groupBy(getKeyFn)`: Group items by key
101+
- `batch(size)`: Process items in batches
102+
- `take(n)`: Limit number of items
103+
- `reduce(fn, initialValue?)`: Aggregate items
104+
105+
### I/O Functions
106+
107+
- `readJsonLinesFrom(source)`: Read JSON Lines from a readable stream
108+
- `writeJsonLinesTo(destination)`: Write JSON Lines to a writable stream
109+
- `readLinesFrom(source)`: Read lines from a readable stream
110+
111+
## Requirements
112+
113+
- Node.js >= 8
114+
- TypeScript (for development)
115+
116+
## Development
117+
118+
1. Clone the repository:
119+
```bash
120+
git clone https://github.com/Space48/json-pipe.git
121+
```
122+
123+
2. Install dependencies:
124+
```bash
125+
npm install
126+
```
127+
128+
3. Build the project:
129+
```bash
130+
npm run build
131+
```
132+
133+
## License
134+
135+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
136+
137+
## Support
138+
139+
For bug reports and feature requests, please open an issue on the [GitHub repository](https://github.com/Space48/json-pipe/issues).
140+
141+
---
142+
Maintained by [Space48](https://github.com/Space48)

0 commit comments

Comments
 (0)