0.0.1 • Published 8 months ago

@santi100a/percentage-lib v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

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.

    NameTypeDescriptionOptional?Default
    numnumberThe number for which the percentage needs to be calculated.NoN/A
    percentagenumberThe percentage value to calculate. Must be positive.NoN/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.