( ...args: any[] )
| 36 | options?: UseArrayIncludesOptions<T, V>, |
| 37 | ): ComputedRef<boolean> |
| 38 | export function useArrayIncludes<T, V = any>( |
| 39 | ...args: any[] |
| 40 | ): ComputedRef<boolean> { |
| 41 | const list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]> = args[0] |
| 42 | const value: MaybeRefOrGetter<V> = args[1] |
| 43 | |
| 44 | let comparator: UseArrayIncludesComparatorFn<T, V> = args[2] |
| 45 | let formIndex = 0 |
| 46 | |
| 47 | if (isArrayIncludesOptions(comparator)) { |
| 48 | formIndex = comparator.fromIndex ?? 0 |
| 49 | comparator = comparator.comparator! |
| 50 | } |
| 51 | |
| 52 | if (typeof comparator === 'string') { |
| 53 | const key = comparator as keyof T |
| 54 | comparator = (element: T, value: V) => element[key] === toValue(value) |
| 55 | } |
| 56 | |
| 57 | comparator = comparator ?? ((element: T, value: T) => element === toValue(value)) |
| 58 | |
| 59 | return computed(() => |
| 60 | toValue(list) |
| 61 | .slice(formIndex) |
| 62 | .some((element, index, array) => comparator( |
| 63 | toValue(element), |
| 64 | toValue(value), |
| 65 | index, |
| 66 | toValue(array), |
| 67 | ))) |
| 68 | } |
no test coverage detected