Sqids

Dosaic.Extensions.Sqids is an extension library that provides string methods to encode and decode values using the Sqidsarrow-up-right algorithm — producing short, YouTube-like identifiers that are URL-safe and reversible.

Installation

dotnet add package Dosaic.Extensions.Sqids

or add as a package reference to your .csproj:

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

Features

  • ToSqid() — encode any string (including Unicode) into a Sqid

  • FromSqid() — decode a Sqid back to the original string (guaranteed round-trip)

  • Default encoder — pre-configured with a shuffled alphabet and minimum length of 10

  • Custom encoder — pass a SqidsEncoder<char> instance to override encoding options per-call

  • Global encoder override — replace the default encoder application-wide via SqidExtensions.Encoder

  • Null safety — both methods throw ArgumentNullException immediately for null inputs

  • Unicode support — encodes and decodes non-ASCII strings (e.g. Chinese, emoji) correctly

Usage

Basic Encoding and Decoding

Round-tripping is guaranteed with the same encoder:

Unicode and Special Characters

Custom Encoder

Supply a SqidsEncoder<char> directly to override options on a per-call basis without affecting the global encoder:

Configuration

The default encoder is a static property and can be replaced application-wide:

Default settings:

Option
Value

Alphabet

kKsW7PVdXUYnHgQ6rujl0GepfNzB2qZ9bC83IyDmOAtJ4hcSvM1Roaw5LxEiTF

MinLength

10

Use Cases

  • Creating short, URL-friendly identifiers from arbitrary strings

  • Obfuscating sequential or predictable IDs in public-facing URLs

  • Generating consistent, reversible short codes for sharing links

Last updated