string
String manipulation streams — split, replace, count, and measure text data.
Install
npm install @datastream/string stringReadableStream Readable
Creates a Readable stream from a string input.
import { stringReadableStream } from '@datastream/string'
const stream = stringReadableStream('hello world') stringLengthStream PassThrough
Counts the total character length of all chunks.
Options
| Option | Type | Default | Description |
|---|---|---|---|
resultKey | string | "length" | Key in pipeline result |
Example
import { pipeline, createReadableStream } from '@datastream/core'
import { stringLengthStream } from '@datastream/string'
const length = stringLengthStream()
const result = await pipeline([
createReadableStream('hello world'),
length,
])
console.log(result)
// { length: 11 } stringCountStream PassThrough
Counts occurrences of a substring across all chunks.
Options
| Option | Type | Default | Description |
|---|---|---|---|
substr | string | — | Substring to count |
resultKey | string | "count" | Key in pipeline result |
Example
import { pipeline, createReadableStream } from '@datastream/core'
import { stringCountStream } from '@datastream/string'
const count = stringCountStream({ substr: '\n' })
const result = await pipeline([
createReadableStream('line1\nline2\nline3'),
count,
])
console.log(result)
// { count: 2 } stringSplitStream Transform
Splits streaming text by a separator, emitting one chunk per segment. Handles splits that cross chunk boundaries.
Options
| Option | Type | Default | Description |
|---|---|---|---|
separator | string | — | String to split on |
Example
import { pipeline, createReadableStream, streamToArray, pipejoin } from '@datastream/core'
import { stringSplitStream } from '@datastream/string'
const river = pipejoin([
createReadableStream('alice,bob,charlie'),
stringSplitStream({ separator: ',' }),
])
const output = await streamToArray(river)
// ['alice', 'bob', 'charlie'] stringReplaceStream Transform
Replaces pattern matches in streaming text. Handles replacements that span chunk boundaries.
Options
| Option | Type | Default | Description |
|---|---|---|---|
pattern | string \| RegExp | — | Pattern to search for |
replacement | string | — | Replacement string |
Example
import { stringReplaceStream } from '@datastream/string'
stringReplaceStream({ pattern: /\t/g, replacement: ',' }) stringMinimumFirstChunkSize Transform
Buffers data until the first chunk meets a minimum size, then passes all subsequent chunks through unchanged.
Options
| Option | Type | Default | Description |
|---|---|---|---|
chunkSize | number | 1024 | Minimum first chunk size in characters |
stringMinimumChunkSize Transform
Buffers data until chunks meet a minimum size before emitting. Useful when downstream requires a minimum data size for processing.
Options
| Option | Type | Default | Description |
|---|---|---|---|
chunkSize | number | 1024 | Minimum chunk size in characters |
stringSkipConsecutiveDuplicates Transform
Skips consecutive duplicate string chunks.
import { stringSkipConsecutiveDuplicates } from '@datastream/string'
// Input chunks: 'a', 'a', 'b', 'a' → Output: 'a', 'b', 'a'