Skip to content

Commit

Permalink
fix: dataGet helper and has method in collection
Browse files Browse the repository at this point in the history
The 'has' method in the Collection class now uses 'has' instead of 'in'. The handling of 'target' inside the 'helpers' file has been revised to now specifically deal with a 'Collection' instance. These changes enhance consistency, readability, and code structure.
  • Loading branch information
maicol07 committed Nov 19, 2023
1 parent d15498f commit d095cfc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ export class Collection<K extends CollectionKeyType = string, V = unknown> imple
}

public has(key: K) {
return key in this.items;
return this.items.has(key);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,11 @@ export function dataGet(
if (isAccessible(target) && exists(target, segment)) {
if (Array.isArray(target)) {
target = target[Number.parseInt(segment, 10)];
} else if (target instanceof Collection) {
target = target.get(segment);
} else {
target = (target as Record<any, any>)[segment];
}
target = (target as Record<any, any>)[segment];
} else {
return value(fallback);
}
Expand Down

0 comments on commit d095cfc

Please sign in to comment.