Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/rodolfoghi/cnpj-util-rust

A library focused on solving a common problems that we face daily in the development of applications using CNPJ (Brazil companies ID number).
https://github.com/rodolfoghi/cnpj-util-rust

Last synced: about 1 month ago
JSON representation

A library focused on solving a common problems that we face daily in the development of applications using CNPJ (Brazil companies ID number).

Awesome Lists containing this project

README

        

![GitHub Workflow Status](https://img.shields.io/github/workflow/status/rodolfoghi/cnpj-util-rust/Rust) ![Crates.io](https://img.shields.io/crates/v/cnpj-util) ![Crates.io](https://img.shields.io/crates/d/cnpj-util) ![GitHub issues](https://img.shields.io/github/issues/rodolfoghi/cnpj-util-rust)

# CNPJ util

CNPJ util inspired in [brazilian-utils/cnpj](https://github.com/brazilian-utils/brazilian-utils/blob/master/src/utilities/cnpj/index.ts).

## Usage

Add the following to your `Cargo.toml`:
```rust
[dependencies]
cnpj_util = "0.1.2"
```

## Examples

### Format:
```rust
use cnpj_util as cnpj;

fn main() {
println!("{}", cnpj::format("46843485000186")); // 46.843.485/0001-86
println!("{}", cnpj::format("468434850001860000000000")); // 46.843.485/0001-86
println!("{}", cnpj::format("46.?ABC843.485/0001-86abc")); // 46.843.485/0001-86
}
```

### Validate:
```rust
use cnpj_util as cnpj;

fn main() {
assert_eq!(false, is_valid("12312312312"));
assert_eq!(false, is_valid("6ad0.t391.9asd47/0ad001-00"));
assert_eq!(true, is_valid("13723705000189"));
assert_eq!(true, is_valid("60.391.947/0001-00"));
}
```