# Text operations

Text operations accept UTF-8 strings and return deterministic results. Line-oriented modes normalize CRLF to LF. String and serialized-array output is capped at 1 MiB; the 50,000 limit applies only where lines or split parts are actually materialized, as noted below.

## Clean text

Call `POST /v1/text/clean` with `input` and one mode:

- `trim-lines`: trim each line, remove empty lines, and join with LF; input is limited to 50,000 lines.
- `collapse-whitespace`: collapse horizontal spaces and tabs, and cap consecutive line breaks at two.
- `lowercase`: apply Unicode-aware lowercase conversion.

## Deduplicate, sort, and diff lines

- Call `POST /v1/text/unique-sort` with `mode: "unique" | "asc" | "desc"`. `unique` preserves first occurrence order; sorted modes use Unicode code point order. Read `result` and `lineCount`.
- Call `POST /v1/text/diff` with `left` and `right`. The response compares unique line sets and returns `equal`, `onlyLeft`, and `onlyRight` in first-seen order.

Unique/sort input and each diff input are limited to 50,000 lines.

## Split and merge

Call `POST /v1/text/split` in one of two forms:

```json
{"input":"a,b,c","mode":"delimiter","delimiter":","}
```

```json
{"input":"A😀B","mode":"length","length":2}
```

The delimiter must be non-empty. Both modes return at most 50,000 parts. Length mode counts Unicode code points, not UTF-16 code units, and `length` must be an integer from 1 through 50,000. Read `parts`, `count`, and `mode`.

Call `POST /v1/text/merge` with `left`, `right`, optional `separator`, and `mode: "line" | "append"`. Line mode joins corresponding lines, fills a missing side with an empty string, and limits each input to 50,000 lines. Append mode returns `left + separator + right` without applying the line-count limit.

## Reverse and count

- Call `POST /v1/text/reverse` with `mode: "characters" | "lines" | "words"`. Character mode reverses Unicode code points; line mode accepts at most 50,000 lines; word mode reverses whitespace-delimited segments while preserving their contents.
- Call `POST /v1/text/count` to return Unicode code points, non-whitespace characters, CJK unified ideographs, English words, lines, and UTF-8 bytes. Counting is limited to 50,000 lines because it materializes normalized lines.

## Convert case

Call `POST /v1/text/case` with `mode: "upper" | "lower" | "camel" | "snake" | "kebab" | "title"`.

Upper and lower modes transform the original text. Composed modes tokenize ASCII letters and digits, normalize tokens to lowercase, and then compose them. Do not imply locale-specific title-casing.
