How to use bytes - 10 common examples

To help you get started, we’ve selected a few bytes examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github beakerbrowser / hashbase / lib / apis / users.js View on Github external
} catch (err) {
        console.error('Failed to setup pro plain!', userRecord, err)
        var message = err.message
        if (err.code === 'card_declined') {
          message = 'Oh dear! Your card was declined. Please check the card information and try again.'
        }
        if (!message) {
          message = 'Failed to create an account with Stripe. Try again or contact support.'
        }
        throw new BadRequestError(message)
      }

      // update local records
      this.usersDB.update(userRecord.id, {
        plan: 'pro',
        diskQuota: bytes.parse(this.config.proDiskUsageLimit),
        namedArchiveQuota: this.config.proNamedArchivesLimit,
        stripeCustomerId: customerId,
        stripeSubscriptionId: subscription.id,
        stripeTokenId: token.id,
        stripeCardId: token.card.id,
        stripeCardBrand: token.card.brand,
        stripeCardCountry: token.card.country,
        stripeCardCVCCheck: token.card.cvc_check,
        stripeCardExpMonth: token.card.exp_month,
        stripeCardExpYear: token.card.exp_year,
        stripeCardLast4: token.card.last4
      })
    } finally {
      release()
    }
  }
github adaptlearning / adapt_authoring / plugins / output / adapt / importsource.js View on Github external
form.parse(req, function (error, fields, files) {
          if(error) {
            if (form.bytesExpected > form.maxFileSize) {
              return cb2(new Error(app.polyglot.t('app.uploadsizeerror', {
                max: bytes.format(form.maxFileSize),
                size: bytes.format(form.bytesExpected)
              })));
            }
            return cb2(error);
          }
          var formAssetDirs = (fields.formAssetFolders && fields.formAssetFolders.length) ? fields.formAssetFolders.split(',') : [];
          formTags = (fields.tags && fields.tags.length) ? fields.tags.split(',') : [];
          cleanFormAssetDirs = formAssetDirs.map(item => item.trim());
          // upzip the uploaded file
          helpers.unzip(files.file.path, COURSE_ROOT_FOLDER, function(error) {
            if(error) return cb2(error);
            cleanupDirs.push(files.file.path, COURSE_ROOT_FOLDER);
            cb2();
          });
        });
      }
