ForgeKit Stable v1.0 is officially released. Upgrade now for zero-assertions DB compilation. Read Release Notes
Docs Nav

@doyzfin/common

@doyzfin/common is the foundational utilities library for ForgeKit developer stacks. It contains lightweight, edge-compatible helpers for class merging, browser assertions, JSON validation, and custom Svelte action bindings with zero runtime overhead.

Class Merger Helper (cn)

Combines CSS classes using clsx and tailwind-merge rules to support reactive class declarations without class name conflicts:

import { cn } from '@doyzfin/common';

// Basic combinations
const classes = cn('px-4 py-2 text-sm', isActive && 'bg-primary text-white');

// Overriding default Tailwind classes correctly
const customButton = cn('bg-red-500 p-4', 'bg-blue-600');
// Results in: 'bg-blue-600 p-4' (Red is merged out)

Edge Runtime Checkers

Verify your active deployment environment parameters securely before running client-only Web APIs:

isBrowser()

Checks if the current process runs inside a real web client environment:

import { isBrowser } from '@doyzfin/common';

if (isBrowser()) {
	// Safe to access window, document, or localStorage
	localStorage.setItem('theme', 'dark');
}

isServer()

Checks if code runs in server/node/edge routing environments:

import { isServer } from '@doyzfin/common';

if (isServer()) {
	console.log('Secure process reading environment secrets...');
}

JSON Validation Utilities

Parse incoming payloads safely without throwing syntax exceptions:

tryParseJson<T>(jsonString: string): T | null

Parses a JSON string safely and returns typed results, or null if parsing fails:

import { tryParseJson } from '@doyzfin/common';

const data = tryParseJson<{ id: string }>('{"id": "usr_99"}');
if (data) {
	console.log('User ID:', data.id);
}