This library provides nano identifiers, an alternative to UUIDs (inspired by
https://github.com/ai/nanoid).
A nano identifier, or nanoid, is a randomly generated opaque value, suitable
for uniquely identifying database entries, file names, et cetera. Ananoid
(pronounced: "an-an-oyd") is a library for generating such identifiers.
It uses cryptographically secure random number generation, and has no
dependencies beyond the dotnet 6 base class libraries. It has both a high-level
API, and a simpler, more memory-efficient, low-level API.
The latest version of this package can be installed from NuGet via the
following command:
CLI
> dotnet add package pblasucci.ananoid --version 1.1.0
|
The most common use-case for this library is to generate an new identifier,
based on sensible defaults (21 random characters from a URL-safe alphabet
consisting of: letters, numbers, underscore, and/or hyphen). A struct
representing such an identifier can be generated as follows:
F#
open pblasucci.Ananoid
// NOTE type annotations only for demonstration's sake
let nanoId : NanoId = NanoId.ofDefaults ()
printfn $"nano identifier as string: %s{string nanoId}"
printfn $"nano identifier length: %i{nanoId.Length}"
VB
Imports pblasucci.Ananoid
Imports System.Console
' NOTE type annotations only for demonstration's sake
Dim nanoId As NanoId = NanoId.NewId()
WriteLine($"nano identifier as string: {nanoId}")
WriteLine($"nano identifier length: {nanoId.Length}")
|
C#
using pblasucci.Ananoid;
using static System.Console;
// NOTE type annotations only for demonstration's sake
NanoId nanoId = NanoId.NewId();
WriteLine($"nano identifier as string: {nanoId}");
WriteLine($"nano identifier length: {nanoId.Length}");
|
OUT
> dotnet fsi ~/scratches/index.fsx
nano identifier as string: KJzJ41XFLlV-eh-nfxCnA
nano identifier length: 21
|
The library is available under the Mozilla Public License, Version 2.0.
For more information see the project's License file.
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
Multiple items
val string: value: 'T -> string
--------------------
type string = System.String