UNPKG

@100mslive/hms-ai-ui

Version:
59 lines (51 loc) 1.43 kB
import { clsx, type ClassValue } from "clsx"; import { twMerge } from "tailwind-merge"; export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)); } /** * Type guard to check if a value is a plain object * @param value - Value to check * @returns True if value is a plain object, false otherwise */ function isPlainObject( value: unknown ): value is Record<string | number | symbol, unknown> { return Boolean( value && typeof value === "object" && !Array.isArray(value) && Object.prototype.toString.call(value) === "[object Object]" ); } /** * Type-safe deep merge function that combines multiple objects * @param target - Target object to merge into * @param sources - Source objects to merge from * @returns Merged object */ export function mergeDeep<T extends Record<string, any>>( target: T, ...sources: Partial<T>[] ): T { if (!sources.length) { return target; } const source = sources.shift(); if (source === undefined) { return target; } if (isPlainObject(target) && isPlainObject(source)) { Object.keys(source).forEach((key) => { if (isPlainObject(source[key])) { if (!target[key]) { Object.assign(target, { [key]: {} }); } mergeDeep(target[key], source[key]); } else { Object.assign(target, { [key]: source[key] }); } }); } return mergeDeep(target, ...sources); }