# Text count

`text-count` · version 1.0.0 · Text · free, no key needed

Count Unicode code points, UTF-16 code units, UTF-8 bytes, and lines.

**Use when you need to: text count · count code points · utf8 byte length.**

## Supported

- text count
- count code points
- utf8 byte length
- count lines

## Not supported

- grapheme clusters
- locale
- word count
- column width

## Behavior

- code_points: number of Unicode code points via for-of over the string (unpaired surrogates count as one each).
- utf16_code_units: text.length.
- utf8_bytes: Buffer.byteLength(text, "utf8").
- Split on CR LF, LF, or CR. Do not treat other Unicode separators as line breaks.
- A trailing terminator does not create an extra empty line.
- Empty document -> zero lines, trailing_terminator false.
- A document that is only a terminator -> one empty line, trailing_terminator true.
- A document with no terminator -> last line kept, trailing_terminator false.
- Preserve empty lines in the middle.
- No locale, no NFC/NFD, no grapheme segmentation.

## Input

- `text` (string, required): max length 256000

## Output

- `code_points` (integer, required)
- `utf16_code_units` (integer, required)
- `utf8_bytes` (integer, required)
- `lines` (integer, required)
- `trailing_terminator` (boolean, required)

## Limits

- max input bytes: 256000
- max lines: 10000

## Example

Request input:

```json
{
  "text": "שלום\n"
}
```

Response:

```json
{
  "result": {
    "code_points": 5,
    "utf16_code_units": 5,
    "utf8_bytes": 9,
    "lines": 1,
    "trailing_terminator": true
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "text-count",
  "version": "1.0.0",
  "input": {
    "text": "שלום\n"
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/text-count/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"text":"שלום\n"}'
```

The machine-readable contract is at [/v1/tools/text-count/versions/1.0.0](/v1/tools/text-count/versions/1.0.0).

### CLI

```sh
node cli.mjs run text-count 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Text lines count](/tools/text-lines-count): Count exact line multiplicities in first-seen order.
- [Text slice codepoints](/tools/text-slice-codepoints): Slice a string by Unicode code-point indexes, not UTF-16 code units.
- [Text diff stats](/tools/text-diff-stats): Summarize a line-record diff as keep, insert, delete, and hunk counts.
- [Text line diff](/tools/text-line-diff): Diff two texts as line records, preserving each line terminator.
- [Text lines chunk](/tools/text-lines-chunk): Split parsed lines into consecutive chunks of size lines each.
- [Text lines difference](/tools/text-lines-difference): Set difference a minus b using exact line equality.
