Giter Site home page Giter Site logo

hetu's Introduction

HETU validator and generator in Rust

Simple crate for validating and generating Finnish Personal Identity Code (HETU).

Supports the 1.1.2023 format.

Works with rust 1.8 stable.

Usage

Add this to your Cargo.toml

[dependencies.hetu]
git = "https://github.com/jelovirt/hetu.git"

To validate:

extern crate hetu;
use hetu::Ssn;

pub fn main() {
  if Ssn::parse("121212-121D").is_ok() {
    println!("Valid HETU")
  } else {
    println!("Invalid")
  }
}

To generate:

extern crate hetu;
use hetu::Ssn;

pub fn main() {
  println!("{}", Ssn::generate());
}

To generate by pattern:

extern crate hetu;
use hetu::Ssn;
use hetu::SsnPattern;

pub fn main() {
  let pattern = SsnPattern::parse("111111-111?").unwrap();
  println!("{}", Ssn::generate_by_pattern(pattern).unwrap());
}

CLI

Command line tool hetu can be used to either validate or randomly generate identifiers.

To validate:

$ hetu 121212-121D
$ echo 121212-121D | hetu -
$ hetu 121212-121C
Error: Invalid checksum: expected D
  
  121212-121C
            ^

To generate:

$ hetu
121212-121D

To generate by pattern that can contain wildcards:

$ hetu -p "121212-121?"
121212-121D
$ hetu -p "121212-???D"
121212-028D
$ hetu -p "??????-???D"
241151-028D

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.