Skip to content
/ hetu Public

Robust parsing for finnish national identification number "henkilötunnus"

License

Notifications You must be signed in to change notification settings

je-l/hetu

Repository files navigation

Parsing and validation for finnish national identification number

API reference available in Pursuit: https://pursuit.purescript.org/packages/purescript-hetu

Personal identity code - Digi- ja väestötietovirasto

This library aims to provide a reliable way to deserialize all valid hetus. Also temporary hetus (id number >= 900) are supported.

> import Hetu
> import Data.Functor
> hetu = parseHetu "260993-5658"
> hetu
(Right { birthday: (Date (Year 1993) September (Day 26)), id: 565 })

> map gender hetu
(Right Male)

> map formatHetu hetu
(Right "260993-5658")

Detailed error messages are provided with exact reason why the hetu is not valid:

> parseHetu "280264-051E"
(Left "Invalid checksum at column 12")

> parseHetu "a60993-5658"
(Left "Expected digit at column 1")

> parseHetu "131052B308T"
(Left "Invalid century: \"B\" at column 8")

Development

Install spago and run spago test

Related projects

About

Robust parsing for finnish national identification number "henkilötunnus"

Resources

License

Stars

Watchers

Forks

Packages

No packages published