(
items: any,
skipDuplicateInput: boolean,
seenItems: Set<any>
)
| 255 | export const __SKIP__ = Symbol('__SKIP__') |
| 256 | |
| 257 | export function getUniqueItems( |
| 258 | items: any, |
| 259 | skipDuplicateInput: boolean, |
| 260 | seenItems: Set<any> |
| 261 | ): any { |
| 262 | let singleItem: boolean = false |
| 263 | if (!Array.isArray(items)) { |
| 264 | items = [items] |
| 265 | singleItem = true |
| 266 | } |
| 267 | |
| 268 | // If skipDuplicateInput is false, return as-is (no deduplication) |
| 269 | if (!skipDuplicateInput) { |
| 270 | return singleItem ? items[0] : items |
| 271 | } |
| 272 | |
| 273 | // Deduplication logic (only when skipDuplicateInput is true) |
| 274 | const newItems: any[] = [] |
| 275 | |
| 276 | for (const item of items) { |
| 277 | const itemRepr = getItemRepr(item) |
| 278 | |
| 279 | if (!seenItems.has(itemRepr)) { |
| 280 | newItems.push(item) |
| 281 | seenItems.add(itemRepr) |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | if (!newItems.length && singleItem) { |
| 286 | return __SKIP__ |
| 287 | } |
| 288 | |
| 289 | return singleItem && newItems.length ? newItems[0] : newItems |
| 290 | } |
| 291 | |
| 292 | export function removeItemFromSeenItemsSet(items: any, seenItems: Set<any>) { |
| 293 | if (!Array.isArray(items)) { |
no test coverage detected