cherry-studio/packages/ui/src/utils/index.ts
MyPrototypeWhat 05c26fbff2 refactor(ui): update utility imports to use internal lib
- Changed utility imports from '@cherrystudio/ui/utils' to '@cherrystudio/ui/lib/utils' across multiple components for better organization.
- Introduced a new internal utility module for class name merging, ensuring consistent usage across the UI components.
- Updated relevant components to reflect the new import paths, enhancing maintainability and clarity.
2025-12-29 18:58:13 +08:00

31 lines
1.1 KiB
TypeScript

/**
* Public utility functions for external consumers.
*
* This module is part of the PUBLIC API and can be imported via `@cherrystudio/ui/utils`.
* For internal-only utilities (e.g., Tailwind class merging), use `lib/` instead.
*
* @module utils
*/
/**
* Converts `null` to `undefined`, otherwise returns the input value.
* Useful when interfacing with APIs or libraries that treat `null` and `undefined` differently.
* @param data - The value that might be `null`
* @returns `undefined` if `data` is `null`, otherwise the original value
*/
export const toUndefinedIfNull = <T>(data: T | null): T | undefined => {
if (data === null) return undefined
else return data
}
/**
* Converts `undefined` to `null`, otherwise returns the input value.
* Handy for ensuring consistent representation of absent values.
* @param data - The value that might be `undefined`
* @returns `null` if `data` is `undefined`, otherwise the original value
*/
export const toNullIfUndefined = <T>(data: T | undefined): T | null => {
if (data === undefined) return null
else return data
}