process#emitWarning TypeScript Examples

The following examples show how to use process#emitWarning. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: windows.ts    From pingman with MIT License 6 votes vote down vote up
//Checking for windows IPV4 fields as per official documentation
function checkForIpV4SpecificFields(options: extendedPingOptions): Array<string> {
    let optionsUsed: string = "";
    let args: Array<string> = [];
    if (options?.IPV4) {
        args.push('-4');
        if (options.doNotFragment) {
            args.push('-f');
        }
        if (typeof options?.recordRouteHops === 'number') {
            args.push('-r', options.recordRouteHops.toString())
        }
        if (typeof options?.hopTimestamp === 'number') {
            args.push('-s', options.hopTimestamp.toString())
        }
    } else {
        if (options.doNotFragment) {
            optionsUsed = optionsUsed.concat(',', options.doNotFragment.toString())
        }
        if (options.recordRouteHops) {
            optionsUsed = optionsUsed.concat(',', options.recordRouteHops.toString())
        }
        if (options.hopTimestamp) {
            optionsUsed = optionsUsed.concat(',', options.hopTimestamp.toString())
        }
        if (optionsUsed.length > 0) {
            emitWarning(ERROR_MESSAGES.ENABLE_IPV4_EXPLICIT.replace('commands', optionsUsed), 'IPV4OnlyWarning');
        }
    }
    return args;
}
Example #2
Source File: windows.ts    From pingman with MIT License 6 votes vote down vote up
//Checking for windows IPV6 fields as per official documentation
function checkForIpV6SpecificFields(options: extendedPingOptions): Array<string> {
    let optionsUsed: string = "";
    let args: Array<string> = [];
    if (options?.IPV6) {
        args.push('-6');
        if (options.srcAddr) {
            args.push('-S', options.srcAddr);
        }
    } else {
        if (typeof options.srcAddr === 'string') {
            optionsUsed = optionsUsed.concat(',', options.srcAddr)
        }
        if (optionsUsed.length > 0) {
            emitWarning(ERROR_MESSAGES.ENABLE_IPV6_EXPLICIT.replace('commands', optionsUsed), 'IPV6OnlyWarning');
        }
    }
    return args;
}
Example #3
Source File: linux.ts    From pingman with MIT License 5 votes vote down vote up
linux = (ip: string, options?: extendedPingOptions): commandBuilder => {
   let defaultNumberOfEchoes = '4';
   let args: Array<string> = [];
   let buildCommand: commandBuilder = {
      command: 'ping',
      arguments: args
   };
   //NO Allowing Unsanitized user input into spawn.Checking each param and assigning
   if (!options) {
      buildCommand.arguments.push('-c', defaultNumberOfEchoes);
      args.push(ip);
      return buildCommand;
   }
   if (typeof options?.numberOfEchos === 'number') {
      args.push('-c', options.numberOfEchos.toString());
   } else {
      args.push('-c', defaultNumberOfEchoes);
   }
   if (options?.soDebugOption) {
      args.push('-d');
   }
   if (typeof options?.interval === 'number') {
      if (options?.floodPing) {
         args.push('-f');
         emitWarning(ERROR_MESSAGES.FLOOD_AND_INTERVAL_ARGS, 'argumentWarning');//Catch the warning and process it
      } else {
         args.push('-i', options?.interval.toString())
      }
   }
   if (options?.floodPing) {
      if (typeof options?.interval === 'number') {
         args.push('-i', options?.interval.toString())
         emitWarning(ERROR_MESSAGES.FLOOD_AND_INTERVAL_ARGS, 'argumentWarning');
      } else {
         args.push('-f');
      }
   }
   if (typeof options?.interfaceAddress === 'string') {
      args.push('-I', options.interfaceAddress);
   }
   if (options?.suppressLoopback) {
      args.push('-L');
   }
   if (typeof options?.TTL === 'number') {
      args.push('-t', options.TTL.toString());
   }
   if (options?.numeric) {
      args.push('-n');
   }
   if (typeof options?.pattern === 'string') {
      args.push('-p', options.pattern);
   }
   if (options?.quiet) {
      args.push('-q');
   }
   if (typeof options?.bufferSize === 'number') {
      args.push('-s', options.bufferSize.toString())
   }
   if (typeof options?.timeBeforeExit === 'number') {
      args.push('-W', options.timeBeforeExit.toString());
   }
   if (options?.verboseOutput) {
      args.push('-v')
   }
   if (typeof options?.timeout === 'number') {
      args.push('-w', options.timeout.toString())
   }
   if (options?.IPV6) {
      buildCommand.command = 'ping6'
   }
   args.push(ip);
   buildCommand.arguments = args;
   return buildCommand;
}
Example #4
Source File: mac.ts    From pingman with MIT License 5 votes vote down vote up
mac = (ip: string, options?: extendedPingOptions): commandBuilder => {
    let defaultNumberOfEchoes = '4'; //default needed because mac by default has continous ping till we cancel
    let args: Array<string> = [];
    let buildCommand: commandBuilder = {
        command: '/sbin/ping',
        arguments: args
    };
    //NO Allowing Unsanitized user input into spawn.Checking each param and assigning
    if (!options) {
        buildCommand.arguments.push('-c', defaultNumberOfEchoes);
        args.push(ip);
        return buildCommand;
    }
    if (typeof options?.numberOfEchos === 'number') {
        args.push('-c', options.numberOfEchos.toString());
    } else {
        args.push('-c', defaultNumberOfEchoes);
    }
    if (options?.soDebugOption) {
        args.push('-d');
    }
    if (typeof options?.interval === 'number') {
        if (options?.floodPing) {
            args.push('-f');
            emitWarning(ERROR_MESSAGES.FLOOD_AND_INTERVAL_ARGS, 'argumentWarning');
        } else {
            args.push('-i', options?.interval.toString())
        }
    }
    if (options?.floodPing) {
        if (typeof options?.interval === 'number') {
            args.push('-i', options?.interval.toString())
        } else {
            args.push('-f');
            emitWarning(ERROR_MESSAGES.FLOOD_AND_INTERVAL_ARGS, 'argumentWarning');
        }
    }
    if (typeof options?.interfaceAddress === 'string') {
        args.push('-I', options.interfaceAddress);
    }
    if (options?.suppressLoopback) {
        args.push('-L');
    }
    if (typeof options?.TTL === 'number') {
        args.push('-m', options.TTL.toString()); //change to -t for linux
    }
    if (options.doNotFragment) {
        args.push('-D');
    }
    if (options?.numeric) {
        args.push('-n');
    }
    if (typeof options?.pattern === 'string') {
        args.push('-p', options.pattern);
    }
    if (options?.quiet) {
        args.push('-q');
    }
    if (typeof options?.srcAddr === 'string') {
        args.push('-S', options.srcAddr); //Delete for Linux
    }
    if (typeof options?.bufferSize === 'number') {
        args.push('-s', options.bufferSize.toString())
    }
    if (typeof options?.timeBeforeExit === 'number') {
        args.push('-t', options.timeBeforeExit.toString()) //change to -w for linux
    }
    if (options?.verboseOutput) {
        args.push('-v')
    }
    if (typeof options?.timeout === 'number') {
        args.push('-W', (options.timeout * 1000).toString())
    }
    if (options?.IPV6) {
        buildCommand.command = '/sbin/ping6'
    }
    args.push(ip);
    buildCommand.arguments = args;
    return buildCommand;
}