{"id":16485332,"url":"https://github.com/morganconrad/f-readline","last_synced_at":"2025-07-10T05:38:32.231Z","repository":{"id":47916581,"uuid":"233274065","full_name":"MorganConrad/f-readline","owner":"MorganConrad","description":"Thin layer over node's readline module to provide functional support: map, reduce, filter, forEach()","archived":false,"fork":false,"pushed_at":"2023-01-06T02:25:33.000Z","size":147,"stargazers_count":2,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-09T10:06:56.645Z","etag":null,"topics":["async","filter","foreach","functional-programming","map","node-readline","readline","reduce"],"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/MorganConrad.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}},"created_at":"2020-01-11T17:58:20.000Z","updated_at":"2021-05-10T23:12:44.000Z","dependencies_parsed_at":"2023-02-05T03:01:27.171Z","dependency_job_id":null,"html_url":"https://github.com/MorganConrad/f-readline","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MorganConrad/f-readline","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MorganConrad%2Ff-readline","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MorganConrad%2Ff-readline/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MorganConrad%2Ff-readline/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MorganConrad%2Ff-readline/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MorganConrad","download_url":"https://codeload.github.com/MorganConrad/f-readline/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MorganConrad%2Ff-readline/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262293208,"owners_count":23288680,"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":["async","filter","foreach","functional-programming","map","node-readline","readline","reduce"],"created_at":"2024-10-11T13:25:28.954Z","updated_at":"2025-06-27T16:31:44.741Z","avatar_url":"https://github.com/MorganConrad.png","language":"JavaScript","readme":"[![Build Status](https://secure.travis-ci.org/MorganConrad/f-readline.png)](http://travis-ci.org/MorganConrad/f-readline)\n[![License](http://img.shields.io/badge/license-MIT-A31F34.svg)](https://github.com/MorganConrad/f-readline)\n[![NPM Downloads](http://img.shields.io/npm/dm/f-readline.svg)](https://www.npmjs.org/package/f-readline)\n[![Known Vulnerabilities](https://snyk.io/test/github/morganconrad/f-readline/badge.svg)](https://snyk.io/test/github/morganconrad/f-readline)\n[![Coverage Status](https://coveralls.io/repos/github/MorganConrad/f-readline/badge.svg)](https://coveralls.io/github/MorganConrad/f-readline)\n\n# f-readline\n\nFor a long time, Node had no \"easy\" way to read a stream line by line.  Until v11.4, when [readline](https://nodejs.org/api/readline.html) added [support for async iteration](https://github.com/nodejs/node/pull/23916).\n\nThis module is a thin layer over readline to provide functional programming constructs: `filter(), forEach(), map(), reduce()`.  It also provides a convenient `getAllLines()`.\n\n\n## Basic API\n\n**Note:** Other than the constructor, all methods are **async**.\n\n### constructor(readable, interfaceOptions)   constructor\n - readable is the stream to be read\n - interfaceOptions (optional, default = {}) will be passed to [readline.createInterface(interfaceOptions)](https://nodejs.org/api/readline.html#readline_readline_createinterface_options)\n   - crlfDelay defaults to 999999\n   - input is set to the `readable` argument\n\n\n### async getAllLines()\nConvenience method to just provide an array of all the lines.  Obviously it must all fit in memory!\n\n## Functional API\nThe \"functional\" methods below accept a user function (or \"predicate\") **fn** as their first argument.  This method is usually called with three arguments:\n\n - the line\n - the line count (starting at 0)\n - the instance of f-readline.  Generally useless but see notes at end\n\n### async filter(fn)\nReturns an array of all lines passing the predicate `fn(line, index, this)`\n\n### async forEach(fn)\nCalls `fn(line, index, this)` for each line.\n\n### async map(fn)\nReturns an array obtained by calling `fn(line, index, this)` for each line\n\n### async reduce(fn, acc)\nReduces using `fn(acc, line, index, this)`\n\n\n### Notes, Todos, and  Caveats\n\n#### Since readline is clever on memory (?), this may save on memory\n - if you are just counting lines or characters\n - if you are filtering just a small subset of the input\n\n#### What good is the 3rd argument to `fn()`?\n - The interfaceOptions are available in `.interfaceOptions`\n - The created interface is available in `.rl`\n - If you want to pass other client specific info to **fn**, just add it to the FReadLine instance, _e.g._\n\n```js\nlet frl = new FReadLine(readable, interfaceOptions);\nfrl.clientData = { your data here };\n\n// then, during the call to fn(), you could access those\n\nfn(line, index, frl) {\n  do something with frl.clientData\n}\n```\n\n#### This module has nothing to do with prompting the user, pausing the input, etc.  Just reading a stream line by line.\n\n### Alternatives\n\nAll of these do their own twiddly buffering and eol parsing, instead of relying on a \"robust\" built-in library.\n\n#### [file-readline](https://www.npmjs.com/package/file-readline)\n - non-functional\n - only reads a **file**, not any stream\n \n#### [n-readlines](https://www.npmjs.com/package/n-readlines)\n - non-functional\n - synchronous\n \n#### [readlines-ng](https://www.npmjs.com/package/readlines-ng)\n - non-functional\n - looks pretty good otherwise and claims to be fast.\n \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorganconrad%2Ff-readline","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmorganconrad%2Ff-readline","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorganconrad%2Ff-readline/lists"}