Function composeLabelFromItems

  • Composes a descriptive label from an array of objects by concatenating values of a specified key in each object. The label adjusts automatically based on the number of items and provides flexibility to customize prefixes and conjunctions.

    Type Parameters

    • T

      The type of each item in the items array.

    Parameters

    Returns string

    A formatted string label based on the provided items and options.

    Example

    // Example usage with a simple array of products
    interface Product { name: string; }
    const products: Product[] = [
    { name: "Apple" },
    { name: "Banana" },
    { name: "Cherry" },
    ];

    const label = composeLabelFromItems({
    items: products,
    labelKey: "name",
    singleItemPrefix: "Only",
    multipleItemsPrefix: "FoundWithin",
    conjunctionWord: "And",
    });
    // Output: "Found in Apple, Banana and Cherry:"

Generated using TypeDoc