@llselect/core
Version:
Low-level select: a minimal, flexible, framework-agnostic replacement for the native HTML select element.
25 lines • 1.36 kB
TypeScript
/**
* Stable-bucket `items` so that every group is contiguous, without touching
* the caller's array.
*
* - Groups appear in order of each key's FIRST appearance.
* - Within a group, items keep their relative order.
* - Items whose key is `null` (ungrouped) form their own single-item segment
* at their walk position; they never merge.
* - Already-contiguous input is detected in one scan and returned AS-IS (the
* input array itself, no copy); otherwise a new array is returned.
*
* This is exactly what `LLSelectBase` runs internally while the
* `gatherGroups` setting is on (the default). Exported for callers who switch
* `gatherGroups` off and gather once themselves (e.g. ahead of many
* `setItems` calls on the same data).
*
* @param items - the item list to gather
* @param itemToGroupKeyFn - item to group key; `null` = the item is in no group
* @param groupKeyCompareFn - key equality; `null` / omitted = identity (`===`,
* plus `NaN` equals `NaN` - the rule the internal `Map` uses; same contract
* as the `groupKeyCompareFn` setting)
* @group Grouping
*/
export declare function gatherItemsByGroupKey<T, GroupKey = string>(items: readonly T[], itemToGroupKeyFn: (item: T) => GroupKey | null, groupKeyCompareFn?: ((a: GroupKey, b: GroupKey) => boolean) | null): readonly T[];
//# sourceMappingURL=grouping.d.ts.map