A minimal utility library offering essential helpers for React (using Vite) and Next.js applications.
- Automatically supports both Vite (React) and Next.js environments
- TypeScript support with full definitions and JSDoc for all functions
- Utilities adapt based on environment variables
- Most-featured utilities: Logging Utilities
# npm
npm install @technway/rvnjs
# yarn
yarn add @technway/rvnjs
# pnpm
pnpm add @technway/rvnjs| Function | Description | Parameters | Returns | Notes |
|---|---|---|---|---|
resolveAvatar |
Resolves a user profile image URL | options: { path?: string | null, fallback?: string, baseUrl?: string | false } |
string - Final image URL |
HTTPS URLs returned as-is. HTTP URLs only allowed in dev. Relative paths are prefixed with API base URL. Fallback is returned for empty or disallowed paths. Requires VITE_API_BASE_URL (Vite) or NEXT_PUBLIC_API_URL (Next.js). |
getDisplayName |
Builds a readable name from a full name | options: { fullName: string, useFullName?: boolean, maxLength?: number } |
string - Display name |
Returns full name or a shortened version depending on flags. Trims and safely handles edge cases. No environment variables required. |
getDefaultProfilePhoto |
options: { role?: string | null, photoPath?: string | null, userAvatarPath?: string, adminAvatarPath?: string } |
string - Profile photo URL |
Deprecated. Use resolveAvatar instead. Falls back to role-specific avatars or API base + photoPath. |
| Type | Description | Notes |
|---|---|---|
AvatarOptions |
Options for resolveAvatar() |
{ path?: string | null, fallback?: string, baseUrl?: string | false } |
DisplayNameOptions |
Options for getDisplayName() |
{ fullName: string, useFullName?: boolean, maxLength?: number } |
ProfilePhotoOptions |
(Deprecated) Legacy options for avatar resolution | Used by getDefaultProfilePhoto(). Prefer AvatarOptions. |
import { resolveAvatar, getDisplayName } from '@technway/rvnjs';
resolveAvatar({ path: 'https://example.com/photo.jpg' });
// → 'https://example.com/photo.jpg'
resolveAvatar({ path: '/uploads/user.jpg' });
// → 'https://your-api.com/uploads/user.jpg'
getDisplayName({ fullName: 'John Michael Doe Smith' });
// → 'John'
getDisplayName({ fullName: 'John Michael Doe Smith', useFullName: true, maxLength: 15 });
// → 'John Michael...'Logging is automatically disabled in production unless explicitly enabled.
- 🧠 Environment-aware: auto-disables in production
- ⚡ Zero cost in prod when unused
- ℹ️ Emoji-prefixed logs for easier scanning
- 🔧 Central toggle via env vars
- 🧼 Cleaner, filterable output in browser console
- No
console.group(),console.table(),console.trace()support - No custom styles (
%c) - Use native
consoledirectly for advanced cases
| Feature | logger() (Main Logger) |
devLog() etc (Dev-Only) |
|---|---|---|
| Logging Mode | Env-controlled (ENABLE_LOGGING) |
Only in development |
| Interface | Object with .debug() etc |
Function with LogOptions object |
| Output Format | Emoji-prefixed messages | Emoji-prefixed messages |
| Performance in Prod | No-op unless explicitly enabled | No-op always |
| Use Case | General app logging | Dev debugging & warnings |
| Function | Description | Returns | Notes |
|---|---|---|---|
isLoggingEnabled |
Returns true if logging is enabled | boolean |
Controlled via VITE_ENABLE_LOGGING or NEXT_PUBLIC_ENABLE_LOGGING |
logger |
Returns a logger object (debug, info, etc) |
LoggerType |
Each log prefixed with emoji (🐛, |
| Function | Description | Parameters | Notes |
|---|---|---|---|
devLog |
Logs debug in development only | { message: string, data?, prefix? } |
Default prefix: 🔧 |
devError |
Logs error in development only | { message: string, data?, prefix? } |
Default prefix: ❌ |
devWarn |
Logs warning in development only | { message: string, data?, prefix? } |
Default prefix: |
devInfo |
Logs info in development only | { message: string, data?, prefix? } |
Default prefix: ℹ️ |
| Method | Emoji | Purpose |
|---|---|---|
log.debug() |
🐛 | Debugging info |
log.info() |
ℹ️ | General info |
log.warn() |
Warnings | |
log.error() |
❌ | Errors |
| Type | Description | Notes | |||
|---|---|---|---|---|---|
LogLevel |
`'debug' | 'info' | 'warn' | 'error'` | Internal log levels |
LogOptions |
Options for dev logging functions | { message: string, data?: unknown, prefix?: string } |
import { logger, devLog, devError } from '@technway/rvnjs';
const log = logger();
log.info('App started');
// → ℹ️ INFO: App started
devLog({ message: 'User loaded', data: { id: 123 } });
// → 🔧 User loaded { id: 123 }
devError({ message: 'Something failed', prefix: '🚫' });
// → 🚫 Something failed| Function | Description | Parameters | Returns | Notes |
|---|---|---|---|---|
isDevEnv |
Returns true if running in development mode |
None | boolean |
Checks NODE_ENV === 'development' or import.meta.env.MODE === 'development' |
getApiBaseUrl |
Returns base API URL from env or custom inputs | { customBaseUrl?: string, customApiPath?: string } |
string |
Reads from VITE_API_BASE_URL or NEXT_PUBLIC_API_URL. Appends path if provided. Trailing slashes removed automatically. |
NEXT_PUBLIC_API_URL(Next.js)VITE_API_BASE_URL(Vite)API_URL(fallback)
| Type | Description | Notes |
|---|---|---|
ApiBaseUrlOptions |
Options for getApiBaseUrl() |
{ customBaseUrl?: string, customApiPath?: string } |
MIT License © Technway Solutions