{"_id":"read-fallback","_rev":"457440","name":"read-fallback","description":"Read file with extension fallback.","dist-tags":{"latest":"0.2.2"},"maintainers":[{"name":"rem","email":"0x142857@gmail.com"}],"time":{"modified":"2024-06-20T07:39:00.000Z","created":"2016-09-30T07:17:33.716Z","0.2.2":"2016-09-30T09:46:55.524Z","0.2.1":"2016-09-30T09:35:50.418Z","0.2.0":"2016-09-30T09:16:09.757Z","0.1.1":"2016-09-30T07:18:01.629Z","0.1.0":"2016-09-30T07:17:33.716Z"},"users":{},"author":{"name":"EGOIST","email":"0x142857@gmail.com","url":"github.com/egoist"},"repository":{"type":"git","url":"git+https://github.com/egoist/read-fallback.git"},"versions":{"0.2.2":{"name":"read-fallback","version":"0.2.2","description":"Read file with extension fallback.","license":"MIT","repository":{"type":"git","url":"git+https://github.com/egoist/read-fallback.git"},"author":{"name":"EGOIST","email":"0x142857@gmail.com","url":"github.com/egoist"},"engines":{"node":">=4"},"scripts":{"test":"jest && eslint index.js __test__/* --ext .js"},"files":["index.js"],"keywords":["read","fallback"],"devDependencies":{"eslint":"latest","eslint-config-egoist":"^1.0.4","jest-cli":"^15.1.1"},"jest":{"testEnvironment":"node"},"eslintConfig":{"extends":"egoist/esnext"},"dependencies":{"path-exists":"^3.0.0"},"gitHead":"f6e8108ec89187f9eaeacc2888ab470c67bf2916","bugs":{"url":"https://github.com/egoist/read-fallback/issues"},"homepage":"https://github.com/egoist/read-fallback#readme","_id":"read-fallback@0.2.2","_shasum":"3b88d2fc08a54c9f74623cd9dad6eccbb7495559","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.4.0","_npmUser":{"name":"rem","email":"0x142857@gmail.com"},"dist":{"shasum":"3b88d2fc08a54c9f74623cd9dad6eccbb7495559","tarball":"http://registry-npm.ywwl.com/read-fallback/download/read-fallback-0.2.2.tgz","integrity":"sha512-jWsOI8hRHtu6tERijsl0X8AjyzfznKqfPGU8vMfAxl9EmuiGRTKcl6hDFg1lpEoj52Bx2FrQC0gp1SN7Ax0n+Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDKo08IwZhiLr5AcPkUAD/4Y4QbAj9VMUIwVAsNDUIm7QIhAO6YX10vWDMdrsCYbxAXp7SNQvj6LKIidJftgfXS5R9d"}],"size":2919,"noattachment":false,"key":"/read-fallback/-/read-fallback-0.2.2.tgz"},"maintainers":[{"name":"rem","email":"0x142857@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/read-fallback-0.2.2.tgz_1475228815281_0.5456642026547343"},"directories":{},"publish_time":1475228815524,"_cnpm_publish_time":1475228815524},"0.2.1":{"name":"read-fallback","version":"0.2.1","description":"Read file with extension fallback.","license":"MIT","repository":{"type":"git","url":"git+https://github.com/egoist/read-fallback.git"},"author":{"name":"EGOIST","email":"0x142857@gmail.com","url":"github.com/egoist"},"engines":{"node":">=4"},"scripts":{"test":"jest && eslint *.js __test__/* --ext .js"},"files":["index.js"],"keywords":["read","fallback"],"devDependencies":{"jest-cli":"^15.1.1","eslint":"latest","eslint-config-egoist":"latest"},"jest":{"testEnvironment":"node"},"eslintConfig":{"extends":"egoist/esnext"},"dependencies":{"path-exists":"^3.0.0"},"gitHead":"3540d0d80a8237ee796d10cfde276884eb99f91c","bugs":{"url":"https://github.com/egoist/read-fallback/issues"},"homepage":"https://github.com/egoist/read-fallback#readme","_id":"read-fallback@0.2.1","_shasum":"f1d159fd9168ecbfc2e1f030d7ac034e2b14fdc8","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.4.0","_npmUser":{"name":"rem","email":"0x142857@gmail.com"},"dist":{"shasum":"f1d159fd9168ecbfc2e1f030d7ac034e2b14fdc8","tarball":"http://registry-npm.ywwl.com/read-fallback/download/read-fallback-0.2.1.tgz","integrity":"sha512-L/dpVUKlrlQ5Qtg/FWM+CAYmKqdByCWWIvCqLmBlVEGO7K1/fVsj8t3/E6uKsuxUN7WkvPqb1ByCKo51r3hrvA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEemDj+kIKarkXtws7APgjT8YmoDvWTCUjRZSZp9IrrqAiEAq0BY47vv7T49KFEJcn/ilXfB/7TNtzQIau/hZcJBQvw="}],"size":2903,"noattachment":false,"key":"/read-fallback/-/read-fallback-0.2.1.tgz"},"maintainers":[{"name":"rem","email":"0x142857@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/read-fallback-0.2.1.tgz_1475228150183_0.2989271958358586"},"directories":{},"publish_time":1475228150418,"_cnpm_publish_time":1475228150418},"0.2.0":{"name":"read-fallback","version":"0.2.0","description":"Read file with extension fallback.","license":"MIT","repository":{"type":"git","url":"git+https://github.com/egoist/read-fallback.git"},"author":{"name":"EGOIST","email":"0x142857@gmail.com","url":"github.com/egoist"},"engines":{"node":">=4"},"scripts":{"test":"jest && eslint *.js __test__/* --ext .js"},"files":["index.js"],"keywords":["read","fallback"],"devDependencies":{"jest-cli":"^15.1.1","eslint":"latest","eslint-config-egoist":"latest"},"jest":{"testEnvironment":"node"},"eslintConfig":{"extends":"egoist/esnext"},"dependencies":{"path-exists":"^3.0.0"},"gitHead":"020278428975482e611ca0afd6d6082807eb7002","bugs":{"url":"https://github.com/egoist/read-fallback/issues"},"homepage":"https://github.com/egoist/read-fallback#readme","_id":"read-fallback@0.2.0","_shasum":"ca4cad2f8d1cedd5939d2c5e3a276282a4f91b3b","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.4.0","_npmUser":{"name":"rem","email":"0x142857@gmail.com"},"dist":{"shasum":"ca4cad2f8d1cedd5939d2c5e3a276282a4f91b3b","tarball":"http://registry-npm.ywwl.com/read-fallback/download/read-fallback-0.2.0.tgz","integrity":"sha512-YH/1obpMrveBg+R8IP3zuAHAw8z4SOBhlAiSZW0jMmaLbU8DB5ugo8lM2r9867rmKY32oLJd7yNwk6t4IoMS9A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIA86d5UiMAHh2HzeT8aPqlq+1y2vNwyW3NOYIABOvdPjAiEA5zisOu2clNB8qOdFcW5Hy4DdianYmkQOdc/mNUgU9kY="}],"size":2901,"noattachment":false,"key":"/read-fallback/-/read-fallback-0.2.0.tgz"},"maintainers":[{"name":"rem","email":"0x142857@gmail.com"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/read-fallback-0.2.0.tgz_1475226967621_0.3239188240841031"},"directories":{},"publish_time":1475226969757,"_cnpm_publish_time":1475226969757},"0.1.1":{"name":"read-fallback","version":"0.1.1","description":"Read file with extension fallback.","license":"MIT","repository":{"type":"git","url":"git+https://github.com/egoist/read-fallback.git"},"author":{"name":"EGOIST","email":"0x142857@gmail.com","url":"github.com/egoist"},"engines":{"node":">=4"},"scripts":{"test":"jest && eslint *.js"},"files":["index.js"],"keywords":["read","fallback"],"devDependencies":{"jest-cli":"^15.1.1","eslint":"latest","eslint-config-egoist":"latest"},"jest":{"testEnvironment":"node"},"eslintConfig":{"extends":"egoist/esnext"},"dependencies":{"path-exists":"^3.0.0"},"gitHead":"acba0f8faf881361b8d81a1e3866175694102c2a","bugs":{"url":"https://github.com/egoist/read-fallback/issues"},"homepage":"https://github.com/egoist/read-fallback#readme","_id":"read-fallback@0.1.1","_shasum":"03dedc11d75898b788bc263b24e36c97df5425b5","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.4.0","_npmUser":{"name":"rem","email":"0x142857@gmail.com"},"dist":{"shasum":"03dedc11d75898b788bc263b24e36c97df5425b5","tarball":"http://registry-npm.ywwl.com/read-fallback/download/read-fallback-0.1.1.tgz","integrity":"sha512-aBdeLXLtUNS07PXw66mD9yV9XJx+1Qfhj/gmYLT07to6DRyUByyUXYZQkGSGu6yxBs5gvWjslJFhh4UX6oMSkw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGzQqxd2wlVEWL7EloRtMN7zez22wCDfi41KAQ3JCIgIAiEAlEud2aw9mhNw3KOZc1CU3fH15QYikkcXUH3WblopRTo="}],"size":2543,"noattachment":false,"key":"/read-fallback/-/read-fallback-0.1.1.tgz"},"maintainers":[{"name":"rem","email":"0x142857@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/read-fallback-0.1.1.tgz_1475219881380_0.9989048829302192"},"directories":{},"publish_time":1475219881629,"_cnpm_publish_time":1475219881629},"0.1.0":{"name":"read-fallback","version":"0.1.0","description":"Read file with extension fallback.","license":"MIT","repository":{"type":"git","url":"git+https://github.com/egoist/read-fallback.git"},"author":{"name":"EGOIST","email":"0x142857@gmail.com","url":"github.com/egoist"},"engines":{"node":">=4"},"scripts":{"test":"jest && eslint *.js"},"files":["index.js"],"keywords":["read","fallback"],"devDependencies":{"jest-cli":"^15.1.1","eslint":"latest","eslint-config-egoist":"latest"},"jest":{"testEnvironment":"node"},"eslintConfig":{"extends":"egoist/esnext"},"dependencies":{"path-exists":"^3.0.0","pify":"^2.3.0"},"gitHead":"800d21f071797a341d1ae2b646386c1e040523a9","bugs":{"url":"https://github.com/egoist/read-fallback/issues"},"homepage":"https://github.com/egoist/read-fallback#readme","_id":"read-fallback@0.1.0","_shasum":"c9078af4c7a3715c02068976af4d3e4c0610d34c","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.4.0","_npmUser":{"name":"rem","email":"0x142857@gmail.com"},"dist":{"shasum":"c9078af4c7a3715c02068976af4d3e4c0610d34c","tarball":"http://registry-npm.ywwl.com/read-fallback/download/read-fallback-0.1.0.tgz","integrity":"sha512-dXiGAELNfJBNLwMkiK1goobKGREr4Fded19gw5FJEjbyyRnsrG6aL4bgc7rUc49fy++NSgKsMamJree+MrUu0g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDc4b15rZF5Ny5FIps/OG1QWGtXluf+gNTP4unniczs6QIgFB1Xxl6XlXEU3dmg7T9zA8jtLknhq9/aAXjBx3hImBI="}],"size":2555,"noattachment":false,"key":"/read-fallback/-/read-fallback-0.1.0.tgz"},"maintainers":[{"name":"rem","email":"0x142857@gmail.com"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/read-fallback-0.1.0.tgz_1475219851469_0.07485019066371024"},"directories":{},"publish_time":1475219853716,"_cnpm_publish_time":1475219853716}},"readme":"# read-fallback\n\n[![NPM version](https://img.shields.io/npm/v/read-fallback.svg?style=flat-square)](https://npmjs.com/package/read-fallback) [![NPM downloads](https://img.shields.io/npm/dm/read-fallback.svg?style=flat-square)](https://npmjs.com/package/read-fallback) [![Build Status](https://img.shields.io/circleci/project/egoist/read-fallback/master.svg?style=flat-square)](https://circleci.com/gh/egoist/read-fallback)\n\n## Install\n\n```bash\n$ npm install --save read-fallback\n```\n\n## Usage\n\nAssume that I have a `foo.txt` with content `bar`:\n\n```js\nconst read = require('read-fallback')\n\n// it looks for foo.md, sure it does not exist\n// then it looks for foo.txt, there it is\n// the last foo.xxx is skipped\nread('foo', {extensions: ['.md', '.txt', '.xxx']})\n  .then(data => {\n    if (data) {\n      console.log(data.file, data.content)\n      //=> foo.txt 'bar'\n    } else {\n      console.log('no matching file!')\n    }\n  })\n\n// use an array of file paths directly\n// because sometimes the filename is different too\nread(['foo.txt', 'bar.md'])\n```\n\n## API\n\n### readFallback(input, [options])\n\n#### input\n\nType: `string` or `array`\n\nAn array of file paths or a single file name.\n\n#### options\n\n##### extensions\n\nType: `array`  \n\nUsed when `input` is a string, eg: \n\n```js\n// looks for gulpfile.js then gulpfile.babel.js\nread('gulpfile', {extensions: ['.js', '.babel.js']})\n\n// if no extensions:\n// it simply reads `foo` only, without any extension\n// but yeah, it's not a common case\nread('foo')\n```\n\n#### handler\n\nType: `function`\n\nSpecific a handler function for reading file content, by default it's a promisified `fs.readFile` and returns `{file, content}` in the end.\n\nAny function which returns a Promise or does synchronus operations is valid.\n\n```js\n// you don't know what you have\n// but if a.js exists you do this\n// if a.ts exists you do that\nread(['a.js', 'a.ts'], {\n  handler(file, index) {\n    if (file === 'a.js') return require(path.resolve(file))\n    if (file === 'a.ts') return require(someTypeScriptParser(file))\n  }\n}).then(data => {\n  // the data isn't `{file, content}` anymore\n  // it's what you return in the last step\n  // here it's the result of require\n})\n```\n\n#### skipHandler\n\nType: `boolean`<br>\nDefault: `false`\n\nSimply return matched file path instead of using a handler function to read its content. In this way:\n\n```js\n// assume we have b.js\nread(['a.js', 'b.js'], {skipHandler: true})\n  .then(data => {\n    console.log(data)\n    //=> {file: 'b.js'}\n    // no data.content !!!\n  })\n```\n\n## Contributing\n\n1. Fork it!\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request :D\n\n## License\n\n[MIT](https://egoist.mit-license.org/) © [EGOIST](https://github.com/egoist)\n","_attachments":{},"homepage":"https://github.com/egoist/read-fallback#readme","bugs":{"url":"https://github.com/egoist/read-fallback/issues"},"license":"MIT"}