Options
All
  • Public
  • Public/Protected
  • All
Menu

Module source/ip

Index

Variables

Variables

Const ip

ip: { expression: (global?: boolean) => RegExp; isValid: (addr: string) => boolean; remove: (str: string) => string; retrieve: (str: string) => string[]; swap: (str: string, newStr: string) => string } = ...

Type declaration

  • expression: (global?: boolean) => RegExp
      • (global?: boolean): RegExp
      • Returns regular expression used to find and verify IP addresses

        Basic usage example:

        import {ip} from 'stringman'; // or const ip = require('stringman').ip;
        const expGlobal = ip.expression(true);
        const exp = ip.expression();
        console.log(expGlobal); //  /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?$)/g
        console.log(exp); //  /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?$)/
        

        Parameters

        • Optional global: boolean

        Returns RegExp

  • isValid: (addr: string) => boolean
      • (addr: string): boolean
      • Tests if argument is valid IP address and return boolean

        Basic usage example:

        import {ip} from 'stringman'; // or const ip = require('stringman').ip;
        const valid = ip.isValid('192.168.0.1');
        const invalid = ip.isValid('192.168.0.256');
        console.log(valid); // true
        console.log(invalid); // false
        

        Parameters

        • addr: string

        Returns boolean

  • remove: (str: string) => string
      • (str: string): string
      • Takes a string and returns the string with all valid IP addresses removed

        Basic usage example:

        import {ip} from 'stringman'; // or const ip = require('stringman').ip;
        const removed = ip.remove('my router is at 192.168.0.1');
        console.log(removed); // 'my router is at'
        

        Parameters

        • str: string

        Returns string

  • retrieve: (str: string) => string[]
      • (str: string): string[]
      • Gets any and all valid IP addresses from a string and returns in array

        Basic usage example:

        import {ip} from 'stringman'; // or const ip = require('stringman').ip;
        const ips = ip.retrieve('my router is at 192.168.0.1');
        console.log(ips); // ['192.168.0.1'];
        

        Parameters

        • str: string

        Returns string[]

  • swap: (str: string, newStr: string) => string
      • (str: string, newStr: string): string
      • Takes a string with an IP and another string and returns the first string with all IP addresses swapped with the second string

        Basic usage example:

        import {ip} from 'stringman'; // or const ip = require('stringman').ip;
        const swapped = ip.swap('my router is at 192.168.0.1', '***.***.***.***');
        console.log(swapped); // 'my router is at ***.***.***.***'
        

        Parameters

        • str: string
        • newStr: string

        Returns string

Generated using TypeDoc