Skip to content

santi100a/factorial-lib

Repository files navigation

Santi's Sorting Library

Build Status npm homepage GitHub stars License Bundlephobia stats

  • 🚀 Lightweight and fast^
  • 👴 ES3-compliant*
  • 💻 Portable between the browser and Node.js

What's this?

This is a small, lightweight library for computing the factorial of any positive finite integer.

Installation

  • Via NPM: npm install @santi100/factorial-lib
  • Via Yarn: yarn add @santi100/factorial-lib
  • Via PNPM: pnpm install @santi100/factorial-lib

API

  • function factorial(n: number): number; Returns NaN if $n$ is negative, infinite, itself NaN or a float.

It takes the number for which the factorial is to be calculated, and returns $n!$

Usage

// ESM
import { factorial } from '@santi100/factorial-lib'; 
import factorial from '@santi100/factorial-lib';

import factorial = require('@santi100/factorial-lib'); // TypeScript

const { factorial } = require('@santi100/factorial-lib'); // CJS

console.log(factorial(5)); // prints 120
console.log(factorial(7)); // prints 5,040

console.log(factorial(-60)); // prints NaN
console.log(factorial(3.5)); // prints NaN
console.log(factorial(NaN)); // prints NaN
console.log(factorial(Infinity)); // prints NaN
console.log(factorial(-Infinity)); // prints NaN

Contribute

Wanna contribute? File an issue or pull request! Look at the contribution instructions and make sure you follow the contribution Code of Conduct.

Disclaimers

*Hasn't been tested in an actual ES3 environment. Feel free to open an issue or pull request if you find any non-ES3 thing. See "Contribute" for instructions on how to do so.

^The source code is just a few kilobytes in size.

About

A lightweight library for calculating the factorial of a number. Official repo for @santi100/factorial-lib on NPM.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project