common-util.ts


Overview

common-util.ts is a utility module providing a collection of general-purpose helper functions for data manipulation, formatting, conversion, and color parsing. These utilities are designed to simplify common tasks across the application, such as:

This file acts as a shared toolkit that can be imported wherever these functionalities are needed, promoting code reuse, consistency, and maintainability throughout the system.


Functions and Exports

isFormData(data: unknown): data is FormData


convertTheKeysOfTheObjectToSnake(data: unknown): unknown


getSearchValue(key: string): string | null


formatNumberWithThousandsSeparator(numberStr: string): string


sortLLmFactoryListBySpecifiedOrder(list: IFactory[]): IFactory[]


filterOptionsByInput(input: string, option?: { label: string; value: string }): boolean


toFixed(value: unknown, fixed = 2): unknown


stringToUint8Array(str: string): Uint8Array


hexStringToUint8Array(hex: string): Uint8Array | undefined


hexToArrayBuffer(input: string): ArrayBuffer


formatFileSize(bytes: number, si = true, dp = 1): string


parseColorToRGBA(color: string): [number, number, number]


Internal Helper Functions

isExcludedField(key: string): boolean

getCSSVariableValue(variableName: string): string


Important Implementation Details & Notes


Interactions with Other Parts of the System


Visual Diagram

flowchart TD
    A[common-util.ts] --> B[isFormData]
    A --> C[convertTheKeysOfTheObjectToSnake]
    A --> D[getSearchValue]
    A --> E[formatNumberWithThousandsSeparator]
    A --> F[sortLLmFactoryListBySpecifiedOrder]
    A --> G[filterOptionsByInput]
    A --> H[toFixed]
    A --> I[stringToUint8Array]
    A --> J[hexStringToUint8Array]
    A --> K[hexToArrayBuffer]
    A --> L[formatFileSize]
    A --> M[parseColorToRGBA]

    subgraph "Helper Functions"
        N[isExcludedField]
        O[getCSSVariableValue]
    end

    C --> N
    M --> O

Summary

The common-util.ts file is a key utility module offering a broad set of helper functions that:

It serves as a foundational toolkit to support consistent and efficient code across the application, especially for modules working with LLM factories and UI-related data processing.


If you have any questions about specific functions or need usage examples for particular contexts, feel free to ask!