dni 0.1.0

Validate Spanish DNI and NIE identification numbers. A faithful port of the python-stdnum algorithms. Zero deps, no_std.
Documentation
# dni

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

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

**Validate Spanish DNI and NIE identification numbers.**

- **DNI** (*Documento Nacional de Identidad*) — 8 digits + a check letter.
- **NIE** (*Número de Identidad de Extranjero*) — `X`/`Y`/`Z` + 7 digits + a check letter.

A faithful Rust port of the algorithms used by
[`python-stdnum`](https://arthurdejong.org/python-stdnum/).

- **Zero dependencies**, **`#![no_std]`**
- `is_valid`, `validate`, `calc_check_digit`, `compact` for both DNI and NIE
- Accepts `-`/space separators and lower-case input
- Differential-tested against `python-stdnum` (60k cases)

## Install

```toml
[dependencies]
dni = "0.1"
```

## Usage

```rust
use dni::{is_valid, validate, calc_check_digit};

// DNI:
assert!(is_valid("12345678Z"));
assert!(!is_valid("12345678A"));         // wrong check letter
assert_eq!(validate("12345678-z").unwrap(), "12345678Z");
assert_eq!(calc_check_digit("12345678").unwrap(), 'Z');

// NIE:
assert!(dni::nie::is_valid("X1234567L"));
assert_eq!(dni::nie::validate("x-2482300-w").unwrap(), "X2482300W");
```

The check letter is `"TRWAGMYFPDXBNJZSQVHLCKE"[number % 23]`; for a NIE the leading `X`/`Y`/`Z`
is first replaced with `0`/`1`/`2`.

## 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.