Codez 0.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Codez --version 0.0.1
NuGet\Install-Package Codez -Version 0.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Codez" Version="0.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Codez --version 0.0.1
#r "nuget: Codez, 0.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Codez as a Cake Addin
#addin nuget:?package=Codez&version=0.0.1

// Install Codez as a Cake Tool
#tool nuget:?package=Codez&version=0.0.1

codez

Codez is a library designed to help ease the process of generating codes for your end users that can be helpful for confirmation numbers, reservation systems, error codes, and more.

Getting Started

NuGet Coming Soon...

CodeGenerator

The core of the library is the CodeGenerator class, which has two methods: GenerateAsync and TryGenerateAsync. The CodeGenerator class is made up of several dependencies that can change the behavior of the generate methods:

  • Alphabet (IAlphabet)
  • Randomizer (IRandomizer)
  • Uniqueness (IUniqueness)
  • Stop Words (IStopWords)
  • Options (CodeGeneratorOptions)

Each dependency is explained in detail below. Codez also comes with some defaults out of the box if you don't want to customize anything.

GenerateAsync

The GenerateAsync method returns a code based on the alphabet and the length specified.

var generator = new CodeGenerator();
// returns "]hG/g"
string result = await generator.GenerateAsync(length: 5);

If the generator fails to generate a code, it will throw a CodeGeneratorException.

TryGenerateAsync

The TryGenerateAsync method returns a CodeGeneratorResult that gives you the generated value, and some other metadata from the generation process. This method will not throw a CodeGeneratorException.

var generator = new CodeGenerator();
// returns CodeGeneratorResult
var result = await generator.TryGenerateAsync(length: 5);

if (result.Success) {
    Console.WriteLine(result.Value);
}

Alphabet

The alphabet is an important part of the generation process. You can constrain what kinds of codes get generated by specifying the alphabet appropriately. Codez comes with an AsciiAlphabet by default with characters between ! (33) and ~ (126) included.

You can also use the StringAlphabet class to pass in a string, and each character will be treated as an option during the generation.

var alphabet = new StringAlphabet("ABCDE");
var characters = alphabet.Characters;

You may also implement your own class using the IAlphabet interface.

Randomizer

The IRandomizer interface picks a random index based on your alphabet size. The RandomRandomizer is used by default.

Uniqueness

The IUniqueness interface allows you to enforce global uniquness on the codes that are being generated. This can be against a database, web api, or whatever you would like. By default, Codez provides a NoUniqueness implementation.

Stop Words

StopWords (IStopWords) provides a mechanism to filter out codes that may be deemed inappropriate or incorrect. You can live on the edge by using the default NoStopWords. If you like it boring, you can also use the InMemoryStopWords implementation and provide inappropriate words there, which uses and IndexOf implementation to find matches.

Transformers

The transformer (ITransfomer) interface allows you to take a uniquely generated code and transform it into something else. The transfomer will only run when the result is a Success. Note, The uniqueness of the code coming from a transfomer is not garaunteed.

There is a sample in which this libary is used to generate unique container names.

Options

Options allow you to alter the behavior of the code generation:

  • Retry Limit (default of 5): Number of iterations to attempt generation
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 1,436 12/30/2018
1.0.0 561 12/29/2018
0.0.4 580 12/22/2018
0.0.1 582 12/16/2018