🤖 Merge PR #65900 netmask: constructor accepts string+number by @yoursunny

This commit is contained in:
Junxiao Shi
2023-06-28 09:47:21 -04:00
committed by GitHub
parent 10a8a995fc
commit 0cbd113e3f
2 changed files with 6 additions and 2 deletions

View File

@@ -2,6 +2,7 @@
// Project: https://github.com/rs/node-netmask
// Definitions by: Matt Frantz <https://github.com/mhfrantz>
// JanST123 <https://github.com/JanST123>
// Junxiao Shi <https://github.com/yoursunny>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/**
@@ -74,5 +75,5 @@ export class Netmask {
* @param net A network - e.g 216.240.32.0/24
* @param mask - optional netmask if not provided in `net`
*/
constructor(net: string, mask?: string);
constructor(net: string, mask?: string | number);
}

View File

@@ -1,12 +1,15 @@
import netmask = require('netmask');
const block = new netmask.Netmask('10.0.0.0/12');
let block = new netmask.Netmask('10.0.0.0/12');
console.log('base', block.base);
if (block.contains('10.0.8.10')) {
console.log('block contains 10.0.8.10');
}
block = new netmask.Netmask('216.240.32.0', '255.255.255.0');
block = new netmask.Netmask('216.240.32.0', 24);
class CustomizedNetmask extends netmask.Netmask {
// Test that we can override `next` to return a CustomizedNetmask (as opposed to netmask.Netmask) object
next(count: number = 1): CustomizedNetmask {