clean-jsdoc-theme TypeDoc APIv0.0.0

ProductCollection

Source: Product.ts:389

Product collection for managing multiple products

Type Parameters

  • T extends IProduct = Product — Product type (must extend IProduct)

Constructors

new ProductCollection< T extends IProduct = Product, >( initialProducts?: T[], ): ProductCollection<T>

Parameters

  • initialProducts (T[], optional) — Optional initial products array

Returns

ProductCollection<T>


Accessors

get size(): number

Gets the number of products in the collection

Methods

[iterator](): Iterator<T>

Iterates over all products

Returns

  • Iterator<T>

add(product: T): this

Adds a product to the collection

Parameters

  • product (T) — Product to add

Returns

  • this — This collection for chaining

filterByCategory(category: ProductCategory): T[]

Filters products by category

Parameters

Returns

  • T[] — Array of matching products

get(productId: string): T | undefined

Gets a product by ID

Parameters

  • productId (string) — Product ID

Returns

  • T | undefined — The product or undefined

remove(productId: string): boolean

Removes a product from the collection

Parameters

  • productId (string) — ID of product to remove

Returns

  • boolean — True if product was removed

Searches products by name or tags

Parameters

  • query (string) — Search query

Returns

  • T[] — Array of matching products

toArray(): T[]

Gets all products as an array

Returns

  • T[] — Array of all products