Skip to content

Commit

Permalink
net: add net.BlockList.isBlockList(value)
Browse files Browse the repository at this point in the history
PR-URL: #56078
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: theanarkh <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Chemi Atlow <[email protected]>
  • Loading branch information
jasnell authored and targos committed Dec 6, 2024
1 parent da354f4 commit 565b04a
Show file tree
Hide file tree
Showing 3 changed files with 23 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
9 changes: 9 additions & 0 deletions lib/internal/blocklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ class BlockList {
this[kHandle][owner_symbol] = this;
}

/**
* Returns true if the value is a BlockList
* @param {any} value
* @returns {boolean}
*/
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 565b04a

Please sign in to comment.