Skip to content

Commit

Permalink
chore(readme): Updated docs with info about coordination numbers and …
Browse files Browse the repository at this point in the history
…interim numbers.

Updated option to be AllowInterimNumber rather than AllowInterim.

Signed-off-by: Johannes Tegnér <[email protected]>
  • Loading branch information
Johannestegner committed Mar 12, 2023
1 parent 01c5584 commit 98662c0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Personnummer.Tests/InterimNumberTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class InterimNumberTests
{
private Personnummer.Options _opts = new Personnummer.Options()
{
AllowInterim = true,
AllowInterimNumber = true,
};

[Theory]
Expand Down
8 changes: 4 additions & 4 deletions Personnummer/Personnummer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ public struct Options
{
public Options()
{
AllowInterim = false;
AllowInterimNumber = false;
AllowCoordinationNumber = true;
}

public bool AllowCoordinationNumber { get; set; } = true;

public bool AllowInterim { get; set; } = false;
public bool AllowInterimNumber { get; set; } = false;
}

#region Fields and Properties
Expand Down Expand Up @@ -68,7 +68,7 @@ public Personnummer(string ssn, Options? options = null)
}


if (options.Value.AllowInterim == false && Regex.IsMatch(ssn.Trim(), InterimTest))
if (options.Value.AllowInterimNumber == false && Regex.IsMatch(ssn.Trim(), InterimTest))
{
throw new PersonnummerException(
$"{ssn} contains non-integer characters and options are set to not allow interim numbers"
Expand Down Expand Up @@ -139,7 +139,7 @@ public Personnummer(string ssn, Options? options = null)
}

var num = groups["numbers"].Value;
if (options.Value.AllowInterim)
if (options.Value.AllowInterimNumber)
{
num = Regex.Replace(num, InterimTest, "1");
}
Expand Down
21 changes: 21 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,27 @@ using Personnummer;
//=> false
```

### Coordination numbers

The package supports coordination numbers. This feature is enabled by default
and can be disabled by passing an option object to the constructor, parse
or validate function.

```csharp
Personnummer.Parse("193405619996"); // True.
Personnummer.Parse("193405619996", new { AllowCoordinationNumber = true }); // False.
```

### Interim / T -numbers

The package supports interim (aka T) -numbers. This feature is not enabled by
default as they are commonly used, but can be enabled by passing an option object
to the constructor, parse of validate function.

```csharp
Personnummer.Parse("20000101T220", new { AllowInterimNumber = true }); // True.
```

See `Personnummer.Test/PersonnummerTest.cs` for more examples.

## License
Expand Down

0 comments on commit 98662c0

Please sign in to comment.