Skip to content

Commit

Permalink
fix: contains and doesntContain resulting in wrong values
Browse files Browse the repository at this point in the history
The function parameters have been changed to optional and argument handling has been adjusted to only consider defined arguments. This improves function flexibility and clarity since it makes the function's behavior more predictable with variable argument amounts.
  • Loading branch information
maicol07 committed Nov 19, 2023
1 parent ca8e024 commit d15498f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ export class Collection<K extends CollectionKeyType = string, V = unknown> imple
* @param value
* @return boolean
*/
public contains(key: ((value: V, key: K) => boolean) | V | K, operator: any = null, value: any = null): boolean {
if (arguments.length === 1) {
public contains(key: ((value: V, key: K) => boolean) | V | K, operator?: any, value?: any): boolean {
const args = [...arguments].filter(arg => arg !== undefined)
if (args.length === 1) {
if (typeof key === 'function') {
let placeholder = {};

Expand All @@ -133,7 +134,7 @@ export class Collection<K extends CollectionKeyType = string, V = unknown> imple
}

// @ts-expect-error
return this.contains(this.operatorForWhere.apply(this, arguments));
return this.contains(this.operatorForWhere.apply(this, args));
}

public containsOneItem() {
Expand Down Expand Up @@ -216,7 +217,7 @@ export class Collection<K extends CollectionKeyType = string, V = unknown> imple
* @param value
* @param item {(value, key) => boolean} Predicate to test every entry
*/
public doesntContain(item: ((value: V, key: K) => boolean) | V | K, operator: any = null, value: any = null) {
public doesntContain(item: ((value: V, key: K) => boolean) | V | K, operator?: any, value?: any) {
return !this.contains(item, operator, value);
}

Expand Down

0 comments on commit d15498f

Please sign in to comment.