https://github.com/bombsimon/elixir-personnummer
🔢 Validate Swedish personal identity numbers
https://github.com/bombsimon/elixir-personnummer
elixir personnummer
Last synced: over 1 year ago
JSON representation
🔢 Validate Swedish personal identity numbers
- Host: GitHub
- URL: https://github.com/bombsimon/elixir-personnummer
- Owner: bombsimon
- License: mit
- Created: 2020-04-19T17:39:09.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-15T20:20:17.000Z (over 3 years ago)
- Last Synced: 2025-03-16T01:45:15.691Z (over 1 year ago)
- Topics: elixir, personnummer
- Language: Elixir
- Homepage: https://bombsimon.github.io/elixir-personnummer/
- Size: 81.1 KB
- Stars: 0
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Personnummer
Validate Swedish [personal identity
numbers](https://en.wikipedia.org/wiki/Personal_identity_number_(Sweden)) with
[Elixir](https://elixir-lang.org/).
## Usage
### Just validation
```elixir
iex(1)> Personnummer.valid?("19900101-0017")
true
```
### Validation and additional information
```elixir
iex(1)> {:ok, pnr} = Personnummer.new("19900101-0017")
{:ok,
%Personnummer{
control: 7,
coordination: false,
date: ~D[1990-01-01],
separator: "-",
serial: 1
}}
iex(2)> Personnummer.valid?(pnr)
true
iex(3)> gender = if Personnummer.is_female?(pnr) do "female" else "male" end
"male"
iex(4)> IO.puts "The person with personal identity number #{Personnummer.format(pnr)} is a #{gender} of age #{Personnummer.get_age(pnr)}"
The person with personal identity number 900101-0017 is a male of age 30
:ok
```
## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `personnummer` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:personnummer, "~> 3.0.0"}
]
end
```
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/personnummer](https://hexdocs.pm/personnummer).
## Testing
Use `mix test` to run doctests and unit tests.
## Documentation
Documentation can be found at
[bombsimon.github.io/elixir-personnummer](https://bombsimon.github.io/elixir-personnummer/).
To generate new documentation, run
```sh
mix docs -f html -o docs
```