parse-numeric-range 0.1.0

Parse a string of numbers and ranges (e.g. 1,3-5,8) into a list of integers. A faithful port of the parse-numeric-range npm package. Zero dependencies, no_std.
Documentation
# parse-numeric-range

[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors-)

[![crates.io](https://img.shields.io/crates/v/parse-numeric-range.svg)](https://crates.io/crates/parse-numeric-range)
[![docs.rs](https://docs.rs/parse-numeric-range/badge.svg)](https://docs.rs/parse-numeric-range)
[![CI](https://github.com/trananhtung/parse-numeric-range/actions/workflows/ci.yml/badge.svg)](https://github.com/trananhtung/parse-numeric-range/actions/workflows/ci.yml)
[![license](https://img.shields.io/crates/l/parse-numeric-range.svg)](#license)

**Parse a string of numbers and ranges into a list of integers.**

`"1,3-5,8"` → `[1, 3, 4, 5, 8]`. A faithful Rust port of the
[`parse-numeric-range`](https://www.npmjs.com/package/parse-numeric-range) npm package
(used by syntax highlighters for line-range selection).

- **Zero dependencies**, **`#![no_std]`**
- Inclusive (`-`, `..`, ``) and exclusive (`...`, ``, ``) ranges
- Negative numbers and descending ranges
- Differential-tested against the reference `parse-numeric-range` implementation

## Install

```toml
[dependencies]
parse-numeric-range = "0.1"
```

## Usage

```rust
use parse_numeric_range::parse;

assert_eq!(parse("1,3-5,8"), [1, 3, 4, 5, 8]);
assert_eq!(parse("1-3,7,9-11"), [1, 2, 3, 7, 9, 10, 11]);
assert_eq!(parse("5-1"), [5, 4, 3, 2, 1]);       // descending
assert_eq!(parse("-5--2"), [-5, -4, -3, -2]);    // negatives
assert_eq!(parse("1...5"), [1, 2, 3, 4]);        // exclusive
assert_eq!(parse("nope"), [] as [i64; 0]);       // junk is ignored
```

## Separators

| Separator        | Meaning              | Example  | Result        |
| ---------------- | -------------------- | -------- | ------------- |
| `-`, `..`, ``   | inclusive of the end | `1-3`    | `[1, 2, 3]`   |
| `...`, ``, ``  | exclusive of the end | `1...3`  | `[1, 2]`      |

Whitespace around each comma-separated entry is trimmed; unrecognized entries are ignored,
and duplicates are kept (no deduplication). Numbers are parsed as `i64`. Like the reference,
ranges are fully expanded, so a very large range allocates one entry per value.

## Contributors ✨

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind are welcome — code, docs, bug reports, ideas, reviews! See the [emoji key](https://allcontributors.org/docs/en/emoji-key) for how each contribution is recognized, and open a PR or issue to get involved.

Thanks goes to these wonderful people:

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
  <tbody>
    <tr>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/trananhtung"><img src="https://avatars.githubusercontent.com/u/30992229?v=4?s=100" width="100px;" alt="Tung Tran"/><br /><sub><b>Tung Tran</b></sub></a><br /><a href="https://github.com/trananhtung/./commits?author=trananhtung" title="Code">💻</a> <a href="#maintenance-trananhtung" title="Maintenance">🚧</a></td>
    </tr>
  </tbody>
</table>

<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->

<!-- ALL-CONTRIBUTORS-LIST:END -->

## License

Licensed under either of [MIT](LICENSE-MIT) or [Apache-2.0](LICENSE-APACHE) at your option.