Convert
The Convert class provides type conversion and formatting functions. It exists in two layers — commons (core conversions) and hub-gui (extended with locale-specific date formatting and UI helpers).
Commons Convert
Package: io-oidis-commons
Core type conversions and formatting available on both frontend and backend.
import { Convert } from "@io-oidis-commons/.../Utils/Convert.js";
String / Number / Boolean Parsing
Convert.StringToInteger($input : string) : number // parseInt (base 10)
Convert.StringToDouble($input : string) : number // parseFloat
Convert.StringToBoolean($input : string) : boolean // "true"/"1"/"yes" → true
Convert.BooleanToString($input : boolean) : string // true → "true"
const page = Convert.StringToInteger(queryParam); // Safe parsing
const rate = Convert.StringToDouble(inputValue); // Safe float parsing
const flag = Convert.StringToBoolean(configValue); // Handles "true", "1", "yes"
StringUtils has equivalent methods (ToInteger, ToDouble, ToBoolean). Either is fine — use whichever fits the calling context. Convert is typically used when converting between different data types; StringUtils when already working with strings.
Object / Array / Function to String
Convert.ObjectToString($object : any, $prefix? : string, $htmlTag? : boolean) : string
Convert.ArrayToString($input : any, $prefix? : string, $htmlTag? : boolean) : string
Convert.FunctionToString($input : any, $multiline? : boolean) : string
Convert.ToType($object : any) : string
// Convert any object to readable HTML string
const html = Convert.ObjectToString(complexObject);
// Convert array or ArrayList to string
const arrayStr = Convert.ArrayToString(items);
// Get type name of any value
Convert.ToType(42); // → "number"
Convert.ToType([]); // → "array"
Convert.ToType(null); // → "null"
Convert.ToType(new Date()); // → "date"
Date Boundary Helpers
Set a Date to the start or end of a day or month. Essential for date range queries:
Convert.DateToStartOfDay(date : Date) : Date // 00:00:00.000
Convert.DateToEndOfDay(date : Date) : Date // 23:59:59.999
Convert.DateToStartOfMonth(date : Date) : Date // 1st of month, 00:00:00.000
Convert.DateToEndOfMonth(date : Date) : Date // Last day of month, 23:59:59.999
// Query all records created today
const today = new Date();
const filter = {
Created: {
$gte: Convert.DateToStartOfDay(today),
$lte: Convert.DateToEndOfDay(today)
}
};
// Query records for the entire month
const filter = {
Created: {
$gte: Convert.DateToStartOfMonth(today),
$lte: Convert.DateToEndOfMonth(today)
}
};
These helpers handle month-end edge cases correctly — DateToEndOfMonth properly sets the last day of the month (28/29/30/31 depending on the month and leap year).
Time Formatting
Convert.TimeToGMTformat($time : number | string | Date) : string // GMT string
Convert.TimeToSeconds($time : number) : number // Milliseconds → seconds
Convert.TimeToLongString($time : number) : string // Human-readable duration
Convert.TimeToLocalFormat($time : number | Date) : string // Locale time zone string
// Format elapsed time into human-readable string
const elapsed = stopwatch.ElapsedTime();
const display = Convert.TimeToLongString(elapsed);
// → "2 days, 3 hours, 15 minutes, 42 seconds"
// Convert to GMT
const gmt = Convert.TimeToGMTformat(Date.now());
// Convert to local timezone
const local = Convert.TimeToLocalFormat(new Date());
Math Helpers
Convert.ToFixed($input : number, $decimalPoints : number, $base? : number) : number
Convert.DegToRad($input : number) : number
Convert.RadToDeg($input : number) : number
Convert.IntegerToSize($input : number, $decimalPoints? : number) : string
// Fixed decimal precision
Convert.ToFixed(3.14159, 2); // → 3.14
// Angle conversions
Convert.DegToRad(180); // → 3.14159...
Convert.RadToDeg(Math.PI); // → 180
// File size formatting
Convert.IntegerToSize(1048576); // → "1 MB"
Convert.IntegerToSize(1536000, 1); // → "1.5 MB"
Convert.IntegerToSize(5368709120); // → "5 GB"
Encoding
Convert.HexadecimalToString($input : number) : string
Convert.StringToHexadecimal($input : string) : number
Convert.UnicodeToString(...$input : number[]) : string
Convert.Base64ToArrayBuffer($data : string) : ArrayBuffer
Convert.Base64ToBlob($input : string, $contentType? : string, $sliceSize? : number) : Blob
// Hex conversions
const hex = Convert.StringToHexadecimal("A"); // → numeric hex value
const str = Convert.HexadecimalToString(0x41); // → "A"
// Unicode
const emoji = Convert.UnicodeToString(0x1F600); // → "😀"
// Base64 decoding
const buffer = Convert.Base64ToArrayBuffer(base64Data);
const blob = Convert.Base64ToBlob(pdfData, "application/pdf");
HTML Helper
Convert.ToHtmlContentBlock($header : string, $content : string, $toggleText? : string) : string
Returns content wrapped in a collapsible HTML block with a toggle button:
const block = Convert.ToHtmlContentBlock(
"Debug Information",
Convert.ObjectToString(debugData),
"Show/Hide"
);
Hub-GUI Convert
Package: io-oidis-hub-gui
Extended Convert with locale-specific date formatting and UI helpers. This is the version used most often in frontend controllers.
import { Convert } from "@io-oidis-hub-gui/.../Utils/Convert.js";
Date Formatting
// Czech date format (DD.MM.YYYY)
Convert.DateToCsFormat($date : Date) : string
// → "23.02.2026"
// Calendar-friendly format
Convert.DateToCalendarFormat($date : Date) : string
// → "2026-02-23"
// Date + time format
Convert.DateTimeToCsFormat($date : Date) : string
// → "23.02.2026 14:30"
Usage in table binding:
$instance.table.BindData(
async ($offset, $limit) => { ... },
async ($data, $item) => {
$item.date.Text(Convert.DateToCsFormat($data.Created));
$item.modified.Text(Convert.DateTimeToCsFormat($data.LastModified));
},
async ($item) => { ... }
);
Complete Commons Method Reference
| Method | Description |
|---|---|
| String/Boolean | |
StringToInteger($input) | String to integer (base 10) |
StringToDouble($input) | String to float |
StringToBoolean($input) | String to boolean |
BooleanToString($input) | Boolean to string |
FunctionToString($input, $multiline?) | Function to string representation |
ObjectToString($object, $prefix?, $htmlTag?) | Any object to HTML/text string |
ArrayToString($input, $prefix?, $htmlTag?) | Array/ArrayList to HTML/text string |
ToType($object) | Type name as string |
| Date Boundaries | |
DateToStartOfDay(date) | Set time to 00:00:00.000 |
DateToEndOfDay(date) | Set time to 23:59:59.999 |
DateToStartOfMonth(date) | First day of month, 00:00:00.000 |
DateToEndOfMonth(date) | Last day of month, 23:59:59.999 |
| Time | |
TimeToGMTformat($time) | GMT format string |
TimeToSeconds($time) | Milliseconds to seconds |
TimeToLongString($time) | Human-readable duration |
TimeToLocalFormat($time) | Locale timezone string |
| Math | |
ToFixed($input, $decimals, $base?) | Fixed decimal precision |
DegToRad($input) | Degrees to radians |
RadToDeg($input) | Radians to degrees |
IntegerToSize($input, $decimals?) | File size formatting (B, kB, MB, GB, TB) |
| Encoding | |
HexadecimalToString($input) | Hex number to string |
StringToHexadecimal($input) | String to hex number |
UnicodeToString(...$input) | Unicode code points to string |
Base64ToArrayBuffer($data) | Base64 to binary buffer |
Base64ToBlob($input, $contentType?, $sliceSize?) | Base64 to Blob |
| HTML | |
ToHtmlContentBlock($header, $content, $toggleText?) | Collapsible HTML block |
When to Use Convert vs Vanilla
| Operation | Convert | Vanilla | Recommendation |
|---|---|---|---|
| Date to Czech format | Convert.DateToCsFormat() | Manual formatting | Always Convert — standardized |
| Date to ISO string | — | date.toISOString() | Vanilla — standard format |
| Date range query | Convert.DateToStartOfDay() | Manual setHours() | Convert — handles all edge cases |
| Base64 to Blob | Convert.Base64ToBlob() | Manual atob + Uint8Array | Convert — cleaner |
| Number parsing | Convert.StringToInteger() | parseInt() | Framework — null-safe |
| File size display | Convert.IntegerToSize() | Manual division | Convert — handles all units |
| Elapsed time display | Convert.TimeToLongString() | Manual calculation | Convert — human-readable |
| Fixed decimals | Convert.ToFixed() | Number.toFixed() | Convert — returns number, not string |
Convert is particularly valuable for date boundaries and time formatting — it ensures consistent, edge-case-safe output. For general type parsing, StringUtils.ToInteger() and StringUtils.ToBoolean() are equally valid choices.
See also: Utilities Overview | StringUtils | ObjectValidator | Stopwatch