GMana.Utils 0.0.10

There is a newer version of this package available.
See the version list below for details.
dotnet add package GMana.Utils --version 0.0.10
                    
NuGet\Install-Package GMana.Utils -Version 0.0.10
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GMana.Utils" Version="0.0.10" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GMana.Utils" Version="0.0.10" />
                    
Directory.Packages.props
<PackageReference Include="GMana.Utils" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add GMana.Utils --version 0.0.10
                    
#r "nuget: GMana.Utils, 0.0.10"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package GMana.Utils@0.0.10
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=GMana.Utils&version=0.0.10
                    
Install as a Cake Addin
#tool nuget:?package=GMana.Utils&version=0.0.10
                    
Install as a Cake Tool

GMana.Utils

A collection of utility extensions, helpers, and services for .NET applications, designed to simplify common tasks such as IP address retrieval, number-to-words conversion, byte size formatting, and more.

Extensions

Khmer Language Helpers

  • IsKhmer: Checks if a string contains only Khmer characters.
  • ContainsKhmer: Checks if a string contains any Khmer characters.

ToByteSizeExtensions

Converts numeric values (string, decimal, double, long) into human-readable byte sizes (e.g., KB, MB, GB).

using GMana.Utils.Extensions;

// String usage
string bytesStr = "5242880";
Console.WriteLine(bytesStr.ToByteSizeString());      // "5.00 MB"
Console.WriteLine(bytesStr.ToByteSizeString("N0"));  // "5 MB"

// Decimal usage
decimal bytesDec = 1073741824m;
Console.WriteLine(bytesDec.ToByteSizeString());      // "1.00 GB"

// Double usage
double bytesDbl = 1099511627776.0;
Console.WriteLine(bytesDbl.ToByteSizeString());      // "1.00 TB"

// Long usage
long bytesLong = 123456789;
Console.WriteLine(bytesLong.ToByteSizeString());     // "117.74 MB"

ToRelativeTimeString

Converts a DateTime to a human-readable relative time string (e.g., "5 seconds ago").

var pastTime = DateTime.Now.AddSeconds(-30);
string result = pastTime.ToRelativeTimeString();  // "30 seconds ago"

Unit Test Example

[Theory]
[InlineData(1, "1 second ago")]
[InlineData(30, "30 seconds ago")]
[InlineData(59, "59 seconds ago")]
public void ToRelativeTimeString_SecondsAgo_ReturnsSecondsAgoText(int seconds, string expected)
{
    var pastTime = DateTime.Now.AddSeconds(-seconds);
    var result = pastTime.ToRelativeTimeString();
    Assert.Equal(expected, result);
}

NumericExtensions

Formats large numbers into compact strings with suffixes (e.g., "1.5k", "2.3M").

// Default precision (2 decimal places)
int number = 1456;
string formatted = number.ToRoundedString();  // "1.46k"

// Custom precision
formatted = number.ToRoundedString(1);  // "1.5k"
formatted = number.ToRoundedString(0);  // "1k"

// Larger numbers
number = 1500000;
formatted = number.ToRoundedString();  // "1.50M"

// Double values
double value = 1346.75;
formatted = value.ToRoundedString();  // "1.35k"

GetIPAddress

Retrieves the IP address of the current machine.

using GMana.Utils;

var ip = IP.GetIPAddress();  // Returns the IP address as a string

ClientIpService

A service to retrieve the client’s IP address in Blazor applications.

Setup for Blazor Server

// Program.cs
builder.Services.AddHttpContextAccessor();
builder.Services.AddScoped<IClientIpService, ClientIpService>();

Setup for Blazor WebAssembly

// Program.cs
builder.Services.AddScoped<IClientIpService, ClientIpService>();

Usage in a Component

@inject IClientIpService IpService

<p>Client IP: @clientIp</p>

@code {
    private string clientIp = "Loading...";

    protected override async Task OnInitializedAsync()
    {
        clientIp = await IpService.GetClientIpAsync();
    }
}

JavaScript for WebAssembly

Add this script to your WebAssembly project:

<script src="_content/BlazorIpAddress/js/ipfetcher.js"></script>

NumberToWordsConverter

Converts a decimal number to English words (e.g., for currency).

decimal number = 165.93m;
string result = NumberToWordsConverter.ConvertToWords(number);
Console.WriteLine(result);  // "One Hundred Sixty-Five Dollar and Ninety-Three Cents"

NumberToKhmerWordsConverter

Converts a decimal number to Khmer words with a custom currency unit.

decimal number = 165.93m;

// Using Dollar (ដុល្លារ)
string dollarResult = NumberToKhmerWordsConverter.ConvertToKhmerWords(number, "ដុល្លារ");
Console.WriteLine(dollarResult);  // "មួយរយហុកសិបប្រាំ ដុល្លារ និង កៅសិបបី សេន"

// Using Riel (រៀល)
string rielResult = NumberToKhmerWordsConverter.ConvertToKhmerWords(number, "រៀល");
Console.WriteLine(rielResult);    // "មួយរយហុកសិបប្រាំ រៀល"

Stringify

// Test Case
[Theory]
[InlineData(null, "")]
[InlineData("", "")]
[InlineData("  ", "")]
[InlineData("Example.txt", "example.txt")]
[InlineData("My-File_Name.DOC", "my_file_name.doc")]
[InlineData("Complex@File#Name!", "complex_file_name")]
[InlineData("NoExtensionFile", "no_extension_file")]
[InlineData("123-456_file.TEST", "123_456_file.test")]
[InlineData("file.with.multiple.dots.TXT", "file_with_multiple_dots.txt")]
[InlineData("UPPERCASE.JPG", "uppercase.jpg")]
[InlineData("Special--_Chars!.mp3", "special_chars.mp3")]

GetDaySuffix

// Test Case
[Theory]
[InlineData(1, "1st")]
[InlineData(2, "2nd")]
[InlineData(3, "3rd")]
[InlineData(4, "4th")]
[InlineData(11, "11th")]
[InlineData(12, "12th")]
[InlineData(13, "13th")]
[InlineData(21, "21st")]
[InlineData(22, "22nd")]
[InlineData(23, "23rd")]
[InlineData(24, "24th")]
[InlineData(101, "101st")]
[InlineData(111, "111th")]
[InlineData(112, "112th")]
[InlineData(113, "113th")]
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on GMana.Utils:

Package Downloads
GMana.Extensions

The GMana.Extensions is a .NET library that provides a collection of extension methods to enhance functionality for common .NET types, including string manipulation, numeric formatting, JSON handling, dictionary operations, enum utilities, character validation, and byte size formatting. Features specialized Khmer language support.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.11 168 8/13/2025
0.0.10 177 5/7/2025
0.0.9 140 5/2/2025
0.0.8 173 3/20/2025
0.0.7 151 3/19/2025
0.0.6 216 3/7/2025
0.0.5 111 2/28/2025
0.0.4 105 2/26/2025
0.0.3 136 2/13/2025
0.0.2 100 1/27/2025
0.0.1 107 1/22/2025