版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 2.2 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <p align="center">
  2. <a href="http://gulpjs.com">
  3. <img height="257" width="114" src="https://raw.githubusercontent.com/gulpjs/artwork/master/gulp-2x.png">
  4. </a>
  5. </p>
  6. # fined
  7. [![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][ci-image]][ci-url] [![Coveralls Status][coveralls-image]][coveralls-url]
  8. Find a file given a declaration of locations.
  9. ## Usage
  10. ```js
  11. var fined = require('fined');
  12. fined({ path: 'path/to/file', extensions: ['.js', '.json'] });
  13. // => { path: '/absolute/path/to/file.js', extension: '.js' } (if file exists)
  14. // => null (if file does not exist)
  15. var opts = {
  16. name: '.app',
  17. cwd: '.',
  18. extensions: {
  19. rc: 'default-rc-loader',
  20. '.yml': 'default-yml-loader',
  21. },
  22. };
  23. fined({ path: '.' }, opts);
  24. // => { path: '/absolute/of/cwd/.app.yml', extension: { '.yml': 'default-yml-loader' } }
  25. fined({ path: '~', extensions: { rc: 'some-special-rc-loader' } }, opts);
  26. // => { path: '/User/home/.apprc', extension: { 'rc': 'some-special-rc-loader' } }
  27. ```
  28. ## API
  29. ### fined(pathObj, opts) => object | null
  30. #### Arguments:
  31. - **pathObj** [string | object] : a path setting for finding a file.
  32. - **opts** [object] : a plain object supplements `pathObj`.
  33. `pathObj` and `opts` can have same properties:
  34. - **path** [string] : a path string.
  35. - **name** [string] : a basename.
  36. - **extensions**: [string | array | object] : extensions.
  37. - **cwd**: a base directory of `path` and for finding up.
  38. - **findUp**: [boolean] : a flag to find up.
  39. #### Return:
  40. This function returns a plain object which consists of following properties if a file exists otherwise null.
  41. - **path** : an absolute path
  42. - **extension** : a string or a plain object of extension.
  43. ## License
  44. MIT
  45. <!-- prettier-ignore-start -->
  46. [downloads-image]: https://img.shields.io/npm/dm/fined.svg?style=flat-square
  47. [npm-url]: https://www.npmjs.com/package/fined
  48. [npm-image]: https://img.shields.io/npm/v/fined.svg?style=flat-square
  49. [ci-url]: https://github.com/gulpjs/fined/actions?query=workflow:dev
  50. [ci-image]: https://img.shields.io/github/workflow/status/gulpjs/fined/dev?style=flat-square
  51. [coveralls-url]: https://coveralls.io/r/gulpjs/fined
  52. [coveralls-image]: https://img.shields.io/coveralls/gulpjs/fined/master.svg
  53. <!-- prettier-ignore-end -->