collectype / BaseFunctions / BaseFunctions
Defined in: BaseFunctions.ts:23
Core collection manipulation class providing chainable operations. Serves as the foundation for filtering, sorting, and transforming collections of any type.
T
The type of items in the collection.
Collectable<T>new BaseFunctions<
T>(items):BaseFunctions<T>
Defined in: BaseFunctions.ts:33
Creates an instance of BaseFunctions.
T[]
Array of items to operate on.
BaseFunctions<T>
protected_items:T[]
Defined in: BaseFunctions.ts:24
protectedoptional_pageState:PageState
Defined in: BaseFunctions.ts:25
protectedoptional_sortState:SortState
Defined in: BaseFunctions.ts:26
protected_stepManager:StepManager
Defined in: BaseFunctions.ts:27
get items():
T[]
Defined in: BaseFunctions.ts:41
Gets the array of items.
T[]
The current array of items.
get count():
number
Defined in: BaseFunctions.ts:49
Gets the number of items.
number
The count of items.
get info():
CollectionInfo
Defined in: BaseFunctions.ts:57
Gets information about the current state of the collection.
Information about pagination, sorting, filters, and operations.
begin(
name):this
Defined in: BaseFunctions.ts:70
Starts a named step with stack management for nested calls. Automatically handles nested step calls without breaking the chain.
string
this
end():
this
Defined in: BaseFunctions.ts:82
Ends the current step and pops from stack.
this
where(
fn):this
Defined in: BaseFunctions.ts:97
Filters items using the provided predicate function. This is the preferred, concise method for filtering collections.
PredicateFn<T>
The predicate function to filter items.
this
The instance for chaining.
collection.fn.where(p => p.is_legendary)
all():
this
Defined in: BaseFunctions.ts:110
Returns the current instance (all items).
this
The instance for chaining.
sort<
K>(field,dir?,type?):this
Defined in: BaseFunctions.ts:124
Sorts the items by a specified field with automatic type detection. Automatically infers the sort type from the field value if not explicitly provided.
K extends string | number | symbol
The key of the field to sort by.
K
The field name to sort on.
SortDir = SortDirEnum.ASC
Sort direction (‘asc’ or ‘desc’). Default is ‘asc’.
Sort type (‘string’, ‘number’, ‘boolean’, ‘date’). Auto-detected if omitted.
this
The instance for chaining.
Error if an unsupported sort type is provided.
page(
current,perPage?):this
Defined in: BaseFunctions.ts:171
Paginates the items by returning a specific page of results.
number
The current page number (1-based).
number = 20
The number of items per page. Default is 20.
this
The instance for chaining.
Error if current is less than 1 or perPage is less than 1.
pipe(
expression):this
Defined in: BaseFunctions.ts:211
Executes a sequence of chainable operations from a pipe expression string. Parses and executes multiple method calls in sequence, ensuring each returns ‘this’ for chaining.
string
| The pipe expression string (e.g., “method1(arg) | method2(arg)”). |
this
The instance for chaining.
Error if a reserved method is used, unknown method is called, or method breaks the chain.