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 🙏

© 2025 – Pkg Stats / Ryan Hefner

continuedfraction.js

v0.0.2

Published

The RAW continued fractions library

Readme

ContinuedFraction.js

NPM Package MIT license

A lightweight JavaScript library sitting on the shoulders of Fraction.js for generating and evaluating standard and generalized continued fractions. It is built with generator-based sequences and convergent recurrences for fast execution.

Features

  • Generate the simple continued‑fraction expansion of √N
  • Convert any real number or rational to its continued‑fraction
  • Infinite generators for classic constants: φ (golden ratio), e, π, 4/π
  • Evaluate (simple or generalized) continued fractions to a Fraction

Example

const frac = ContinuedFraction.eval(
  ContinuedFraction.fromFraction(3021, 203),
  10 // Max Steps
);
console.log(frac.toString()); // → "3021/203"

Installation

You can install ContinuedFraction.js via npm:

npm install continuedfraction.js

Or with yarn:

yarn add continuedfraction.js

Alternatively, download or clone the repository:

git clone https://github.com/rawify/ContinuedFraction.js

Usage

Include the continuedfraction.min.js file in your project:

<script src="path/to/continuedfraction.min.js"></script>
<script>
  var x = ContinuedFraction.sqrt(2);
</script>

Or in a Node.js project:

const ContinuedFraction = require('continuedfraction.js');

or

import ContinuedFraction from 'continuedfraction.js';

ContinuedFraction API

Import the static utility class and use its generators and evaluator:

// 1) Continued‑fraction terms of √23
const sqrtGen = ContinuedFraction.sqrt(23);
console.log(sqrtGen.next().value); // 4
console.log(sqrtGen.next().value); // 1, 3, 1, 8, …
// 2) Continued‑fraction of a decimal
let cnt = 0;
for (let piCf of ContinuedFraction.fromNumber(Math.PI)) {
  console.log(piCf);
  if (cnt++ >= 10) break;
}
// 3) Golden ratio φ terms
const phiGen = ContinuedFraction.PHI();
console.log(phiGen.next().value); // 1, and forever 1…
// 4) Evaluate the first 10 terms of e’s CF to a Fraction
const approxE = ContinuedFraction.eval(ContinuedFraction.E, 10);
console.log(approxE.toString()); // e ≈ “193/71”
// 5) Generalized CF for π, 4/π
const genPi = ContinuedFraction.PI();
console.log(genPi.next().value);   // { a: 3, b: 0 }
console.log(genPi.next().value);   // { a: 6, b: 1 }
// 6) Continued‑fraction from two integers
const halfCf = ContinuedFraction.fromFraction(1, 2);
console.log([...halfCf]); // [0, 2]

Methods

| Method | Signature | Description | | ------------------------ | ----------------------------------------------------------------- | ----------------------------------------------------------------------- | | sqrt(N: number) | Generator<number> | Simple CF terms of √N | | fromNumber(n) | Generator<number> | CF terms of any real via Fraction.js | | fromFraction(a, b) | Generator<number> | CF terms of the rational a/b | | PHI() | Generator<number> | Infinite 1’s for the golden ratio | | FOUR_OVER_PI() | Generator<CFTerm> | Generalized CF terms for 4/π | | PI() | Generator<CFTerm> | Generalized CF terms for π | | E() | Generator<number> | CF expansion of e | | eval(generator, steps) | Generator (() => Generator, steps?: number) ⇒ Fraction | Evaluate (generalized) continued fraction to a Fraction approximation |

Coding Style

As every library I publish, ContinuedFraction is also built to be as small as possible after compressing it with Google Closure Compiler in advanced mode. Thus the coding style orientates a little on maxing-out the compression rate. Please make sure you keep this style if you plan to extend the library.

Building the library

After cloning the Git repository run:

npm install
npm run build

Copyright and Licensing

Copyright (c) 2025, Robert Eisele Licensed under the MIT license.