-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
73e70c1
commit aacd5be
Showing
5 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import * as _ from 'radashi' | ||
import { bench } from 'vitest' | ||
|
||
describe('isWeakSet', () => { | ||
bench('with no arguments', () => { | ||
_.isWeakSet() | ||
}) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
title: isWeakSet | ||
description: Returns true for WeakSet instances | ||
--- | ||
|
||
## Basic usage | ||
|
||
Returns true for `WeakSet` instances, even if they are subclass instances or from | ||
other [realms](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof#instanceof_and_multiple_realms). | ||
|
||
```ts | ||
import * as _ from 'radashi' | ||
|
||
_.isWeakSet(new WeakSet()) // true | ||
_.isWeakSet(new (class extends WeakSet {})()) // true | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { isTagged } from 'radashi' | ||
|
||
export function isWeakSet<T extends WeakKey = WeakKey>( | ||
value: unknown, | ||
): value is WeakSet<T> { | ||
return isTagged(value, '[object WeakSet]') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import * as vm from 'node:vm' | ||
import * as _ from 'radashi' | ||
|
||
describe('isWeakSet', () => { | ||
test('returns true for WeakSet instances', () => { | ||
expect(_.isWeakSet(new WeakSet())).toBe(true) | ||
}) | ||
test('returns true for WeakSet subclass instances', () => { | ||
expect(_.isWeakSet(new (class extends WeakSet {})())).toBe(true) | ||
}) | ||
test('returns true for WeakSet instances from other realms', () => { | ||
expect(_.isWeakSet(vm.runInNewContext('new WeakSet()'))).toBe(true) | ||
}) | ||
test('returns false for undefined', () => { | ||
expect(_.isWeakSet(undefined)).toBe(false) | ||
}) | ||
test('returns false for null', () => { | ||
expect(_.isWeakSet(null)).toBe(false) | ||
}) | ||
test('returns false for non-WeakSet objects', () => { | ||
expect(_.isWeakSet({})).toBe(false) | ||
}) | ||
}) |