How to use the @build-tracker/types.BudgetType.PERCENT_DELTA function in @build-tracker/types

To help you get started, we’ve selected a few @build-tracker/types 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 paularmstrong / build-tracker / src / formatting / src / index.ts View on Github external
export function formatBudgetResult(budgetResult: BudgetResult, itemName: string, useEmoji: boolean = false): string {
  const { actual, expected, level, sizeKey, type } = budgetResult;
  const actualFormatted = type === BudgetType.PERCENT_DELTA ? formatPercent(actual) : formatBytes(actual);
  const expectedFormatted = type === BudgetType.PERCENT_DELTA ? formatPercent(expected) : formatBytes(expected);
  const diffFormatted =
    type === BudgetType.PERCENT_DELTA ? formatPercent(actual - expected) : formatBytes(actual - expected);

  const prefix = `${(useEmoji ? levelToEmoji : levelToString)[level]}: \`${itemName}\``;

  switch (type) {
    case BudgetType.DELTA:
      return `${prefix} failed the ${sizeKey} budget delta limit. Expected to increase no more than ${expectedFormatted}, but increased by ${actualFormatted}`;
    case BudgetType.PERCENT_DELTA:
      return `${prefix} failed the ${sizeKey} budget percent change limit. Expected no increase by no more than ${expectedFormatted}, but increased by ${actualFormatted}`;
    case BudgetType.SIZE:
      return `${prefix} failed the ${sizeKey} budget size limit of ${expectedFormatted} by ${diffFormatted}`;
  }
}
github paularmstrong / build-tracker / src / formatting / src / index.ts View on Github external
export function formatBudgetResult(budgetResult: BudgetResult, itemName: string, useEmoji: boolean = false): string {
  const { actual, expected, level, sizeKey, type } = budgetResult;
  const actualFormatted = type === BudgetType.PERCENT_DELTA ? formatPercent(actual) : formatBytes(actual);
  const expectedFormatted = type === BudgetType.PERCENT_DELTA ? formatPercent(expected) : formatBytes(expected);
  const diffFormatted =
    type === BudgetType.PERCENT_DELTA ? formatPercent(actual - expected) : formatBytes(actual - expected);

  const prefix = `${(useEmoji ? levelToEmoji : levelToString)[level]}: \`${itemName}\``;

  switch (type) {
    case BudgetType.DELTA:
      return `${prefix} failed the ${sizeKey} budget delta limit. Expected to increase no more than ${expectedFormatted}, but increased by ${actualFormatted}`;
    case BudgetType.PERCENT_DELTA:
      return `${prefix} failed the ${sizeKey} budget percent change limit. Expected no increase by no more than ${expectedFormatted}, but increased by ${actualFormatted}`;
    case BudgetType.SIZE:
      return `${prefix} failed the ${sizeKey} budget size limit of ${expectedFormatted} by ${diffFormatted}`;
  }
}

@build-tracker/types

Build Tracker typescript types

MIT
Latest version published 3 years ago

Package Health Score

51 / 100
Full package analysis

Similar packages