租房小程序前端代码
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.

125 lines
2.2 KiB

3 months ago
  1. # locate-path [![Build Status](https://travis-ci.com/sindresorhus/locate-path.svg?branch=master)](https://travis-ci.com/github/sindresorhus/locate-path)
  2. > Get the first path that exists on disk of multiple paths
  3. ## Install
  4. ```
  5. $ npm install locate-path
  6. ```
  7. ## Usage
  8. Here we find the first file that exists on disk, in array order.
  9. ```js
  10. const locatePath = require('locate-path');
  11. const files = [
  12. 'unicorn.png',
  13. 'rainbow.png', // Only this one actually exists on disk
  14. 'pony.png'
  15. ];
  16. (async () => {
  17. console(await locatePath(files));
  18. //=> 'rainbow'
  19. })();
  20. ```
  21. ## API
  22. ### locatePath(paths, options?)
  23. Returns a `Promise<string>` for the first path that exists or `undefined` if none exists.
  24. #### paths
  25. Type: `Iterable<string>`
  26. Paths to check.
  27. #### options
  28. Type: `object`
  29. ##### concurrency
  30. Type: `number`\
  31. Default: `Infinity`\
  32. Minimum: `1`
  33. Number of concurrently pending promises.
  34. ##### preserveOrder
  35. Type: `boolean`\
  36. Default: `true`
  37. Preserve `paths` order when searching.
  38. Disable this to improve performance if you don't care about the order.
  39. ##### cwd
  40. Type: `string`\
  41. Default: `process.cwd()`
  42. Current working directory.
  43. ##### type
  44. Type: `string`\
  45. Default: `'file'`\
  46. Values: `'file' | 'directory'`
  47. The type of paths that can match.
  48. ##### allowSymlinks
  49. Type: `boolean`\
  50. Default: `true`
  51. Allow symbolic links to match if they point to the chosen path type.
  52. ### locatePath.sync(paths, options?)
  53. Returns the first path that exists or `undefined` if none exists.
  54. #### paths
  55. Type: `Iterable<string>`
  56. Paths to check.
  57. #### options
  58. Type: `object`
  59. ##### cwd
  60. Same as above.
  61. ##### type
  62. Same as above.
  63. ##### allowSymlinks
  64. Same as above.
  65. ## Related
  66. - [path-exists](https://github.com/sindresorhus/path-exists) - Check if a path exists
  67. ---
  68. <div align="center">
  69. <b>
  70. <a href="https://tidelift.com/subscription/pkg/npm-locate-path?utm_source=npm-locate-path&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
  71. </b>
  72. <br>
  73. <sub>
  74. Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
  75. </sub>
  76. </div>