ClearTools 3.0.9
dotnet add package ClearTools --version 3.0.9
NuGet\Install-Package ClearTools -Version 3.0.9
<PackageReference Include="ClearTools" Version="3.0.9" />
<PackageVersion Include="ClearTools" Version="3.0.9" />
<PackageReference Include="ClearTools" />
paket add ClearTools --version 3.0.9
#r "nuget: ClearTools, 3.0.9"
#:package ClearTools@3.0.9
#addin nuget:?package=ClearTools&version=3.0.9
#tool nuget:?package=ClearTools&version=3.0.9
ClearTools
A comprehensive .NET Standard 2.1 utility library providing robust, production-ready tools for common development tasks. ClearTools offers utilities for string manipulation, cryptography, image processing, Azure services integration, HTTP client operations, and much more.
🚀 Quick Start
Installation
dotnet add package ClearTools
Basic Usage
using ClearTools.Extensions;
using Clear.Tools;
// String extensions
string text = "Hello 123 World!";
int number = text.ToInt32(); // Extracts numbers: 123
string cleaned = StringUtility.StripSymbols(text); // Removes symbols, preserves spaces: "Hello 123 World"
// Image processing
var scaledImage = ImageUtility.ScaleImage(originalImage, 800, 600);
// Cryptography
string salt = Crypto.CreateSalt();
string hash = Crypto.EncodeSHA256("password", salt);
// OTP generation
var otpResult = OtpUtility.GenerateCode("user@example.com", 12345, TimeSpan.FromMinutes(5));
📋 Table of Contents
- Core Utilities
- Extension Methods
- Azure Integration
- HTTP Client
- Middleware
- Data Models
- Installation & Setup
- Examples
- Documentation
- Contributing
- License
🔧 Core Utilities
String Utilities (StringUtility
)
Comprehensive string manipulation and processing tools:
// URL and SEO-friendly string generation
string urlKey = StringUtility.GenerateUrlKey("My Blog Post Title!"); // "my-blog-post-title"
// HTML and symbol stripping
string cleanText = StringUtility.StripHTML("<p>Hello <b>World</b></p>"); // "Hello World"
string alphanumeric = StringUtility.StripSymbols("Hello @World! 123"); // "Hello World 123"
// Date-based unique identifiers
string dateCode = StringUtility.GetDateCode(); // File time-based code
string updateId = StringUtility.AddUpDate(); // Timestamp-based ID
// Tag generation
string tags = StringUtility.GenerateTags("tag1", "tag2", "tag3"); // "tag1,tag2,tag3"
Image Processing (ImageUtility
)
Advanced image manipulation capabilities:
// Image scaling with aspect ratio preservation
Image scaledImage = ImageUtility.ScaleImage(sourceImage, 800, 600, ImageSizePreference.Width);
// Image cropping and resizing
Image croppedImage = ImageUtility.CropImage(sourceBitmap, 300, 300);
Bitmap resizedImage = ImageUtility.ResizeImage(sourceImage, 400, 300);
// Format conversion
byte[] imageBytes = ImageUtility.ConvertBitmapToBytes(bitmap, ImageFormat.Jpeg);
string base64Image = ImageUtility.ConvertImageToBase64(image, ImageFormat.Png);
// High-quality JPEG saving
ImageUtility.SaveJpegToFile("output.jpg", image, quality: 85);
Cryptography & Security
Encryption (Encryption
)
string key = "MySecretEncryptionKeyThatIsLongEnough123"; // 32+ chars required
string encrypted = Encryption.Encrypt("sensitive data", key);
string decrypted = Encryption.Decrypt(encrypted, key);
Cryptography (Crypto
)
// Hashing algorithms
string salt = Crypto.CreateSalt(128);
string sha256Hash = Crypto.EncodeSHA256("password", salt);
string sha512Hash = Crypto.EncodeSHA512("password", salt);
string sha1Hash = Crypto.EncodeSHA1("password");
// Base64 encoding/decoding
string encoded = Crypto.EncodeBase64("text to encode");
string decoded = Crypto.DecodeBase64(encoded);
OTP (One-Time Password) Utilities (OtpUtility
)
// Generate OTP with custom expiry
var otpResult = OtpUtility.GenerateCode("user@example.com", 12345, TimeSpan.FromMinutes(5));
Console.WriteLine($"Code: {otpResult.Code}, Expires: {otpResult.ExpiryTime}");
// Validate OTP
bool isValid = OtpUtility.ValidateCode("user@example.com", 12345, "123456", otpResult.ExpiryTime);
Number Base Conversion (BaseConverter
)
Convert numbers between different bases and formats:
// Convert from any base to decimal
long decimal = BaseConverter.ConvertToDecimal("1010", 2); // Binary to decimal: 10
long hexDecimal = BaseConverter.ConvertToDecimal("FF", 16); // Hex to decimal: 255
// Convert decimal to any base
string binary = BaseConverter.ConvertFromDecimal(10, 2); // "1010"
string hex = BaseConverter.ConvertFromDecimal(255, 16); // "FF"
// Convert to alphabetic representation
string alpha = BaseConverter.ConvertToAlpha(26); // "BA"
EditorJS Integration (EditorJS
)
Parse and convert EditorJS content to HTML:
// Parse EditorJS JSON to HTML
string html = EditorJS.Parse(editorJsJsonString);
// Supports: headers, paragraphs, lists, images, embeds (YouTube, Vimeo)
🔌 Extension Methods
String Extensions (StringExtensions
)
Powerful string manipulation extensions:
// Value toggling
string toggled = "active".Toggle("inactive"); // "inactive"
// Case-insensitive operations
bool contains = "Hello World".Search("WORLD"); // true
bool equals = "Hello".EqualsNoCase("HELLO"); // true
// Number and symbol extraction
string numbers = "abc123def456".ExtractNumbers(); // "123456"
string clean = "Hello;World*".StripSymbols(); // "HelloWorld" (removes specific symbols)
// Type conversions
int number = "abc123".ToInt32(); // 123
decimal price = "Price: $29.99".ToDecimal(); // 29.99
// CSV processing
List<string> items = "apple,banana,cherry".ToListFromCsv();
HashSet<string> uniqueItems = "apple,banana,apple".ToHashSetFromCsv();
DateTime Extensions (DateTimeExtensions
)
Enhanced DateTime formatting:
DateTime now = DateTime.Now;
string dateStr = now.ToDateString(); // "15/Aug/2025"
string dateTimeStr = now.ToDateTimeString(); // "15/Aug/2025 14:30:15"
☁️ Azure Integration
Key Vault Integration (KeyVaultExtensions
)
Robust Azure Key Vault integration for configuration management:
// Define your settings class
public class AppSettings
{
public string DatabaseConnectionString { get; set; }
[KeyVaultKey("api-key")]
public string ApiKey { get; set; }
}
// For ASP.NET Web Applications
var builder = WebApplication.CreateBuilder(args);
builder.AddKeyVaultForWebApplication<AppSettings>(
keyVaultUri: "https://your-keyvault.vault.azure.net/",
out AppSettings settings
);
// For Azure Functions
hostBuilder.AddKeyVaultForAzureFunctions<AppSettings>(
keyVaultUri: "https://your-keyvault.vault.azure.net/",
out AppSettings functionSettings
);
Azure Storage (AzureStorageManager
)
Azure Blob Storage operations:
string connectionString = "DefaultEndpointsProtocol=https;AccountName=...";
// Upload operations
AzureStorageManager.UploadToAzure(connectionString, "container", stream, "application/pdf", "file.pdf", "folder");
// Download operations
AzureStorageManager.DownloadFromAzure(connectionString, "container", fileInfo, "folder");
// Check folder existence
bool exists = AzureStorageManager.AzureFolderExists(connectionString, "container", "folder");
Service Collection Extensions (ServicesExtensions
)
Automatic service registration by interface:
// Register all services implementing IService
services.AddScopedServicesByInterface<IService>();
services.AddSingletonServicesByInterface<IRepository>();
services.AddTransientServicesByInterface<IValidator>();
🌐 HTTP Client
API Client (ApiClient
)
Comprehensive HTTP client with built-in error handling and serialization:
// Initialize
var apiClient = new ApiClient(httpClient);
// GET with various options
var user = await apiClient.GetAsync<User>("https://api.example.com/users/1");
var userWithAuth = await apiClient.GetAsync<User>("https://api.example.com/users/1", bearerToken);
// POST operations
var response = await apiClient.PostAsync("https://api.example.com/users", newUser);
var createdUser = await apiClient.PostAsync<User, User>("https://api.example.com/users", newUser);
// reCAPTCHA validation
var captchaResult = await apiClient.ValidateGoogleCaptcharAsync(secretKey, response, remoteIp);
🛡️ Middleware
Request Validation Middleware (RequestValidationMiddleware
)
ASP.NET Core middleware for API key validation:
// Setup
services.AddRequestValidation("your_secret_api_key", skipForDevelopment: true);
app.UseRequestValidation();
// Client usage - include key in headers
client.DefaultRequestHeaders.Add("key", "your_secret_api_key");
📊 Data Models
ValidationCodeResult
: OTP generation results with code and expiryCaptcherResponse
: Google reCAPTCHA validation response- EditorJS Models: Complete data structures for EditorJS content parsing
- Smart Enums: Type-safe enumeration base classes
📦 Installation & Setup
Package Installation
# Via .NET CLI
dotnet add package ClearTools
# Via PackageReference
<PackageReference Include="ClearTools" Version="3.0.9" />
Dependencies
ClearTools targets .NET Standard 2.1 and includes:
- Azure.Storage.Blobs (12.25.0)
- Azure.Security.KeyVault.Secrets (4.8.0)
- Newtonsoft.Json (13.0.3)
- System.Drawing.Common (9.0.8)
- Microsoft.AspNetCore.Http.Abstractions (2.3.0)
📖 Examples
Complete Image Processing Pipeline
public class ImageProcessor
{
public async Task<string> ProcessAndUploadImage(IFormFile file)
{
using var stream = file.OpenReadStream();
var image = Image.FromStream(stream);
// Process image
var scaledImage = ImageUtility.ScaleImage(image, 800, 600);
var imageBytes = ImageUtility.ConvertBitmapToBytes((Bitmap)scaledImage, ImageFormat.Jpeg);
// Generate unique filename
var fileName = StringUtility.GenerateFileName(file.FileName, "jpg");
// Upload to Azure
using var uploadStream = new MemoryStream(imageBytes);
AzureStorageManager.UploadToAzure(connectionString, "images", uploadStream, "image/jpeg", fileName, "uploads");
return fileName;
}
}
OTP Service Implementation
public class OtpService
{
private readonly int _secretKey = 123456;
public ValidationCodeResult GenerateOtp(string email)
{
return OtpUtility.GenerateCode(email, _secretKey, TimeSpan.FromMinutes(5));
}
public bool ValidateOtp(string email, string code, DateTime expiry)
{
return OtpUtility.ValidateCode(email, _secretKey, code, expiry);
}
}
📚 Documentation
For comprehensive documentation covering all methods and use cases, see:
- Complete Usage Guide - Detailed documentation with examples for every class and method
- API Reference - Complete API documentation
- Changelog - Version history and changes
🏷️ Features Summary
✅ String Utilities: URL generation, HTML stripping, text processing
✅ Image Processing: Scaling, cropping, format conversion, quality optimization
✅ Cryptography: Hashing, encryption, salt generation, secure tokens
✅ OTP Management: Generation, validation, expiry handling
✅ Azure Integration: Key Vault, Blob Storage, managed identity support
✅ HTTP Client: RESTful API client with authentication and serialization
✅ Extensions: String, DateTime, Byte array, and service collection extensions
✅ Middleware: Request validation, API key authentication
✅ EditorJS: Content parsing and HTML conversion
✅ Base Conversion: Number base conversion utilities
✅ File Management: File I/O operations and utilities
🤝 Contributing
We welcome contributions! Please see our Contributing Guidelines for details.
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
📞 Support
- Issues: GitHub Issues
- NuGet Package: ClearTools on NuGet
- Documentation: Complete Usage Guide
ClearTools - Making .NET development clearer, one utility at a time. 🚀
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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | 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.1
- Azure.Extensions.AspNetCore.Configuration.Secrets (>= 1.4.0)
- Azure.Identity (>= 1.15.0)
- Azure.Security.KeyVault.Secrets (>= 4.8.0)
- Azure.Storage.Blobs (>= 12.25.0)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.3.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.8)
- Microsoft.Extensions.Hosting (>= 9.0.8)
- Newtonsoft.Json (>= 13.0.3)
- System.Drawing.Common (>= 9.0.8)
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 |
---|---|---|
3.0.9 | 98 | 8/21/2025 |
3.0.7 | 234 | 7/3/2025 |
3.0.7-preview1 | 143 | 7/3/2025 |
3.0.6 | 144 | 6/30/2025 |
3.0.5 | 165 | 6/26/2025 |
3.0.5-preview1 | 305 | 6/10/2025 |
3.0.4 | 302 | 3/28/2025 |
3.0.2 | 145 | 2/20/2025 |
3.0.1 | 114 | 2/13/2025 |
3.0.0 | 150 | 12/19/2024 |
2.1.23-preview5 | 140 | 12/10/2024 |
2.1.23-preview3 | 105 | 10/23/2024 |
2.1.23-preview2 | 138 | 9/18/2024 |
2.1.23-preview1 | 129 | 7/5/2024 |
2.1.22 | 194 | 2/2/2024 |
2.1.22-preview1 | 101 | 7/5/2024 |
2.1.21 | 129 | 2/1/2024 |
2.1.20 | 535 | 7/25/2022 |
2.1.19 | 516 | 7/17/2022 |
2.1.18 | 544 | 7/17/2022 |
2.1.17 | 479 | 8/24/2021 |
2.1.16 | 478 | 7/3/2021 |
2.1.15 | 501 | 7/2/2021 |
2.1.14 | 477 | 6/12/2021 |
2.1.13 | 470 | 4/6/2021 |
2.1.12 | 630 | 6/19/2020 |
2.1.11 | 634 | 6/18/2020 |
2.1.10 | 583 | 6/18/2020 |
2.1.9 | 600 | 6/18/2020 |
2.1.8 | 667 | 11/15/2019 |
2.1.7 | 650 | 9/11/2019 |
2.1.6 | 702 | 7/24/2019 |
2.1.5 | 677 | 7/17/2019 |
2.1.4 | 700 | 7/17/2019 |
2.1.3 | 690 | 7/17/2019 |
2.1.2 | 676 | 7/16/2019 |
2.1.1 | 859 | 1/11/2019 |
1.0.0 | 835 | 12/29/2018 |