personnummer_erl

CIcodecovLicense

Validate, parse and format Swedish personal identity numbers (personnummer) in Erlang/OTP. Implements the personnummer specification v3.1.

Supports:

Installation

Once published to Hex, add to rebar.config:

{deps, [{personnummer_erl, "3.1.0"}]}.

Until then, depend on the GitHub source:

{deps, [
    {personnummer_erl,
        {git, "https://github.com/denizdogan/personnummer_erl.git",
            {branch, "main"}}}
]}.

Requires Erlang/OTP 27 or newer.

Quick start

{ok, Pnr} = personnummer:parse(<<"198608134667">>),

true = personnummer:valid(<<"198608134667">>),
<<"860813-4667">> = personnummer:format(Pnr),
<<"198608134667">> = personnummer:format(Pnr, true),
{1986, 8, 13} = personnummer:get_date(Pnr),
19 = personnummer:get_century(Pnr),
<<"466">> = personnummer:get_serial(Pnr),
7 = personnummer:get_check(Pnr),
<<"-">> = personnummer:get_separator(Pnr),
true = personnummer:is_female(Pnr),
false = personnummer:is_coordination_number(Pnr),
false = personnummer:is_interim_number(Pnr).

Options

%% Reject coordination numbers (samordningsnummer).
personnummer:parse(Input, #{allow_coordination_number => false}).

%% Accept interim numbers (T-numbers). Disabled by default.
personnummer:parse(<<"20000101T220">>, #{allow_interim_number => true}).

Defaults: allow_coordination_number => true, allow_interim_number => false.

Compliance

The test suite is driven by JSON fixtures vendored from personnummer/meta. See test/testdata/README.md for refresh instructions.

Development

This project uses Mise for tool versions and task running.

$ mise compile
$ mise test
$ mise format     # apply erlfmt
$ mise check      # fmt-check, eunit, dialyzer
$ mise eq-all     # eqwalizer (requires `elp` on PATH)
$ mise cover      # test coverage report
$ mise docs       # ex_doc

CI runs mise check plus codecov upload on OTP 27 and 28.

Conventions

Releasing

  1. Bump vsn in src/personnummer.app.src and convert the [Unreleased] heading in CHANGELOG.md to the new version. Commit and push.
  2. Run mise check to confirm everything is green.
  3. Run mise publish. This publishes to Hex (requires rebar3 hex user auth once), tags vX.Y.Z, and pushes the tag.

License

MIT