npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nfractions

v1.0.0

Published

Fractions with BigInts

Downloads

4

Readme

nFractions

Creates fractions using BigInts.

Syntax

new Fraction(  numerator,  denominator  )
  • numerator: string, number, bigint, Fraction (default: 0)
  • denominator: string, number, bigint, Fraction (default: 1)
new Fraction(1, 2)     //  = 1/2
new Fraction(2n, 4n)   //  = 2/4
new Fraction("1", "2") //  = 1/2
new Fraction("1", -2n) //  = 1/-2
new Fraction("1/2")    //  = 1/2
new Fraction(new Fraction("1/2")) //  = 1/2
new Fraction("1/2", 2) //  = 1/4
new Fraction(.5, .5)   //  = 5/5
new Fraction(1)        //  = 1/1
new Fraction()         //  = 0/1
new Fraction(1, 0)     //  err: ZeroDivisionError

new Fraction(.11111111111111111111111111111)   //  = 1111111111111111/10000000000000000
new Fraction(".11111111111111111111111111111") //  = 11111111111111111111111111111/1000000000000000000000000000000000

Properties

  • .numerator: BigInt
  • .denominator: BigInt
  • .isNaN: Boolean
  • .isNegative: Boolean
  • .negative: Fraction
    • Returns the faction with a negated numerator. Does not change the value of the variable.
  • .reciprocal: Fraction
    • Returns the reciprical. Does not change the value of the variable.
  • .whole: BigInt

Inequality/inequality

  • Equals
    • .eq( value ) (mimics ==)
  • Strictly Equals
    • .seq( value ) (mimics ===)
  • Less Than
    • .lt( value ) (mimics <)
  • Less Than or Equals
    • .lteq( value ) (mimics <=)
  • Greater Than
    • .gt( value ) (mimics >)
  • Greater Than or Equals
    • .gteq( value ) (mimics >=)

Examples

new Fraction(1, 2).lt(1n)      // => true
new Fraction(1, 2).gt(.5)      // => false
new Fraction(1, 2).lteq("foo") // => false
new Fraction(1, 2).eq("1/2")   // => true
new Fraction(1, 2).seq("1/2")  // => false
new Fraction(1, 2).seq(new Fraction("1/2")) // => true

Arithmatic

  • Addition
    • .plus( addend ) (mimics +)
  • Subtraction
    • .minus( subtrahend ) (mimics -)
  • Multiplication
    • .times( multiplicidad ) (mimics *)
  • Division
    • .divide( dividend ) (mimics /)

Parameters can only be of type number, Fraction, bigint, or parsebale string.

  • Exponentiation

    • Fraction.pow( fraction , exponent ) (mimics Math.pow())
    • Only accepts Fractions as first input and integers (including BigInts) as second
  • Absolution

    • Fraction.abs( fraction ) (mimics Math.abs())
    • Only accepts Fractions as input
  • Reciprocation

    • .reciprocate()
    • This will change the value of the variable.
  • Simplification

    • .reduce()
    • This will change the value of the variable.

.clone()

Returns a copy of the variable. Eliminates the risk of call-by-sharing logic errors.

Statics

Fraction.NaN

Acts as NaN as a fraction. Math and comparisons cannot be done with it.

Will not throw an error if the input is not a string. May throw a ZeroDivisionError.

Fraction.parseFraction()

Accepts only strings. Will always return a Fraction or Fraction.NaN. Will return whatever fraction is within the string.

Fraction.parseFraction("1/2")     // =>  1/2
Fraction.parseFraction(" 1 / 2 ") // =>  1/2
Fraction.parseFraction("0b1/0x2") // =>  1/2
Fraction.parseFraction("-1 / +2") // => -1/2
Fraction.parseFraction("1/0")     // err: ZeroDivisionError
Fraction.parseFraction(6)         // => NaN
Fraction.parseFraction("foo")     // => NaN