Utilities
Orbitus Core provides essential utility functions to speed up development and ensure consistency.
Styling
cn (ClassNames)
A utility to conditionally join classNames and handle Tailwind CSS conflicts using clsx and tailwind-merge.
import { cn } from '@orbitusdev/core/utils';
export function Button({ className, variant }) {
return (
<button
className={cn(
'px-4 py-2 rounded font-medium', // Base styles
variant === 'primary' && 'bg-blue-500 text-white', // Conditional
className // External override
)}
>
Click me
</button>
);
}Formatting
formatDate
Formats a date into a human-readable string using Intl.DateTimeFormat.
import { formatDate } from '@orbitusdev/core/utils';
// Default (tr-TR locale)
formatDate(new Date()); // "13.02.2026 14:30"
// Custom options
formatDate(new Date(), 'en-US', { month: 'long', year: 'numeric' }); // "February 2026"formatPhoneNumber
Formats a phone number string.
import { formatPhoneNumber } from '@orbitusdev/core/utils';
formatPhoneNumber('5551234567'); // "(555) 123 45 67" (example format)Async Helpers
delay
Returns a promise that resolves after a specified number of milliseconds. Useful for simulating latency or creating pauses.
import { delay } from '@orbitusdev/core/utils';
async function demo() {
console.log('Start');
await delay(1000); // Wait 1 second
console.log('End');
}Observability
logger
A structured logger instance for client and server logging.
import { logger } from '@orbitusdev/core/utils';
logger.info('User logged in', { userId: '123' });
logger.error('Payment failed', { error });Generators
generateToken
Generates a random string token of a specified length.
import { generateToken } from '@orbitusdev/core/utils';
const token = generateToken(32);Error Handling
AppError
A custom error class for application-specific errors with status codes and metadata.
import { AppError } from '@orbitusdev/core/utils';
throw new AppError('Resource not found', 404, { resourceId: '123' });Last updated on