Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could use asserts here

Suggested change
* @returns {boolean}
* @returns {asserts value is BlockList}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure what this would accomplish. The method does not assert at all, it just returns true or false and should not throw any errors.

*/
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({}));
}
Loading