{"id":17472754,"url":"https://github.com/shinnn/file-or-stdin","last_synced_at":"2025-03-28T08:10:32.489Z","repository":{"id":57235533,"uuid":"65373771","full_name":"shinnn/file-or-stdin","owner":"shinnn","description":"Read a file, or read stdin if no files are specified","archived":false,"fork":false,"pushed_at":"2019-02-21T10:24:46.000Z","size":75,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-09T03:18:01.949Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shinnn.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":"2016-08-10T10:31:52.000Z","updated_at":"2019-02-21T10:24:47.000Z","dependencies_parsed_at":"2022-09-04T23:02:17.200Z","dependency_job_id":null,"html_url":"https://github.com/shinnn/file-or-stdin","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Ffile-or-stdin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Ffile-or-stdin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Ffile-or-stdin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Ffile-or-stdin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shinnn","download_url":"https://codeload.github.com/shinnn/file-or-stdin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245991582,"owners_count":20706129,"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":[],"created_at":"2024-10-18T17:35:36.514Z","updated_at":"2025-03-28T08:10:32.440Z","avatar_url":"https://github.com/shinnn.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# file-or-stdin\n\n[![npm version](https://img.shields.io/npm/v/file-or-stdin.svg)](https://www.npmjs.com/package/file-or-stdin)\n[![Build Status](https://travis-ci.com/shinnn/file-or-stdin.svg?branch=master)](https://travis-ci.com/shinnn/file-or-stdin)\n[![Coverage Status](https://img.shields.io/coveralls/shinnn/file-or-stdin.svg)](https://coveralls.io/github/shinnn/file-or-stdin?branch=master)\n\nRead a file, or read [stdin](https://nodejs.org/api/process.html#process_process_stdin) if no files are specified\n\n```javascript\n// echo \"Hello!\" | node example.js\nconst fileOrStdin = require('file-or-stdin');\n\n(async () =\u003e {\n  (await fileOrStdin('path/to/a/file')).toString() // file contents;\n  (await fileOrStdin(null)).toString(); //=\u003e 'Hello!'\n})();\n```\n\n## Installation\n\n[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/about-npm/).\n\n```\nnpm install file-or-stdin\n```\n\n## API\n\n```javascript\nconst fileOrStdin = require('file-or-stdin');\n```\n\n### fileOrStdin(*filePath* [, *options*])\n\n*filePath*: `string` or a [falsy value](https://developer.mozilla.org/docs/Glossary/Falsy)  \n*options*: `Object` ([`fs.readFile`](https://nodejs.org/api/fs.html#fs_fs_readfile_path_options_callback) options) or `string` (encoding)   \nReturn: `Promise\u003cBuffer\u003e` or `Promise\u003cstring\u003e`\n\nWhen the first argument is a file path, it reads the given file and returns a promise of the file contents.\n\nWhen the first argument is a falsy value, it reads [stdin](http://www.linfo.org/standard_input.html) and returns a promise of the buffered stdin data.\n\n```javascript\n// echo \"nodejs\" | node example.js\n(async () =\u003e {\n  await fileOrStdin('', 'utf8'); //=\u003e 'nodejs'\n})();\n```\n\n```javascript\n// echo \"nodejs\" | node example.js\n(async () =\u003e {\n  await fileOrStdin('', 'base64'); //=\u003e 'bm9kZWpz'\n})();\n```\n\n## License\n\n[ISC License](./LICENSE) © 2018 - 2019 Shinnosuke Watanabe\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshinnn%2Ffile-or-stdin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshinnn%2Ffile-or-stdin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshinnn%2Ffile-or-stdin/lists"}