Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 7 Examples of "parcel in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'parcel' 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.

static _parseParcelInfo(data) {
    const transitionMap = {
      'parcel.height': 'measurements.heightInMillimeter',
      'parcel.length': 'measurements.lengthInMillimeter',
      'parcel.width': 'measurements.widthInMillimeter',
      'parcel.weight': 'measurements.weightInGram',
      'parcel.trackingId': 'trackingData.trackingId',
      'parcel.providerTransaction': 'trackingData.providerTransaction',
      'parcel.provider': 'trackingData.provider',
      'parcel.carrier': 'trackingData.carrier',
      'parcel.isReturn': 'trackingData.isReturn',
      'parcel.items': 'items',
    }

    const parcel = {
      id: data['parcel.id'],
    }

    // Build parcel object
    Object.keys(data).forEach(fieldName => {
      if (!transitionMap[fieldName]) return

      // All values are loaded as a string
      let fieldValue = data[fieldName]

      // do not set empty values
      if (fieldValue === '') return

      // Cast measurements to Number
      if (/^measurements/.test(transitionMap[fieldName]))
        fieldValue = Number(fieldValue)
// Basic delivery object with delivery item
    const delivery = {
      id: data['delivery.id'],
      items: [
        {
          // there can be multiple delivery items with same item.id and
          // item.quantity therefore we use unique identifier _itemGroupId
          _groupId: data._itemGroupId,
          id: data['item.id'],
          quantity: parseInt(data['item.quantity'], 10),
        },
      ],
    }

    // Add parcel info if it is present
    if (data['parcel.id']) {
      const parcel = DeliveriesParser._parseParcelInfo(data)

      if (parcel.measurements && Object.keys(parcel.measurements).length !== 4)
        return Promise.reject(new Error('All measurement fields are mandatory'))

      delivery.parcels = [parcel]
    }

    const order = {
      orderNumber: data.orderNumber,
      shippingInfo: {
        deliveries: [delivery],
      },
    }
    return Promise.resolve(order)
  }
function getPageFiles({dir, config, isClient, entrypoint}) {
  let result = []
  if(entrypoint) {
    if(isClient) {
      result = glob.sync(`pages(_app|_error).+(${config.pageExtensions.join('|')})`, { cwd: dir, absolute: true })      
    } else {
      result = glob.sync(`pages(_document|_app|_error).+(${config.pageExtensions.join('|')})`, { cwd: dir, absolute: true })            
    }
    result = [...result, ...glob.sync(entrypoint, { cwd: dir, absolute: true })]
  } else {
    result = glob.sync(`pages/**/${isClient ? '!(_document)' : ''}*.+(${config.pageExtensions.join('|')})`, { cwd: dir, absolute: true })
  }
  const appPath = path.join(dir, 'pages', '_app.js')
  if(!result.some((item) => item === appPath)) {
    result.push(require.resolve('next/dist/pages/_app.js'))
  }

  const errorPath = path.join(dir, 'pages', '_error.js')
  if(!result.some((item) => item === errorPath)) {
    result.push(require.resolve('next/dist/pages/_error.js'))
  }
function getPageFiles({dir, config, isClient, entrypoint}) {
  let result = []
  if(entrypoint) {
    if(isClient) {
      result = glob.sync(`pages(_app|_error).+(${config.pageExtensions.join('|')})`, { cwd: dir, absolute: true })      
    } else {
      result = glob.sync(`pages(_document|_app|_error).+(${config.pageExtensions.join('|')})`, { cwd: dir, absolute: true })            
    }
    result = [...result, ...glob.sync(entrypoint, { cwd: dir, absolute: true })]
  } else {
    result = glob.sync(`pages/**/${isClient ? '!(_document)' : ''}*.+(${config.pageExtensions.join('|')})`, { cwd: dir, absolute: true })
  }
  const appPath = path.join(dir, 'pages', '_app.js')
  if(!result.some((item) => item === appPath)) {
    result.push(require.resolve('next/dist/pages/_app.js'))
  }

  const errorPath = path.join(dir, 'pages', '_error.js')
  if(!result.some((item) => item === errorPath)) {
    result.push(require.resolve('next/dist/pages/_error.js'))
  }

  if(!isClient) {
    const documentPath = path.join(dir, 'pages', '_document.js')
    if(!result.some((item) => item === documentPath)) {
function getPageFiles({dir, config, isClient, entrypoint}) {
  let result = []
  if(entrypoint) {
    if(isClient) {
      result = glob.sync(`pages(_app|_error).+(${config.pageExtensions.join('|')})`, { cwd: dir, absolute: true })      
    } else {
      result = glob.sync(`pages(_document|_app|_error).+(${config.pageExtensions.join('|')})`, { cwd: dir, absolute: true })            
    }
    result = [...result, ...glob.sync(entrypoint, { cwd: dir, absolute: true })]
  } else {
    result = glob.sync(`pages/**/${isClient ? '!(_document)' : ''}*.+(${config.pageExtensions.join('|')})`, { cwd: dir, absolute: true })
  }
  const appPath = path.join(dir, 'pages', '_app.js')
  if(!result.some((item) => item === appPath)) {
    result.push(require.resolve('next/dist/pages/_app.js'))
  }

  const errorPath = path.join(dir, 'pages', '_error.js')
  if(!result.some((item) => item === errorPath)) {
    result.push(require.resolve('next/dist/pages/_error.js'))
  }

  if(!isClient) {
function getPageFiles({dir, config, isClient, entrypoint}) {
  let result = []
  if(entrypoint) {
    if(isClient) {
      result = glob.sync(`pages(_app|_error).+(${config.pageExtensions.join('|')})`, { cwd: dir, absolute: true })      
    } else {
      result = glob.sync(`pages(_document|_app|_error).+(${config.pageExtensions.join('|')})`, { cwd: dir, absolute: true })            
    }
    result = [...result, ...glob.sync(entrypoint, { cwd: dir, absolute: true })]
  } else {
    result = glob.sync(`pages/**/${isClient ? '!(_document)' : ''}*.+(${config.pageExtensions.join('|')})`, { cwd: dir, absolute: true })
  }
  const appPath = path.join(dir, 'pages', '_app.js')
  if(!result.some((item) => item === appPath)) {
    result.push(require.resolve('next/dist/pages/_app.js'))
  }

  const errorPath = path.join(dir, 'pages', '_error.js')
  if(!result.some((item) => item === errorPath)) {
    result.push(require.resolve('next/dist/pages/_error.js'))
  }

  if(!isClient) {
    const documentPath = path.join(dir, 'pages', '_document.js')
    if(!result.some((item) => item === documentPath)) {
      result.push(require.resolve('next/dist/pages/_document.js'))
    }
function getAssetClass() {
  try {
    return require('parcel').Asset;
  } catch (e) {
    return require('parcel-bundler').Asset;
  }
}

Is your System Free of Underlying Vulnerabilities?
Find Out Now