Initial commit
This commit is contained in:
29
utils.ts
Normal file
29
utils.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
export const generateId = (): string => {
|
||||
return Math.random().toString(36).substring(2, 9);
|
||||
};
|
||||
|
||||
export const formatTime = (date: Date): string => {
|
||||
const h = date.getHours().toString().padStart(2, '0');
|
||||
const m = date.getMinutes().toString().padStart(2, '0');
|
||||
const s = date.getSeconds().toString().padStart(2, '0');
|
||||
const ms = date.getMilliseconds().toString().padStart(3, '0');
|
||||
return `${h}:${m}:${s}.${ms}`;
|
||||
};
|
||||
|
||||
export const uInt8ArrayToHex = (arr: Uint8Array): string => {
|
||||
return Array.from(arr)
|
||||
.map(b => b.toString(16).padStart(2, '0').toUpperCase())
|
||||
.join(' ');
|
||||
};
|
||||
|
||||
export const uInt8ArrayToAscii = (arr: Uint8Array): string => {
|
||||
// Replace non-printable characters with a dot or special symbol to avoid rendering issues
|
||||
return Array.from(arr)
|
||||
.map(b => {
|
||||
if (b >= 32 && b <= 126) {
|
||||
return String.fromCharCode(b);
|
||||
}
|
||||
return '.'; // Placeholder for non-printable chars
|
||||
})
|
||||
.join('');
|
||||
};
|
||||
Reference in New Issue
Block a user