@santi100a/percentage-lib
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

Santi's Powerful Percentage Function

Build Status npm homepage GitHub stars License Bundlephobia stats

  • 🚀 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 If num is not a number or percentage is not a number. Throws a TypeError If percentage 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.

Package Sidebar

Install

npm i @santi100a/percentage-lib

Weekly Downloads

3

Version

0.0.1

License

MIT

Unpacked Size

35 kB

Total Files

41

Last publish

Collaborators

  • santi100a