Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

575 B
Raw Blame
/** A count of finished items out of a total — an onboarding checklist, say. */
export interface ProgressCounts {
  done: number
  total: number
}

/**
 * How far through a checklist something is, as a percentage for a progress bar.
 *
 * An empty checklist counts as complete rather than as nothing done: a
 * marketplace that asks nothing of its sellers has no outstanding work, and
 * `done / total` would be NaN.
 */
export function progressPercentage({ done, total }: ProgressCounts): number {
  if (total <= 0) return 100

  return Math.round((done / total) * 100)
}