Code Monkey home page Code Monkey logo

redskap's Introduction

🇳🇴 Redskap

Currently there's only one utility in the library, IdentificationNumber, which lets you parse, validate and generate Norwegian National Identity Numbers. More utilities are coming!

The library targets .NET Standard 2.0 and .NET 5, which means it's supported on pretty much any .NET platform still supported by Microsoft.

Parsing

The library supports parsing fødselsnummer, D-nummer and H-nummer. This is done through the various overloads of IdentificationNumber.Parse and IdentificationNumber.TryParse. There's also a few overloads of IsValid to validate that a string is a valid identification number (of a specified type). Additionally, there are convenience methods for parsing out date of birth (using TryParseDateOfBirth) and gender (using TryParseGender) directly.

Parsing is built on modern APIs such as ReadOnlySpan<T>, which makes it really fast and completely allocation free. See benchmarks below.

Benchmarks

The results of the IsValidIdentificationNumberBenchmark on .NET 8:

Method Mean Error StdDev Ratio RatioSD Gen0 Allocated Alloc Ratio
Redskap 27.63 ns 0.291 ns 0.272 ns 1.00 0.00 - - NA
Nonin 118.67 ns 1.315 ns 1.098 ns 4.30 0.06 0.0315 264 B NA
NoCommons 265.39 ns 2.474 ns 2.314 ns 9.61 0.15 0.0458 384 B NA
Tedd 1,357.05 ns 11.306 ns 10.023 ns 49.10 0.57 0.2995 2512 B NA
NinEngine 329.70 ns 1.598 ns 1.495 ns 11.93 0.11 0.0153 128 B NA

Generation

The library also supports generating valid fødselsnummer, D-nummer and H-nummer. This is done through the various overloads of IdentificationNumber.Generate. These let you specify kind, gender, date of birth and/or a min- and max date. If you want to control the randomness of the generation, e.g. for unit testing, you can create your own instance of IdentificationNumber.Generator and pass in your own (seeded) Random instance. See this unit test as an example.

Benchmarks

The results of the GenerateIdentificationNumberBenchmark on .NET 8:

Method Mean Error StdDev Ratio RatioSD Gen0 Gen1 Allocated Alloc Ratio
Redskap 140.6 ns 1.02 ns 0.85 ns 1.00 0.00 - - - NA
NoCommons 1,161,481.9 ns 12,681.80 ns 11,862.56 ns 8,275.50 80.83 66.4063 7.8125 566769 B NA
NinEngine 1,632.0 ns 28.36 ns 26.53 ns 11.58 0.19 0.3681 - 3092 B NA

redskap's People

Contributors

khellang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

terjew

redskap's Issues

Adding Swedish social security number

Hi,

Would you be open for adding support for Swedish "personnummer"? I did something similar as a test for parsing IBAN. See here for more information

Edit: Looking more closely I see that there is much more to it than just social security number. Perhaps support for Swedish doesn't belong here but instead a separate package that can hold Finish and Danish as well. Just thinking out loud :)

Best regards
Joakim

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.