Skip to content

Commit

Permalink
net: add net.BlockList.isBlockList(value)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell committed Nov 29, 2024
1 parent 61b077d commit b65f654
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions doc/api/net.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@ added:

The list of rules added to the blocklist.

### `BlockList.isBlockList(value)`

<!-- YAML
added: REPLACEME
-->

* `value` {any} Any JS value
* Returns `true` if the `value` is a `net.BlockList`

## Class: `net.SocketAddress`

<!-- YAML
Expand Down
4 changes: 4 additions & 0 deletions lib/internal/blocklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class BlockList {
this[kHandle][owner_symbol] = this;
}

static isBlockList(value) {
return value?.[kHandle] !== undefined;
}

[kInspect](depth, options) {
if (depth < 0)
return this;
Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-blocklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,8 @@ const util = require('util');
assert(!blocklist.check('1.1.1.2'));
assert(!blocklist.check('2.3.4.5'));
}

{
assert(BlockList.isBlockList(new BlockList()));
assert(!BlockList.isBlockList({}));
}

0 comments on commit b65f654

Please sign in to comment.