github adaptlearning / adapt_authoring / plugins / output / adapt / importsourcecheck.js View on Github external
form.parse(req, function (error, fields, files) {
          if(error) {
            if (form.bytesExpected > form.maxFileSize) {
              return cb2(new Error(app.polyglot.t('app.uploadsizeerror', {
                 max: bytes.format(form.maxFileSize),
                 size: bytes.format(form.bytesExpected)
              })));
            }
            return cb2(error);
          }
          var formAssetDirs = (fields.formAssetFolders && fields.formAssetFolders.length) ? fields.formAssetFolders.split(',') : [];
          importInfo['formTags'] = (fields.tags && fields.tags.length) ? fields.tags.split(',') : [];
          cleanFormAssetDirs = formAssetDirs.map(item => item.trim());

          // clear any previous import files
          fs.emptyDir(COURSE_ROOT_FOLDER, function(error) {
            if(error) return cb2(error);
            // upzip the uploaded file
            logger.log('info', 'unzipping');
            logger.log('info', COURSE_ROOT_FOLDER);
            logger.log('info', files.file.path)
github qgustavor / direct-mega / src / splitter.js View on Github external
function handleSubmit (evt) {
  evt.preventDefault()

  const url = form.elements.url.value.trim()
    // Accept URLs without protocol
    .replace(/^(?!https?:\/\/)/i, 'https://')
    // Accept Direct MEGA URL input
    .replace(/https?:\/\/directme.ga\/(?:view)?[?#]([^&]+)/i, 'https://mega.nz/#$1')
    // Normalize mega.co.nz to mega.nz
    .replace('https://mega.co.nz/', 'https://mega.nz/')

  const size = bytes.parse(form.elements.size.value.trim())

  // Show that's possible loading from the hash
  window.location.hash = url

  output.textContent = 'Loading file info...'

  splitFromURL(url, size).then(result => {
    if (result.folder) {
      const list = document.createElement('ul')
      const files = createFileList(result.folder)
      for (let {file, filePath} of files) {
        const li = document.createElement('li')
        const anchor = document.createElement('a')
        anchor.textContent = filePath
        anchor.href = '#' + url + '!' + file.downloadId[1]
        anchor.addEventListener('click', handleFileClick)
github joshlobaptista / Barista-Fullstack / node_modules / body-parser / lib / types / urlencoded.js View on Github external
function urlencoded (options) {
  var opts = options || {}

  // notice because option default will flip in next major
  if (opts.extended === undefined) {
    deprecate('undefined extended: provide extended option')
  }

  var extended = opts.extended !== false
  var inflate = opts.inflate !== false
  var limit = typeof opts.limit !== 'number'
    ? bytes.parse(opts.limit || '100kb')
    : opts.limit
  var type = opts.type || 'application/x-www-form-urlencoded'
  var verify = opts.verify || false

  if (verify !== false && typeof verify !== 'function') {
    throw new TypeError('option verify must be function')
  }

  // create the appropriate query parser
  var queryparse = extended
    ? extendedparser(opts)
    : simpleparser(opts)

  // create the appropriate type checking function
  var shouldParse = typeof type !== 'function'
    ? typeChecker(type)
github jamesshore / lets_code_javascript / node_modules / karma / node_modules / connect / node_modules / body-parser / lib / types / json.js View on Github external
function json(options) {
  var opts = options || {}

  var limit = typeof opts.limit !== 'number'
    ? bytes.parse(opts.limit || '100kb')
    : opts.limit
  var inflate = opts.inflate !== false
  var reviver = opts.reviver
  var strict = opts.strict !== false
  var type = opts.type || 'application/json'
  var verify = opts.verify || false

  if (verify !== false && typeof verify !== 'function') {
    throw new TypeError('option verify must be function')
  }

  // create the appropriate type checking function
  var shouldParse = typeof type !== 'function'
    ? typeChecker(type)
    : type
github expressjs / body-parser / lib / types / json.js View on Github external
function json (options) {
  var opts = options || {}

  var limit = typeof opts.limit !== 'number'
    ? bytes.parse(opts.limit || '100kb')
    : opts.limit
  var inflate = opts.inflate !== false
  var reviver = opts.reviver
  var strict = opts.strict !== false
  var type = opts.type || 'application/json'
  var verify = opts.verify || false

  if (verify !== false && typeof verify !== 'function') {
    throw new TypeError('option verify must be function')
  }

  // create the appropriate type checking function
  var shouldParse = typeof type !== 'function'
    ? typeChecker(type)
    : type
github bundlewatch / bundlewatch / src / app / analyze / analyzeFiles / index.js View on Github external
uniqueFilePaths.forEach(filePath => {
        const currentBranchFile = currentBranchFileDetails[filePath]
        const baseBranchFile = baseBranchFileDetails[filePath]

        if (!currentBranchFile) {
            // baseBranchFile must exist
            results.push({
                filePath,
                message: `${filePath}: File removed (${bytes(
                    baseBranchFile.size,
                )} smaller than ${baseBranchName}) ${getCompressionText(
                    baseBranchFile.compression,
                )}`,
                status: STATUSES.REMOVED,
                size: 0,
                baseBranchSize: baseBranchFile.size,
                maxSize: 0,
            })
            return
        }

        if (currentBranchFile.error) {
            results.push({
                filePath,
                error: currentBranchFile.error,
github MainframeHQ / onyx / src / components / Conversation.js View on Github external
) : (
        
          
          
          
        
      )
    ) : null

    let textBlock = null
    const text =
      blocks.MessageBlockText && // $FlowFixMe
      blocks.MessageBlockText.map(b => b.text).join('\n')
    if (text != null) {
      textBlock = 
    }

    const openProfile = () => {
      onPressProfile(profile)
github zeit / now / packages / now-cli / src / util / index.js View on Github external
deployment.warnings.forEach(warning => {
        if (warning.reason === 'size_limit_exceeded') {
          const { sha, limit } = warning;
          const n = hashes.get(sha).names.pop();

          warn(`Skipping file ${n} (size exceeded ${bytes(limit)}`);

          hashes.get(sha).names.unshift(n); // Move name (hack, if duplicate matches we report them in order)
          sizeExceeded++;
        } else if (warning.reason === 'node_version_not_found') {
          warn(`Requested node version ${warning.wanted} is not available`);
          missingVersion = true;
        }
      });

bytes

Utility to parse a string bytes to bytes and vice-versa

MIT
Latest version published 2 years ago

Package Health Score

77 / 100
Full package analysis

Popular bytes functions