UNPKG

nhb-toolbox

Version:

A versatile collection of smart, efficient, and reusable utility functions, classes and types for everyday development needs.

17 lines (16 loc) 960 B
import type { PercentageOptions } from './types'; /** * * Performs a percentage-related calculation based on the given mode and inputs. * * - `get-percent`: Calculates what percentage the `part` is of the `total`. * - `get-value`: Calculates the value from a given `percentage` of a `total`. * - `get-original`: Calculates the original value from a known `value` and `percentage`. * - `get-change-percent`: Percent increase/decrease from `oldValue` to `newValue`. * - `apply-percent-change`: Applies increase/decrease by `percentage` to `baseValue`. * - `get-percent-difference`: Absolute percent difference between two values. * - `inverse-percent`: What percent `total` is of `part`. * * @param options - The calculation mode and inputs required for the operation. * @returns The calculated number rounded to three decimal places, or `NaN` if input is invalid. */ export declare function calculatePercentage(options: PercentageOptions): number;