{"_id":"closest-file-data","_rev":"254109","name":"closest-file-data","description":"Allow to find and retrieve some data (such as config file) related to a given path (with cache)","dist-tags":{"latest":"0.1.4"},"maintainers":[{"name":"huafu","email":"huafu.gandon@gmail.com"}],"time":{"modified":"2021-06-03T16:17:53.000Z","created":"2018-07-20T14:45:57.676Z","0.1.4":"2018-07-22T08:04:19.227Z","0.1.3":"2018-07-21T07:19:15.499Z","0.1.2":"2018-07-21T07:14:53.262Z","0.1.1":"2018-07-20T15:04:46.233Z","0.1.0":"2018-07-20T14:45:57.676Z"},"users":{},"author":{"name":"Huafu Gandon","email":"huafu.gandon@gmail.com"},"repository":{"type":"git","url":"https://github.com/huafu/closest-file-data.git"},"versions":{"0.1.4":{"name":"closest-file-data","version":"0.1.4","description":"Allow to find and retrieve some data (such as config file) related to a given path (with cache)","main":"./dist/index.js","typings":"./dist/index.d.ts","repository":{"type":"git","url":"https://github.com/huafu/closest-file-data.git"},"author":{"name":"Huafu Gandon","email":"huafu.gandon@gmail.com"},"license":"MIT","keywords":["relative","file","resource","config","search"],"devDependencies":{"@types/flat":"^0.0.28","@types/jest":"^23.3.0","@types/node":"^10.5.2","flat":"^4.1.0","jest":"<23","ts-jest":"<23","tslint":"^5.11.0","typescript":"^2.9.2"},"scripts":{"lint":"tslint --project .","test:unit":"jest","test:dist":"jest -c jest.config.dist.js","test:e2e":"jest -c jest.config.e2e.js","build":"tsc -p .","test":"npm run test:unit && npm run build && npm run test:dist && npm run test:e2e","prepublish":"npm run lint && npm run test"},"licenseText":"MIT License\n\nCopyright (c) 2018 Huafu Gandon\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"closest-file-data@0.1.4","dist":{"shasum":"975f87c132f299d24a0375b9f63ca3fb88f72b3a","size":216935,"noattachment":false,"key":"/closest-file-data/-/closest-file-data-0.1.4.tgz","tarball":"http://registry.cnpm.dingdandao.com/closest-file-data/download/closest-file-data-0.1.4.tgz"},"maintainers":[{"name":"huafu","email":"huafu.gandon@gmail.com"}],"_npmUser":{"name":"huafu","email":"huafu.gandon@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/closest-file-data_0.1.4_1532246659101_0.2655137566347665"},"_hasShrinkwrap":false,"publish_time":1532246659227,"_cnpm_publish_time":1532246659227},"0.1.3":{"name":"closest-file-data","version":"0.1.3","description":"Allow to find and retrieve some data (such as config file) related to a given path (with cache)","main":"./dist/index.js","typings":"./dist/index.d.ts","repository":{"type":"git","url":"https://github.com/huafu/closest-file-data.git"},"author":{"name":"Huafu Gandon","email":"huafu.gandon@gmail.com"},"license":"MIT","keywords":["relative","file","resource","config","search"],"devDependencies":{"@types/flat":"^0.0.28","@types/jest":"^23.3.0","@types/node":"^10.5.2","flat":"^4.1.0","jest":"<23","ts-jest":"<23","tslint":"^5.11.0","typescript":"^2.9.2"},"scripts":{"lint":"tslint --project .","test:unit":"jest","test:dist":"jest -c jest.config.dist.js","test:e2e":"jest -c jest.config.e2e.js","build":"tsc -p .","test":"npm run test:unit && npm run build && npm run test:dist && npm run test:e2e","prepublish":"npm run lint && npm run test"},"licenseText":"MIT License\n\nCopyright (c) 2018 Huafu Gandon\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"closest-file-data@0.1.3","dist":{"shasum":"23c564ca166767b91ea88dd65791495c3fc44a34","size":4373,"noattachment":false,"key":"/closest-file-data/-/closest-file-data-0.1.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/closest-file-data/download/closest-file-data-0.1.3.tgz"},"maintainers":[{"name":"huafu","email":"huafu.gandon@gmail.com"}],"_npmUser":{"name":"huafu","email":"huafu.gandon@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/closest-file-data_0.1.3_1532157555413_0.49193761681414583"},"_hasShrinkwrap":false,"publish_time":1532157555499,"_cnpm_publish_time":1532157555499},"0.1.2":{"name":"closest-file-data","version":"0.1.2","description":"Allow to find and retrieve some data (such as config file) related to a given path (with cache)","main":"./dist/index.js","typings":"./dist/index.d.ts","repository":{"type":"git","url":"https://github.com/huafu/closest-file-data.git"},"author":{"name":"Huafu Gandon","email":"huafu.gandon@gmail.com"},"license":"MIT","keywords":["relative","file","resource","config","search"],"devDependencies":{"@types/flat":"^0.0.28","@types/jest":"^23.3.0","@types/node":"^10.5.2","flat":"^4.1.0","jest":"<23","ts-jest":"<23","tslint":"^5.11.0","typescript":"^2.9.2"},"scripts":{"lint":"tslint --project .","test:unit":"jest","test:dist":"jest -c jest.config.dist.js","test:e2e":"jest -c jest.config.e2e.js","build":"tsc -p .","test":"npm run test:unit && npm run build && npm run test:dist && npm run test:e2e","prepublish":"npm run lint && npm run test"},"licenseText":"MIT License\n\nCopyright (c) 2018 Huafu Gandon\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"closest-file-data@0.1.2","dist":{"shasum":"1024e3bdc8744cd35ff4de16668bcf0bd63c7346","size":4382,"noattachment":false,"key":"/closest-file-data/-/closest-file-data-0.1.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/closest-file-data/download/closest-file-data-0.1.2.tgz"},"maintainers":[{"name":"huafu","email":"huafu.gandon@gmail.com"}],"_npmUser":{"name":"huafu","email":"huafu.gandon@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/closest-file-data_0.1.2_1532157292449_0.9952099493187772"},"_hasShrinkwrap":false,"publish_time":1532157293262,"_cnpm_publish_time":1532157293262},"0.1.1":{"name":"closest-file-data","version":"0.1.1","description":"Allow to find and retrieve some data (such as config file) related to a given path (with cache)","main":"./dist/index.js","typings":"./dist/index.d.ts","repository":{"type":"git","url":"https://github.com/huafu/closest-file-data.git"},"author":{"name":"Huafu Gandon","email":"huafu.gandon@gmail.com"},"license":"MIT","keywords":["relative","file","resource","config","search"],"devDependencies":{"@types/flat":"^0.0.28","@types/jest":"^23.3.0","@types/node":"^10.5.2","flat":"^4.1.0","jest":"<23","ts-jest":"<23","tslint":"^5.11.0","typescript":"^2.9.2"},"scripts":{"lint":"tslint --project .","test:unit":"jest","test:dist":"jest -c jest.config.dist.js","test:e2e":"jest -c jest.config.e2e.js","build":"tsc -p .","test":"npm run test:unit && npm run build && npm run test:dist && npm run test:e2e","prepublish":"npm run lint && npm run test"},"licenseText":"MIT License\n\nCopyright (c) 2018 Huafu Gandon\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"closest-file-data@0.1.1","dist":{"shasum":"cdc4d980b69706a2da34f26624363085c243aeaa","size":4388,"noattachment":false,"key":"/closest-file-data/-/closest-file-data-0.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/closest-file-data/download/closest-file-data-0.1.1.tgz"},"maintainers":[{"name":"huafu","email":"huafu.gandon@gmail.com"}],"_npmUser":{"name":"huafu","email":"huafu.gandon@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/closest-file-data_0.1.1_1532099086166_0.7353708716059362"},"_hasShrinkwrap":false,"publish_time":1532099086233,"_cnpm_publish_time":1532099086233},"0.1.0":{"name":"closest-file-data","version":"0.1.0","description":"Allow to find and retrieve some data (such as config file) related to a given path (with cache)","main":"./dist/index.js","typings":"./dist/index.d.ts","repository":{"type":"git","url":"https://github.com/huafu/closest-file-data.git"},"author":{"name":"Huafu Gandon","email":"huafu.gandon@gmail.com"},"license":"MIT","devDependencies":{"@types/flat":"^0.0.28","@types/jest":"^23.3.0","@types/node":"^10.5.2","flat":"^4.1.0","jest":"<23","ts-jest":"<23","tslint":"^5.11.0","typescript":"^2.9.2"},"scripts":{"lint":"tslint --project .","test:unit":"jest","test:dist":"jest -c jest.config.dist.js","test:e2e":"jest -c jest.config.e2e.js","build":"tsc -p .","test":"npm run test:unit && npm run build && npm run test:dist && npm run test:e2e","prepublish":"npm run lint && npm run test"},"licenseText":"MIT License\n\nCopyright (c) 2018 Huafu Gandon\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"closest-file-data@0.1.0","dist":{"shasum":"726373161ebd73ead6ade3fc7adb6cd925b5f748","size":4337,"noattachment":false,"key":"/closest-file-data/-/closest-file-data-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/closest-file-data/download/closest-file-data-0.1.0.tgz"},"maintainers":[{"name":"huafu","email":"huafu.gandon@gmail.com"}],"_npmUser":{"name":"huafu","email":"huafu.gandon@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/closest-file-data_0.1.0_1532097957582_0.153883243280317"},"_hasShrinkwrap":false,"publish_time":1532097957676,"_cnpm_publish_time":1532097957676}},"readme":"<img style=\"float: right; width: 48px;\" src=\"icon.png\"></img>\n\n# Closest File Data [![Build Status](https://travis-ci.org/huafu/closest-file-data.svg?branch=master)](https://travis-ci.org/huafu/closest-file-data) [![Beerpay](https://beerpay.io/huafu/closest-file-data/badge.svg?style=beer-square)](https://beerpay.io/huafu/closest-file-data)  [![Beerpay](https://beerpay.io/huafu/closest-file-data/make-wish.svg?style=flat-square)](https://beerpay.io/huafu/closest-file-data?focus=wish)\n\nA NodeJS module to find and retrieve data (such as config) related to a given path. No dependencies. Implements caching.\n\n## What is this?\n\n### TL;DR:\n\n```js\n// some/project/path\n// ├── package.json\n// └── src\n//     ├── index.js\n//     └── utils\n//         └── dummy.js\nconst pkg = closestFileData(\n  '/some/project/path/src/utils/dummy.js',\n  {basename: 'package.json', read: require}\n);\nconsole.log(pkg.version);\n```\n\n---\n\n### A more complex example\n\nLet's say you want to find some config data related to a given file. We'll take BabelJS for example. Their config can be\na `JSON` file in `.babelrc`, or a `JS` file in `.babelrc.js`, or even in the `babel` key of `package.json`.\nNow you are given the path of a file and you want to get the Babel config closest to that file... what a mess!\n\nWell, with this module now you can safely do:\n\n```js\nimport closestFileData from 'closest-file-data';\n\nconst babelReaders = [\n  // each line represents what is called a reader (see below):\n  { basename: '.babelrc', read: f => JSON.parse(readFileSync(f, 'utf-8')) },\n  { basename: '.babelrc.js', read: f => require(f) },\n  { basename: 'package.json', read: f => require(f).babel },\n];\n\nconst config = closestFileData('/path/to/some/deep/file.js', babelReaders);\n// `config` will be either the object representing the first config data found,\n// or `undefined` if no configuration found.\n```\n\n## What is a `reader`?\n\nA reader is an object with 2 properties:\n\n- **`basename`**: the basename of the file for which the `read` will be called with.\n- **`read`**: a method that should return either the data read for given file, or `undefined` if the `read` should\n  be considered without result (useful in the Babel case for example when there is no `babel` key in the `package.json`).\n\nThe second parameter to `closestFileData()` can be a single reader or an array of readers.\nIt will try a find a file with name `basename` in the given `path` (first argument of `closestFileData`) for each\ngiven reader, until one returns something else then `undefined`. If none, it'll go up one directory and start again,\nuntil it reaches the root of the filesystem.\n\n## Is it cached?\n\nYup, the cache is different per list of base names files in the set of readers given to `closestFileData()`.\nYou can also clear the cache if needed for testing purpose:\n\n```js\nimport closestFileData from 'closest-file-data';\n\n// ...\n\nclosestFileData.cache.clear();\n```\n\n### Installing\n\nAdd to your project with `npm`:\n\n```bash\nnpm install --save closest-file-data\n```\n\nor with `yarn`:\n\n```bash\nyarn add closest-file-data\n```\n\nEnd with an example of getting some data out of the system or using it for a little demo\n\n## Running the tests\n\nYou need to get a copy of the repository to run unit and integration tests:\n\n```bash\ngit clone https://github.com/huafu/closest-file-data.git\ncd closest-file-data\nnpm run test\n```\n\n### There is 3 test scripts:\n\n- `test:unit`: run tests using the typescript source in `src`, useful while developing.\n- `test:dist`: run tests using the built js version in `dist`, needs to have ran `build` before.\n- `test:e2e`: run real World tests without mocking the file-system, using the built js version in `dist`. Needs to have ran `build` before.\n\nThe `test` script run them all and takes care of building the sources before.\n\n## Built With\n\n* [TypeScript](https://www.typescriptlang.org/)\n\n## Contributing\n\nPull requests welcome!\n\n## Versioning\n\nWe use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/huafu/closest-file-data/tags). \n\n## Authors\n\n* **Huafu Gandon** - *Initial work* - [huafu](https://github.com/huafu)\n\nSee also the list of [contributors](https://github.com/huafu/closest-file-data/contributors) who participated in this project.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details\n\n## Support on Beerpay\nHey dude! Help me out for a couple of :beers:!\n\n[![Beerpay](https://beerpay.io/huafu/closest-file-data/badge.svg?style=beer-square)](https://beerpay.io/huafu/closest-file-data)  [![Beerpay](https://beerpay.io/huafu/closest-file-data/make-wish.svg?style=flat-square)](https://beerpay.io/huafu/closest-file-data?focus=wish)","_attachments":{},"license":"MIT"}