OneCleek.SkyHelpers
1.0.6
dotnet add package OneCleek.SkyHelpers --version 1.0.6
NuGet\Install-Package OneCleek.SkyHelpers -Version 1.0.6
<PackageReference Include="OneCleek.SkyHelpers" Version="1.0.6" />
<PackageVersion Include="OneCleek.SkyHelpers" Version="1.0.6" />
<PackageReference Include="OneCleek.SkyHelpers" />
paket add OneCleek.SkyHelpers --version 1.0.6
#r "nuget: OneCleek.SkyHelpers, 1.0.6"
#:package OneCleek.SkyHelpers@1.0.6
#addin nuget:?package=OneCleek.SkyHelpers&version=1.0.6
#tool nuget:?package=OneCleek.SkyHelpers&version=1.0.6
SkyHelpers
A collection of useful C# helpers and extensions for ** .NET 10.0 ** applications.
Platform Requirements
- Target Framework: .NET 10.0
Helpers
DateHelper
A utility class for friendly date formatting and Hijri date conversion.
Features
- Relative Time: Converts
DateTimeto human-readable strings (e.g., "just now", "5 minutes ago", "in 2 days"). - Hijri Date: Converts Gregorian dates to Hijri dates with support for adjustment and localized month names.
- Localization: Supports English, French, and Arabic.
Usage
using SkyHelpers;
using System.Globalization;
// Relative Time (Uses current UI culture)
var date = DateTime.Now.AddMinutes(-5);
string relative = DateHelper.RelativeAgo(date); // "5 min ago" (if en)
// Explicit Culture (French)
var frCulture = new CultureInfo("fr");
string relativeFr = DateHelper.RelativeAgo(date, frCulture); // "il y a 5 min"
// Hijri Date
string hijri = DateHelper.GetHijriDate(DateTime.Now); // "10 Ramadan 1445"
string hijriAr = DateHelper.GetHijriDate(DateTime.Now, culture: new CultureInfo("ar")); // "10 رمضان 1445"
LocalizationHelper
Internal helper for retrieving localized strings.
Features
- GetString: Retrieves a localized string key.
- GetRelativeString: Helper for past/future relative date strings.
- Culture Support: Accepts optional
CultureInfo, defaults toCurrentUICulture.
Usage (Internal)
string text = LocalizationHelper.GetString("KeyName");
string textFr = LocalizationHelper.GetString("KeyName", new CultureInfo("fr"));
Parse
Safe parsing utilities for common types.
Features
- Int: Parses to
int?. Returnsnullon failure. - Decimal: Parses to
decimal. Returns0on failure. - Double: Parses to
double. Returns0on failure. - Boolean: Parses to
bool. Returnsfalseon failure. - DateTime: Parses to
DateTime?. Returnsnullon failure. - TimeOnly: Parses to
TimeOnly?. Returnsnullon failure. - DateOnly: Parses to
DateOnly?. Returnsnullon failure.
Usage
using SkyHelpers;
int? id = Parse.Int("123");
decimal price = Parse.Decimal("19.99");
double lat = Parse.Double("48.8566");
bool isActive = Parse.Boolean("true");
DateTime? date = Parse.DateTime("2023-01-01");
TimeOnly? time = Parse.TimeOnly("14:30");
DateOnly? dateOnly = Parse.DateOnly("2023-12-25");
Hooks
Interfaces for common entity framework entity lifecycle hooks.
Features
- IBeforeCreate:
void BeforeCreate() - IBeforeUpdate:
void BeforeUpdate() - IBeforeDelete:
void BeforeDelete()
Usage
using SkyHelpers;
public class MyEntity : IBeforeCreate
{
public void BeforeCreate()
{
// Logic before creation
}
}
PasswordHelper
BCrypt password hashing compatible with Laravel ($2y$ prefix).
Features
- HashPassword: Hashes a password with BCrypt (default cost 10) and uses
$2y$prefix. - VerifyPassword: Verifies a password against a hash (supports
$2y$,$2a$,$2b$).
Usage
using SkyHelpers;
string hash = PasswordHelper.HashPassword("secret");
bool isValid = PasswordHelper.VerifyPassword("secret", hash);
Messages
A unified Twilio wrapper for sending WhatsApp and SMS messages.
Configuration
The Messages class is initialized with your Twilio credentials:
- accountSid: Your Twilio Account SID.
- authToken: Your Twilio Auth Token.
- fromNumber: The Twilio phone number to send from.
- phoneCode (Optional): Default country dialing code (e.g., "+213"). Defaults to
+213.
Methods
- SendWhatsApp: Sends a WhatsApp message. Returns
trueon success,falseon failure. - SendSms: Sends an SMS message. Returns
trueon success,falseon failure.
Both methods automatically handle phone number formats (+, 00, and local numbers with leading 0).
Usage
using SkyHelpers;
var msg = new Messages("AC...", "AuthToken...", "+14155238886");
// Send WhatsApp
bool whatsAppSent = msg.SendWhatsApp("+15551234567", "Hello via WhatsApp!");
if (whatsAppSent)
Console.WriteLine("WhatsApp sent!");
// Send SMS (requires Messaging Service SID)
bool smsSent = msg.SendSms("0550123456", "Hello via SMS!", "MG...");
if (smsSent)
Console.WriteLine("SMS sent!");
PhoneCode
A utility class providing a comprehensive list of international dialing codes.
Features
- GetAll / GetCountryPhoneCodes: Returns a list of
CountryInfoobjects containing country names and dialing codes (e.g., "Algeria", "+213").
Usage
using SkyHelpers;
var codes = PhoneCode.GetAll();
var dz = codes.FirstOrDefault(c => c.Name == "Algeria");
Console.WriteLine(dz.Code); // Output: +213
MachineIdentifier
Generates a unique hardware-based identifier for the machine running the application.
Features
- GetUniqueIdentifier: Returns a hashed string derived from CPU ID, BIOS Serial Number, and BaseBoard Serial Number.
- Fallbacks: Robustly handles missing hardware information by trying multiple identifiers.
Usage
using SkyHelpers;
string uniqueId = MachineIdentifier.GetUniqueIdentifier();
Console.WriteLine(uniqueId); // e.g., "a1b2c3d4..."
ImageHelper
Utilities for manipulating images, converting bytes, and saving files.
Features
- GetImageBytesFromPath: Safely reads image bytes from a path.
- GetImageFromPath: Loads an
Imageobject from a path. - SaveImageToProjectDirectory: Saves an image to
[AppDir]/Images/[SubDirectory]. - ImageToBytes / BytesToImage: Convenient conversion methods.
- To24bppRgb: Standardization.
- ResizeImage: Resizes an image while preserving aspect ratio and optimizing output format (JPEG vs PNG).
Usage
using SkyHelpers;
using System.Drawing;
Image img = ImageHelper.GetImageFromPath("path/to/image.jpg");
byte[] bytes = ImageHelper.ImageToBytes(img);
// Resizing
byte[] originalBytes = File.ReadAllBytes("large_image.jpg");
// Resize to 800px width (height calculated automatically)
byte[] resizedBytes = ImageHelper.ResizeImage(originalBytes, width: 800);
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0-windows7.0 is compatible. |
-
net10.0-windows7.0
- BCrypt.Net-Next (>= 4.0.3)
- System.Management (>= 10.0.1)
- Twilio (>= 7.13.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.