Skip to content

Commit 0f24994

Browse files
committed
Added documentation about transform utilities
1 parent 2fb2c85 commit 0f24994

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

packages/utils/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,25 @@ setUser(p => update(p, "street", "number", 64));
9696
- **`power`** - `a ** b ** c ** ...`
9797
- **`clamp`** - clamp a number value between two other values
9898

99+
## String transforms
100+
101+
`(string) => T` transform functions for converting raw string data into typed values. Useful as the `transform` option for SSE, WebSocket, and similar streaming primitives.
102+
103+
```ts
104+
import { json, ndjson, safe } from "@solid-primitives/utils";
105+
106+
const { data } = createSSE<Event>(url, { transform: json });
107+
const { data } = createSSE<Event[]>(url, { transform: ndjson });
108+
const { data } = createSSE<Event>(url, { transform: safe(json) });
109+
```
110+
111+
- **`json`** - Parse a string as a single JSON value
112+
- **`ndjson`** - Parse newline-delimited JSON (NDJSON / JSON Lines) into an array
113+
- **`lines`** - Split a string into a `string[]` by newline, filtering empty lines
114+
- **`number`** - Parse a string as a number via `Number()`
115+
- **`safe(transform, fallback?)`** - Wrap any transform in a `try/catch`; returns `fallback` instead of throwing
116+
- **`pipe(a, b)`** - Compose two transforms into one
117+
99118
## Changelog
100119

101120
See [CHANGELOG.md](./CHANGELOG.md)

0 commit comments

Comments
 (0)