{"id":15673592,"url":"https://github.com/lmammino/fib-it","last_synced_at":"2025-05-09T00:27:30.934Z","repository":{"id":138310516,"uuid":"163002920","full_name":"lmammino/fib-it","owner":"lmammino","description":"6 ways to generate a fibonacci sequence in JavaScript","archived":false,"fork":false,"pushed_at":"2019-01-20T18:32:26.000Z","size":106,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-31T19:51:10.319Z","etag":null,"topics":["fib","fibonacci","generator","iterable","iterator","javascript","node","nodejs","stream","streams"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lmammino.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-12-24T15:23:25.000Z","updated_at":"2019-01-20T18:32:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"62feb4ea-e041-4e59-9b15-fede812eba3d","html_url":"https://github.com/lmammino/fib-it","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmammino%2Ffib-it","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmammino%2Ffib-it/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmammino%2Ffib-it/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmammino%2Ffib-it/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lmammino","download_url":"https://codeload.github.com/lmammino/fib-it/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253169075,"owners_count":21864969,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fib","fibonacci","generator","iterable","iterator","javascript","node","nodejs","stream","streams"],"created_at":"2024-10-03T15:41:22.364Z","updated_at":"2025-05-09T00:27:30.879Z","avatar_url":"https://github.com/lmammino.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fib-it\n\nFibonacci sequence implemented in 6 different ways with JavaScript. A nice excuse to explore **functions**, **iterators**, **generators**, **iterable values**, **event emitters** and **streams**!\n\n[![npm version](https://badge.fury.io/js/fib-it.svg)](https://badge.fury.io/js/fib-it)\n[![CircleCI](https://circleci.com/gh/lmammino/fib-it.svg?style=shield)](https://circleci.com/gh/lmammino/fib-it)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n\n## Install\n\nAs usual, npm-it-away:\n\n```bash\nnpm i --save fib-it\n```\n\n## Usage\n\nThe library exposes 6 different implementations of the fibonacci sequence.\n\nThe sequence will be infinite (as much as it can be considering JavaScript integer space) unless limited to max number.\n\n### _Function-based_ implementation\n\n```javascript\nconst { genFib } = require('fib-it')\n\nconst f = genFib(6) // limit the sequence to numbers below 6\nf() // 1\nf() // 1\nf() // 2\nf() // 3\nf() // 5\nf() // null\nf() // null\n```\n\n### _itarator-based_ implementation\n\n```javascript\nconst { genFibIterator } = require('fib-it')\n\nit = genFibIterator(6) // { next: [Function: next] }\nit.next() // { value: 1, done: false }\nit.next() // { value: 1, done: false }\nit.next() // { value: 2, done: false }\nit.next() // { value: 3, done: false }\nit.next() // { value: 5, done: false }\nit.next() // { value: null, done: true }\n\n// or\n\nit = genFibIterator(6)\nlet result = it.next()\nwhile (!result.done) {\n  console.log(result.value)\n  result = it.next()\n}\n// 1\n// 1\n// 2\n// 3\n// 5\n```\n\n### _generator-based_ implementation\n\n```javascript\ngen = fibGenerator(6) // {}\ngen.next() // { value: 1, done: false }\ngen.next() // { value: 1, done: false }\ngen.next() // { value: 2, done: false }\ngen.next() // { value: 3, done: false }\ngen.next() // { value: 5, done: false }\ngen.next() // { value: null, done: true }\ngen.next() // { value: undefined, done: true }\n\n// or\n\ngen = fibGenerator(6)\n[...gen] // [ 1, 1, 2, 3, 5 ]\n```\n\n### _iterable-based_ implementation\n\n```javascript\nconst { genFibIterable } = require('fib-it')\n\nit = genFibIterable(6) // { [Symbol(Symbol.iterator)]: [GeneratorFunction: [Symbol.iterator]] }\n[...it] // [ 1, 1, 2, 3, 5 ]\n\n// or\n\nfor (n of f) { console.log(n) }\n// 1\n// 1\n// 2\n// 3\n// 5\n```\n\n### _event-emitter-based_ implementation\n\n```javascript\nconst { FibEmitter } = require('fib-it')\n\nconst fe = new FibEmitter(6, 10)\nfe.on('data', n =\u003e console.log(n))\nfe.on('end', () =\u003e console.log('done!'))\nfe.start()\n// 1\n// 1\n// 2\n// 3\n// 5\n// done!\n```\n\n### _stream-based_ implementation\n\n```javascript\nconst s = new FibStream(7) // FibStream { ... }\ns.on('data', chunk =\u003e console.log(chunk.readUInt32LE(0).toString()))\ns.on('end', () =\u003e console.log('done!'))\n// 1\n// 1\n// 2\n// 3\n// 5\n// done!\n```\n\n## When do I really use this?\n\nThere are some [actual use cases](https://www.stocktrader.com/2009/05/26/fibonacci-numbers-investors-sequence-elliot-wave-theory/) for the fibonacci sequence. So maybe you need something like this in your code!\n\nIn reality this is just an experiment to compare different methodology to generate data sequences in JavaScript, so I expect it to be used mostly for education purposes rather than for production code.\n\nAlso with this goal in mind, the code is kept relatively simple and it's not meant to be _feature-complete_ or _error-proof_.\n\n## Contribute\n\nFeel more than welcome to\n[report bugs](https://github.com/lmammino/fib-it/issues) or [propose changes](https://github.com/lmammino/fib-it/pulls).\n\n## License\n\nLicensed under [MIT](https://github.com/lmammino/fib-it/blob/master/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flmammino%2Ffib-it","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flmammino%2Ffib-it","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flmammino%2Ffib-it/lists"}