<commit_before>/*
Name:         fibonacci
Description:  This function calculates fibonacci numbers for one or endless iterations.
Author:       <NAME> (https://frankl.in)
Source:       https://github.com/fvdm/nodejs-fibonacci
Contact:      https://github.com/fvdm/nodejs-fibonacci/issues
License:      Unlicense / Public Domain (see UNLICENSE FILE)
              <https://github.com/fvdm/nodejs-fibonacci/raw/master/UNLICENSE>

It returns an object with these elements:

* number     - the number as string
* length     - the number of digits
* iterations - how many iterations it took
* ms         - duration in milliseconds

Usage:
var fibonacci = require ('fibonacci');
var bigNumber = fibonacci.iterate (3000);
console.log (bigNumber);

Get all numbers:

WARNING: THIS CONTINUES FOREVER !!!
         or till you run out of RAM

         Stop with `fibonacci.kill ()`;

fibonacci.on ('result', function (result) {
  console.log (result.iterations +') '+ result.number);
  if (result.ms > 10000) {
    fibonacci.kill ();
  }
});

fibonacci.iterate ();
*/

var bignum = require ('bignum');
var EventEmitter = require ('events') .EventEmitter;

var app = new EventEmitter ();

app.iterate = function (limit) {
  var next = bignum (1);
  var cur = bignum (-1);
  var last = bignum (0);
  var loop = bignum (0);
  var start = new Date () .getTime ();

  app.doWhile = true;

  while (app.doWhile) {
    last = cur; // prev cur -> now last
    cur = next; // prev next -> now cur
    next = cur.add (last);

    var result = {
      number: next.toString (),
      length: next.toString () .length,
      iterations: loop.toString (),
      ms: new Date ().getTime () - start
    }

    app.emit ('result', result);

    // found the one
    if (limit !== undefined && loop == limit) {
      app.doWhile = false;
      app.emit ('done', result);
      return result;
    }

    // catch infinity
    if (next === 'Infinity') {
      app.doWhile = false;
      app.emit ('stop', {
        reason: 'infinity',
        max_limit: Number.MAX_LIMIT.toString (),
        last_result: result,
        iterations: loop.toString (),
        intended: limit ? limit : false
      });
      break;
    }

    // count
    loop = loop.add (1);
  }
}

app.kill = function () {
  app.doWhile = false;
}

// ready
module.exports = app;<commit_msg>Minor clean up<commit_after>/*
Name:           fibonacci
Description:    This function calculates fibonacci numbers for one or endless iterations.
Author:         <NAME> (https://frankl.in)
Source & docs:  https://github.com/fvdm/nodejs-fibonacci
Contact:        https://github.com/fvdm/nodejs-fibonacci/issues
License:        Unlicense / Public Domain (see UNLICENSE FILE)
                <https://github.com/fvdm/nodejs-fibonacci/raw/master/UNLICENSE>
*/

var bignum = require ('bignum');
var EventEmitter = require ('events') .EventEmitter;
var app = new EventEmitter ();

app.iterate = function (limit) {
  var next = bignum (1);
  var cur = bignum (-1);
  var last = bignum (0);
  var loop = bignum (0);
  var start = new Date () .getTime ();

  app.doWhile = true;

  while (app.doWhile) {
    last = cur; // prev cur -> now last
    cur = next; // prev next -> now cur
    next = cur.add (last);

    var result = {
      number: next.toString (),
      length: next.toString () .length,
      iterations: loop.toString (),
      ms: new Date () .getTime () - start
    }

    app.emit ('result', result);

    // found the one
    if (limit !== undefined && loop == limit) {
      app.doWhile = false;
      app.emit ('done', result);
      return result;
    }

    // catch infinity
    if (next === 'Infinity') {
      app.doWhile = false;
      app.emit ('stop', {
        reason: 'infinity',
        max_limit: Number.MAX_LIMIT.toString (),
        last_result: result,
        iterations: loop.toString (),
        intended: limit ? limit : null
      });
      break;
    }

    // count
    loop = loop.add (1);
  }
}

app.kill = function () {
  app.doWhile = false;
}

// ready
module.exports = app;
{'fraction_non_alphanumeric': 0.13967861557478367, 'fraction_numerical': 0.004697156983930779, 'mean_word_length': 2.382943143812709, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 12, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2298909', 'n_tokens_mistral': 1330, 'n_tokens_neox': 1267, 'n_words': 369}