Skip to content

Commit

Permalink
Let there be light! 💡
Browse files Browse the repository at this point in the history
  • Loading branch information
kutyel committed Jul 18, 2024
0 parents commit 393190e
Show file tree
Hide file tree
Showing 18 changed files with 2,654 additions and 0 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Elm CI

on:
push:
branches:
- "main"
pull_request:

jobs:
main:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Read .nvmrc
run: echo NVMRC=`cat .nvmrc` >> $GITHUB_ENV
- uses: actions/setup-node@v2
with:
node-version: ${{ env.NVMRC }}
cache: yarn

# Re-use node_modules between runs until package.json or yarn.lock changes.
- name: Cache node_modules
id: cache-node_modules
uses: actions/cache@v2
with:
path: node_modules
key: node_modules-${{ hashFiles('package.json', 'yarn.lock') }}

# Re-use ~/.elm between runs until elm.json, elm-tooling.json or
# review/elm.json changes. The Elm compiler saves downloaded Elm packages
# to ~/.elm, and elm-tooling saves downloaded tool executables there.
- name: Cache ~/.elm
uses: actions/cache@v2
with:
path: ~/.elm
key: elm-${{ hashFiles('elm.json', 'elm-tooling.json', 'review/elm.json') }}

# Install tools from elm-tooling.json, unless we restored them from
# cache. yarn.lock and elm-tooling.json can change independently,
# so we need to install separately based on what was restored from cache.
# This is run even if we restored ~/.elm from cache to be 100% sure
# node_modules/.bin/ contains links to all your tools. `elm-tooling
# install` runs very fast when there’s nothing new to download so
# skipping the step doesn’t save much time.
- name: yarn ci install
run: yarn install --immutable --immutable-cache --check-cache

- name: elm make
run: npx --no-install elm make src/Main.elm --output=/dev/null

- name: elm-test
run: yarn test

- name: elm-review
run: yarn review

- name: elm-format
run: npx --no-install elm-format --validate src tests

- name: build
run: npm run build
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
elm-stuff/
node_modules/
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/gallium
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright © 2024 Scrive AB

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Elm Personal Number

[![Elm CI](https://github.com/scrive/elm-personal-number/workflows/Elm%20CI/badge.svg)](https://github.com/scrive/elm-personal-number/actions)

A library for validating personal numbers. Built from the ground up using parser combinators!

## Supported countries

- Swedish personal numbers (personnummer).
- Swedish personal numbers for foreign visitors (sammordningsnummer).
- Norwegian personal numbers (fødselsnummer).
- Finnish personal numbers (henkilötunnus).
- Danish personal numbers (personnummer).

## Example usage

```elm
import PersonalNumber.Swedish as PersonalNumber exposing (ValidationError(..))


personalNumber : String -> String
personalNumber str =
case PersonalNumber.fromString str of
Ok pnr ->
-- The `pnr` is wrapped in a `PersonalNumber` type and is
-- guaranteed to be valid. Use the `display` function to turn
-- it back into a user readable string.
PersonalNumber.display pnr

Err InvalidFormat ->
"Not the correct format for a swedish personal number."

Err InvalidLength ->
"The personal number is not of the correct length."

Err InvalidDate ->
"The first part of the personal number needs to be a valid date."

Err InvalidChecksum ->
"One or more digits in the personal number is wrong."
```

## JSON

```elm
import PersonalNumber.Swedish as PersonalNumber
import Json.Decode as Decode
import Json.Encode as Encode

type alias Person =
{ personalNumber : PersonalNumber.PersonalNumber
}

decoder : Decoder Person
decoder =
Decode.map2 Person
(Decode.field "personal_number" PersonalNumber.decoder)


encode : Person -> Value
encode person =
Encode.object
[ ( "personal_number", PersonalNumber.encode person.personalNumber )
]
```
8 changes: 8 additions & 0 deletions elm-tooling.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"tools": {
"elm": "0.19.1",
"elm-format": "0.8.7",
"elm-json": "0.2.10",
"elm-test-rs": "3.0.0"
}
}
26 changes: 26 additions & 0 deletions elm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"type": "package",
"name": "scrive/elm-personal-number",
"summary": "A library for validating personal numbers",
"license": "MIT",
"version": "1.0.0",
"source-directories": [
"src"
],
"exposed-modules": [
"PersonalNumber.Danish",
"PersonalNumber.Finnish",
"PersonalNumber.Norwegian",
"PersonalNumber.Swedish"
],
"elm-version": "0.19.0 <= v < 0.20.0",
"dependencies": {
"elm/core": "1.0.2 <= v < 2.0.0",
"elm/json": "1.1.2 <= v < 2.0.0",
"elm/parser": "1.1.0 <= v < 2.0.0",
"elmcraft/core-extra": "2.0.0 <= v < 3.0.0"
},
"test-dependencies": {
"elm-explorations/test": "2.0.0 <= v < 3.0.0"
}
}
Loading

0 comments on commit 393190e

Please sign in to comment.