SanderSade.UrlShortener
1.0.0
dotnet add package SanderSade.UrlShortener --version 1.0.0
NuGet\Install-Package SanderSade.UrlShortener -Version 1.0.0
<PackageReference Include="SanderSade.UrlShortener" Version="1.0.0" />
paket add SanderSade.UrlShortener --version 1.0.0
#r "nuget: SanderSade.UrlShortener, 1.0.0"
// Install SanderSade.UrlShortener as a Cake Addin #addin nuget:?package=SanderSade.UrlShortener&version=1.0.0 // Install SanderSade.UrlShortener as a Cake Tool #tool nuget:?package=SanderSade.UrlShortener&version=1.0.0
The main purpose of the UrlShortener is to shorten in the URLs.
Great many sites, such as reddit, TinyUrl, bit.ly, goo.gl, t.co (Twitter) and Flickr, have a short alphanumeric ID (76pb94) instead of a long numeric value (434521912) in the URL. This makes the link shorter, easier for the user to see the differences in the URL - and it simply looks better, too.
There are two ways to achieve this. You can generate a string suitable for display and store it along with ID, or just store the numeric ID and convert the number to a string token and back. UrlShortener is intended to do the latter while giving more control to the developer than other similar libraries.
In addition, as a side-effect of the URL shortening functionality, UrlShortener can convert from any positional mathematical base system to decimal and back.
Features
- Support for full Int64 range
Many URL shortening libraries either support just Int32 values (which a popular website will use up in a few months - or less), or just positive numbers. UrlShortener supports full Int64 range, from -9223372036854775808 to 9223372036854775807. - Full control of the used characters
Most URL shortening libraries allow to use just a fixed set of characters - usually a..z, or 0..z. UrlShortener not only has multiple predefined common character sets, but also lets you to define any characters you want, in any order you want. You can do "012345" as your base or "123qwe" - both are properly handled as base 6. Or, for example, use the reversed decimal base, "9876543210". - Includes common bases/character sets
UrlShortener includes more than 20 of common character sets/bases, including base 36, base64url (RFC4648), multiple variants of base 62, RFC3986-compliant base 65, base 12 (Unicode and non-Unicode versions) and many more - see CharacterSet.cs. - Unicode support
I really don't recommend the use of Unicode for URL shortening, but should you want to use Internationalized Resource Identifiers (RFC3987) or use base 12 Unicode version, UrlShortener supports Unicode characters. - Input validation
There are some libraries that don't validate characters when converting to decimal. Depending on the algorithm used, this may return an invalid base-10 value without any errors. UrlShortener validates the input against your defined character set, and throws ApplicationException() if it contains invalid characters. - Fast
- Converting 10 000 000 decimal items (starting from int.MaxValue, or 2 147 483 647) to base 36 (0..9, a..z) took 00:00:05.9824399, or about 1.7M operations per second.
- Converting 10 000 000 base 36 items to decimal (using resulting values from previous test) took 00:00:05.1318302.
The tests were done on a not-all-that-powerful laptop, and used sequential values, both of which affect the results - but they are a good indicator that performance really isn't something to worry about.
- Sequence functionality
You can declare a starting decimal number in UrlShortener constructor (defaults to 0) and get sequential values in specified base callingNext
. This is fully thread-safe, but the numbers are per UrlShortener instance (the library is intended to be used one-instance-per-base in your application/website).
This should not be considered an alternative for database or other real sequence, but can be useful for unit or integration tests.
UrlShortener also hasCurrent
andPrevious
properties, latter moves the current to previous value, e.g. Current becomes Current - 1. - .NET Standard 2.0
.NET Standard 2.0 means this library can be used with .NET Framework 4.6.1+, .NET Core 2.0 and more - see here for detailed information.
Product | Versions 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. |
-
.NETStandard 2.0
- No dependencies.
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.0 | 30,517 | 10/20/2017 |