Sqids

Dosaic.Extensions.Sqids is an extension library that provides methods to convert strings to and from Sqid format using the Sqids library.

Installation

To install the nuget package follow these steps:

dotnet add package Dosaic.Extensions.Sqids

or add as package reference to your .csproj

<PackageReference Include="Dosaic.Extensions.Sqids" Version="" />

Usage

The extension provides simple methods to convert strings to and from Sqid format.

Basic Conversion

Convert a string to a Sqid:

using Dosaic.Extensions.Sqids;

string originalString = "HelloWorld";
string sqidString = originalString.ToSqid();

Convert a Sqid back to the original string:

using Dosaic.Extensions.Sqids;

string sqidString = "kKs7PVdXUYnH"; // Example sqid
string originalString = sqidString.FromSqid();

Custom Encoder

You can also use a custom encoder for special use cases:

Default Configuration

By default, the extension uses the following configuration:

  • Alphabet: "kKsW7PVdXUYnHgQ6rujl0GepfNzB2qZ9bC83IyDmOAtJ4hcSvM1Roaw5LxEiTF"

  • Minimum Length: 10

You can modify the default encoder if needed:

Use Cases

Sqids are useful for:

  • Creating URL-friendly identifiers

  • Obfuscating sequential IDs

  • Generating short, unique string identifiers

Last updated