mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2025-03-08 03:24:48 +01:00
[refactor] Moved isValidIPAddress
to its own TS file
This commit is contained in:
@ -3,7 +3,7 @@ import {Player} from "./Player";
|
||||
import {SpecialServerIps} from "./SpecialServerIps";
|
||||
import {post} from "./Terminal";
|
||||
|
||||
import {isValidIPAddress} from "../utils/IPAddress";
|
||||
import {isValidIPAddress} from "../utils/helpers/isValidIPAddress";
|
||||
import {formatNumber} from "../utils/StringHelperFunctions";
|
||||
|
||||
|
||||
|
@ -10,7 +10,7 @@ import {Script, findRunningScript,
|
||||
|
||||
import {parse, Node} from "../utils/acorn";
|
||||
import {printArray} from "../utils/HelperFunctions";
|
||||
import {isValidIPAddress} from "../utils/IPAddress";
|
||||
import {isValidIPAddress} from "../utils/helpers/isValidIPAddress";
|
||||
import {isString} from "../utils/helpers/isString";
|
||||
|
||||
var Promise = require("bluebird");
|
||||
|
@ -5,9 +5,10 @@ import {Player} from "./Player";
|
||||
import {RunningScript, Script} from "./Script";
|
||||
import {SpecialServerNames, SpecialServerIps} from "./SpecialServerIps";
|
||||
import {getRandomInt} from "../utils/helpers/getRandomInt";
|
||||
import {createRandomIp, isValidIPAddress, ipExists} from "../utils/IPAddress";
|
||||
import {createRandomIp, ipExists} from "../utils/IPAddress";
|
||||
import {Reviver, Generic_toJSON,
|
||||
Generic_fromJSON} from "../utils/JSONReviver";
|
||||
import {isValidIPAddress} from "../utils/helpers/isValidIPAddress";
|
||||
|
||||
function Server(params={ip:createRandomIp(), hostname:""}) {
|
||||
/* Properties */
|
||||
|
@ -30,12 +30,4 @@ function ipExists(ip) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function isValidIPAddress(ipaddress) {
|
||||
if (/^(25[0-6]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-6]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-6]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-6]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipaddress))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export {createRandomIp, ipExists, isValidIPAddress};
|
||||
export {createRandomIp, ipExists};
|
||||
|
12
utils/helpers/isValidIPAddress.ts
Normal file
12
utils/helpers/isValidIPAddress.ts
Normal file
@ -0,0 +1,12 @@
|
||||
|
||||
/**
|
||||
* Checks whether a IP Address string is valid.
|
||||
* @param ipaddress A string representing a potential IP Address
|
||||
*/
|
||||
export function isValidIPAddress(ipaddress: string) {
|
||||
const byteRange: string = "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)";
|
||||
const regexStr: string = `^${byteRange}\.${byteRange}\.${byteRange}\.${byteRange}$`;
|
||||
const ipAddressRegex: RegExp = new RegExp(regexStr);
|
||||
|
||||
return ipAddressRegex.test(ipaddress);
|
||||
}
|
Reference in New Issue
Block a user