Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "type-check in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'type-check' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

function readJson (file) {
  if (!check('String', file)) return
  if (file.slice(-5) !== '.json') {
    console.log(chalk.red(`\n${chalk.bold('AppVersion:')} ${file} is not a Json\n`))
    process.exit(1)
  }
  try {
    let obj = require(file === JSON_FILE ? resolve('./', file) : resolve(file))
    // checks if the appversion.json is at the latest version
    if (file === JSON_FILE && (!obj.config || obj.config.appversion !== apvVersion)) obj = updateAppversion(obj)
    return obj
  } catch (err) {
    if (err.code === 'MODULE_NOT_FOUND') {
      console.log(chalk.red(`\n${chalk.bold('AppVersion:')} Could not find appversion.json\nType ${chalk.bold('\'apv init\'')} for generate the file and start use AppVersion.\n`))
      process.exit(1)
    } else {
      throw new Error(err)
    }
function setStatus (param) {
  if (!check('String', param)) return
  let obj = readJson(JSON_FILE)
  let previousObj = {
    status: {
      stage: obj.status.stage,
      number: obj.status.number
    }
  }
  let status = param.split('.')
  if (status[1] && !check('Number', Number(status[1]))) {
    console.log(chalk.red(`\n${chalk.bold('AppVersion:')} Insert a valid status.number number\n`))
    return
  }
  let match = ['Stable', 'stable', 'RC', 'rc', 'Beta', 'beta', 'Alpha', 'alpha']
  if (match.indexOf(status[0]) === -1) {
    console.log(chalk.red(`\n${chalk.bold('AppVersion:')} Insert a valid status.stage string\n`))
    return
  }
  obj.status.stage = status[0]
  // if there's not the status number, it's setted to zero
  obj.status.number = Number(status[1]) || 0
  writeJson(obj, chalk.green(`\n${chalk.bold('AppVersion:')} Status updated to ${status[0]}.${status[1] || 0}\n`))
  createBadge('status', true, previousObj)
}
function createLogger(prefix) {
  check(prefix, String);

  // Return noop if logging is disabled.
  if(Migrations.options.log === false) {
    return function() {};
  }

  return function(level, ...args) {
    //check(level, Match.OneOf('info', 'error', 'warn', 'debug'));
    var logger = Migrations.options && Migrations.options.logger;

    if(logger && _.isFunction(logger)) {

      logger({level, ...args });

    } else {
      console[level]({ level, ...args });
export const checkParamOrThrow = (value, name, type, message) => {
    if (!message) message = `Parameter "${name}" of type ${type} must be provided`;

    const allowedTypes = parseType(type);

    const allowsBuffer = allowedTypes.filter(item => item.type === 'Buffer').length;
    const allowsPromise = allowedTypes.filter(item => item.type === 'Promise').length;

    if (allowsBuffer && Buffer.isBuffer(value)) return;
    if (allowsPromise && typeof value.then === 'function') return;

    // This will ignore Buffer type.
    if (!parsedTypeCheck(allowedTypes, value)) throw new Error(message);
};
export const checkParamOrThrow = (value, name, type, message) => {
    if (!message) message = `Parameter "${name}" of type ${type} must be provided`;

    const allowedTypes = parseType(type);

    const allowsBuffer = allowedTypes.filter(item => item.type === 'Buffer').length;
    const allowsPromise = allowedTypes.filter(item => item.type === 'Promise').length;

    if (allowsBuffer && Buffer.isBuffer(value)) return;
    if (allowsPromise && typeof value.then === 'function') return;

    // This will ignore Buffer type.
    if (!parsedTypeCheck(allowedTypes, value)) throw new Error(message);
};
function composePattern (pattern, callback) {
  if (!check('String', pattern)) throw new Error('composePattern() -> pattern is not a string')
  if (!check('Function', callback)) throw new Error('composePattern() -> callback is not a function')
  pattern = pattern.split('')
  getAppVersion((err, obj) => {
    if (err) console.log(err)
    let ptt = ''
    pattern.map((ele) => {
      ptt += switchPattern(obj, ele)
    })
    callback(ptt)
  })
}
input.pages.forEach(page => {
                if (!typeCheck(PAGE_INPUT_TYPE, page) && !isSinglePageInput) {
                    log('Expected input:');
                    log(INPUT_TYPE);
                    log('Received input:');
                    console.dir(input);
                    throw new Error('Received invalid input');
                }
            });
        } else if (isSinglePageInput) {
function switchPattern (obj, pattern) {
  if (!check('String', pattern)) throw new Error('switchPattern() -> pattern is not a string')
  if (!check('Object', obj)) throw new Error('switchPattern() -> obj is not an object')
  switch (pattern) {
    case 'M' || 'B':
      return obj.version.major
    case 'm' || 'F':
      return obj.version.minor
    case 'p' || 'f':
      return obj.version.patch
    case 'S':
      return obj.status.stage
    case 's':
      return obj.status.number
    case 'n':
      return obj.build.number
    case 't':
      return obj.build.total
module.exports.middleware = (req, res, next) => {
  if (!typeCheck('Object', req)) {
    throw new ErrorWrapper('req argument wrong type', 500)
  }
  if (!typeCheck('Object', res)) {
    throw new ErrorWrapper('res argument wrong type', 500)
  }
  if (next && !typeCheck('Function', next)) {
    throw new ErrorWrapper('next  argument wrong type', 500)
  }
}
module.exports.main = (argument, type, required) => {
  /**
   * check if required
   */
  if (required && !argument) {
    throw new ErrorWrapper('Required parameters not supplied', 500)
  }
  /**
   * check arguments type
   */
  const isArgumentExist = [null, false, NaN].includes(argument) || argument
  if (isArgumentExist && !typeCheck(type, argument)) {
    throw new ErrorWrapper('Argument wrong type', 500)
  }
}

Is your System Free of Underlying Vulnerabilities?
Find Out Now