How to use the bytes.format function in bytes

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 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 vicanso / diving / web / src / App.js View on Github external
},
      {
        name: imageSizeName,
        title:
          "Image size and file type proportion(Text, Image, Document, Compression, Others)",
        value: bytes.format(basicInfo.sizeBytes)
      },
      {
        name: userSizeName,
        title: "All bytes except for the base image",
        value: bytes.format(basicInfo.userSizeBytes)
      },
      {
        name: wastedSizeName,
        title: "All bytes of remove or duplicate files",
        value: bytes.format(basicInfo.wastedBytes)
      }
    ];
    const renderEfficiencyScoreProgress = item => {
      if (item.name !== efficiencyScoreName) {
        return;
      }
      return (
github TrySound / rollup-plugin-size-snapshot / src / index.js View on Github external
const formatSize = d => chalk.bold(bytes.format(d, bytesConfig));
github egoist / npm-size / lib / cli.js View on Github external
)}`
        }

        const { size, prettySize } = result

        const sizeLimit = options.limit && bytes.parse(options.limit)
        const exceededSizeLimit = size > sizeLimit
        if (exceededSizeLimit) {
          process.exitCode = 1
        }

        return exceededSizeLimit
          ? `${padRight(names[index], maxLength)} ${colors.red(
              prettySize
            )} ${colors.red(
              `(limit: ${bytes.format(sizeLimit, {
                unitSeparator: ' '
              })})`
            )}`
          : `${padRight(names[index], maxLength)} ${colors.green(prettySize)}`
      }
github ai / size-limit / old / cli-body.js View on Github external
function formatBytes (size) {
  return bytes.format(size, { unitSeparator: ' ' })
}
github ehmicky / autoserver / src / config / reducers / limits.js View on Github external
const validateMaxpayload = function({ maxpayload, minMaxpayload }) {
  const maxpayloadA = parseBytes(maxpayload)

  if (maxpayloadA === null || Number.isNaN(maxpayloadA)) {
    const message =
      '\'config.limits.maxpayload\' must be a size in bytes, which can include "B", "KB", "MB", "GB" or "TB"'
    throwError(message, { reason: 'CONFIG_VALIDATION' })
  }

  if (maxpayloadA < minMaxpayload) {
    const minMaxpayloadA = formatBytes(minMaxpayload)
    const message = `'config.limits.maxpayload' must be at least ${minMaxpayloadA}`
    throwError(message, { reason: 'CONFIG_VALIDATION' })
  }
}

bytes

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

MIT
Latest version published 3 years ago

Package Health Score

74 / 100
Full package analysis

Popular bytes functions