#parser #format #validation #cnpj

no-std cnpj-util

Format and validate CNPJ, Brazil companies ID number

5 releases

0.1.4 Oct 1, 2020
0.1.3 Apr 15, 2020
0.1.2 Apr 15, 2020
0.1.1 Apr 15, 2020
0.1.0 Apr 15, 2020

#391 in Parser implementations

MIT/Apache

9KB
137 lines

GitHub Workflow Status Crates.io Crates.io GitHub issues

CNPJ util

CNPJ util inspired in brazilian-utils/cnpj.

Usage

Add the following to your Cargo.toml:

[dependencies]
cnpj_util = "0.1.2"

Examples

Format:

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:

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"));
}

No runtime deps