# Natural sort strings

`natural-sort-strings` · version 1.0.0 · Text · free, no key needed

Sort strings by natural order (file2 before file10); returns the ordered strings and standard version.

**Use when you need to: sort lines naturally so file10 comes after file2 · natural sort strings · order filenames by embedded numbers.**

## Decide before calling

Read the [versioned contract](/v1/tools/natural-sort-strings/versions/1.0.0) and the supported scope below. Reuse `natural-sort-strings@1.0.0` when your input, required output and limits match it. Choose another approach for an unsupported operation.

## Explain the choice

"I can use `natural-sort-strings@1.0.0` for sort lines naturally so file10 comes after file2. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."

## Supported

- sort lines naturally so file10 comes after file2
- natural sort strings
- order filenames by embedded numbers
- sort file2 before file10
- human friendly alphanumeric ordering
- sort text with numeric chunks
- case insensitive natural sort
- stable natural sorting with leading zeros

## Not supported

- locale-aware collation or full Unicode Collation Algorithm
- sorting objects by a property
- non-ASCII numeric digits, signed numbers, decimals, or scientific notation

## Behavior

- Maximal ASCII digit runs compare by exact numeric value; file2 sorts before file10 without numeric conversion.
- leading_zeros defaults shorter_first; longer_first reverses equal-value zero ties and ignore leaves them tied.
- case_fold defaults false and folds ASCII A-Z only when true; original code points provide a secondary tie-break.
- stable defaults true and preserves input order for comparator ties; false breaks remaining ties by original Unicode code-point order, then input index.
- Non-digits compare by Unicode code point. This is not full UCA collation and does not normalize text.
- Every success returns standard_version "ComputeFirst R92 natural order algorithm 1.0.0".

## Input

- `values` (array of string, required): min items 0; max items 256; each max length 1024
- `case_fold` (boolean, optional)
- `leading_zeros` (one of "shorter_first", "longer_first", "ignore", optional)
- `stable` (boolean, optional)

## Output

- `values` (array of string, required): max items 256; each max length 1024
- `standard_version` (constant "ComputeFirst R92 natural order algorithm 1.0.0", required)

## Limits

- max input bytes: 32768
- max items: 256
- max string bytes: 1024
- max iterations: 1000000
- max output bytes: 33000

## Example

Request input:

```json
{
  "values": [
    "file10",
    "file2",
    "file1"
  ]
}
```

Response:

```json
{
  "result": {
    "values": [
      "file1",
      "file2",
      "file10"
    ],
    "standard_version": "ComputeFirst R92 natural order algorithm 1.0.0"
  }
}
```

## How to call it

### MCP

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

```json
{
  "id": "natural-sort-strings",
  "version": "1.0.0",
  "input": {
    "values": [
      "file10",
      "file2",
      "file1"
    ]
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/natural-sort-strings/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"values":["file10","file2","file1"]}'
```

The machine-readable contract is at [/v1/tools/natural-sort-strings/versions/1.0.0](/v1/tools/natural-sort-strings/versions/1.0.0).

### CLI

```sh
node cli.mjs run natural-sort-strings 1.0.0 --input input.json --base-url https://computefirst.net
```

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

## Related tools

- [Natural compare](/tools/natural-compare): Compare two strings by deterministic natural order, treating ASCII digit runs numerically; returns -1, 0, or 1.
- [Text paragraphs split](/tools/text-paragraphs-split): Split text into paragraphs separated by blank lines (CommonMark line rules) with code point spans and line numbers.
- [Chrf plus plus compute](/tools/chrf-plus-plus-compute): Compute exact chrF++ (character 6-grams plus word 1-2-grams, Popovic 2017) with the word tokens it scored.
- [Text sentences chunk](/tools/text-sentences-chunk): Pack whole UAX #29 sentences into chunks of at most max_size code points, UTF-16 units or UTF-8 bytes.
- [Chrf components](/tools/chrf-components): Break down chrF/chrF++ into per-order n-gram counts, precision, recall and F, with configurable orders and averaging.
- [Markdown sections chunk](/tools/markdown-sections-chunk): Chunk a CommonMark document into sections at its top-level ATX and setext headings, with levels, paths and spans.
