GeezerVison is showing github.com — net: add net.BlockList.isBlockList(value) · nodejs/node@ed7eab1
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: doc/api/net.md +9Lines changed: 9 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -170,6 +170,15 @@ added: |
170 | 170 |
|
171 | 171 | The list of rules added to the blocklist. |
172 | 172 |
|
| 173 | +### `BlockList.isBlockList(value)` |
| 174 | + |
| 175 | +<!-- YAML |
| 176 | +added: REPLACEME |
| 177 | +--> |
| 178 | + |
| 179 | +* `value` {any} Any JS value |
| 180 | +* Returns `true` if the `value` is a `net.BlockList`. |
| 181 | + |
173 | 182 | ## Class: `net.SocketAddress` |
174 | 183 |
|
175 | 184 | <!-- YAML |
|
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/blocklist.js +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -43,6 +43,15 @@ class BlockList { |
43 | 43 | this[kHandle][owner_symbol] = this; |
44 | 44 | } |
45 | 45 |
|
| 46 | + /** |
| 47 | + * Returns true if the value is a BlockList |
| 48 | + * @param {any} value |
| 49 | + * @returns {boolean} |
| 50 | + */ |
| 51 | + static isBlockList(value) { |
| 52 | + return value?.[kHandle] !== undefined; |
| 53 | + } |
| 54 | + |
46 | 55 | [kInspect](depth, options) { |
47 | 56 | if (depth < 0) |
48 | 57 | return this; |
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-blocklist.js +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -282,3 +282,8 @@ const util = require('util'); |
282 | 282 | assert(!blocklist.check('1.1.1.2')); |
283 | 283 | assert(!blocklist.check('2.3.4.5')); |
284 | 284 | } |
| 285 | + |
| 286 | +{ |
| 287 | + assert(BlockList.isBlockList(new BlockList())); |
| 288 | + assert(!BlockList.isBlockList({})); |
| 289 | +} |