@santi100a/percentage-lib
v0.0.1
Published
Santi's Powerful Percentage Function: Easily find percentages!
Downloads
7
Maintainers
Readme
Santi's Powerful Percentage Function
- 🚀 Lightweight and fast
- 👴 ES3-compliant
- 💻 Portable between the browser and Node.js
- 📘 Includes TypeScript definitions
What's this?
This is a lightweight, portable NPM package to take the percentage of any number.
$$ P = \frac{1}{100} \cdot n \cdot p $$
Installation
- Via NPM:
npm install @santi100a/percentage-lib
- Via Yarn:
yarn add @santi100a/percentage-lib
- Via PNPM:
pnpm install @santi100a/percentage-lib
API
function percentage(num: number, percentage: number): number;
Calculates the percentage of a given number.
| Name | Type | Description | Optional? | Default | | ------------ | -------- | ----------------------------------------------------------- | --------- | ------- | |
num
|number
| The number for which the percentage needs to be calculated. | No | N/A | |percentage
|number
| The percentage value to calculate. Must be positive. | No | N/A |Returns the calculated percentage value. Throws a
TypeError
Ifnum
is not a number orpercentage
is not a number. Throws aTypeError
Ifpercentage
is not positive.
Usage
const percentage = require('@santi100a/percentage-lib'); // CJS
import percentage from '@santi100a/percentage-lib'; // ESM
import percentage = require('@santi100a/percentage-lib'); // TypeScript
const result = percentage(50, 20);
console.log(result); // Output: 10
Contribute
Wanna contribute? File an issue or pull request! Look at the contribution instructions and make sure you follow the contribution Code of Conduct.