Sofondo
SofondoFrameworkDocs

Utilities API Reference

Complete reference for core utilities in the Sofondo Framework.

Installation

npm install @sofondo/core

Usage

Import utilities from @sofondo/core:

import { getStorageStatus, getStorageColor, formatBytes } from '@sofondo/core';

Storage Utilities

getStorageStatus(value, max, inverted?)

Calculate storage usage status based on percentage thresholds.

Parameters:

  • value: number - Current usage value
  • max: number - Maximum capacity
  • inverted?: boolean - If true, higher percentages are better (default: false)

Returns: 'healthy' | 'warning' | 'critical'

Example:

import { getStorageStatus } from '@sofondo/core';

const status = getStorageStatus(75, 100); // 'warning'
const completionStatus = getStorageStatus(90, 100, true); // 'healthy'

getStorageColor(status)

Get hex color code for a storage status.

Parameters:

  • status: 'healthy' | 'warning' | 'critical' - Storage status

Returns: string - Hex color code

Colors:

  • healthy: #0f9d58 (green)
  • warning: #f9ab00 (orange)
  • critical: #ea4335 (red)

Example:

import { getStorageStatus, getStorageColor } from '@sofondo/core';

const status = getStorageStatus(usage, max);
const color = getStorageColor(status);

getStorageClassName(status)

Get CSS class name suffix for a storage status.

Parameters:

  • status: 'healthy' | 'warning' | 'critical' - Storage status

Returns: 'positive' | 'warning' | 'negative'

Example:

const className = getStorageClassName('healthy'); // 'positive'

Configuration

defineConfig(config)

Define a type-safe Sofondo configuration.

Parameters:

  • config: UserConfig - Partial configuration object

Returns: UserConfig - The same configuration (for type safety)

Example:

import { defineConfig } from '@sofondo/core';

export default defineConfig({
  theme: { defaultMode: 'dark' },
  sidebar: { defaultCollapsed: true },
});

mergeConfig(userConfig?)

Merge user configuration with defaults.

Parameters:

  • userConfig?: UserConfig - User configuration to merge

Returns: ResolvedConfig - Complete configuration with defaults

validateConfig(config)

Validate configuration and return errors.

Parameters:

  • config: UserConfig - Configuration to validate

Returns: string[] - Array of error messages (empty if valid)