Skip to content

Commit

Permalink
feat: Added Set::keys() method
Browse files Browse the repository at this point in the history
  • Loading branch information
rudashi committed Sep 27, 2024
1 parent 2994a95 commit 811b237
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/JavaScript/Set.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@ public function has(mixed $value): bool
return in_array($value, $this->items, true);
}

/**
* Returns Set keys as SetIterator.
* Alias for the values()
* @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/keys
*
* @return \Rudashi\JavaScript\SetIterator<int, TValue>
*/
public function keys(): SetIterator
{
return $this->values();
}

/**
* @return array<int, TValue>
*/
Expand Down
11 changes: 11 additions & 0 deletions tests/Unit/SetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,17 @@
['bar', true],
]);

describe('keys', function () {
it('returns new SetIterator', function () {
$set = new Set(['foo', 'bar']);

expect($set->keys())
->toBeInstanceOf(SetIterator::class)
->current()?->toBe('foo')
->next()?->toBe('bar');
});
});

describe('values', function () {
it('returns new SetIterator', function () {
$set = new Set(['foo', 'bar']);
Expand Down

0 comments on commit 811b237

Please sign in to comment.