index.d.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. declare namespace locatePath {
  2. interface Options {
  3. /**
  4. Current working directory.
  5. @default process.cwd()
  6. */
  7. readonly cwd?: string;
  8. /**
  9. Type of path to match.
  10. @default 'file'
  11. */
  12. readonly type?: 'file' | 'directory';
  13. /**
  14. Allow symbolic links to match if they point to the requested path type.
  15. @default true
  16. */
  17. readonly allowSymlinks?: boolean;
  18. }
  19. interface AsyncOptions extends Options {
  20. /**
  21. Number of concurrently pending promises. Minimum: `1`.
  22. @default Infinity
  23. */
  24. readonly concurrency?: number;
  25. /**
  26. Preserve `paths` order when searching.
  27. Disable this to improve performance if you don't care about the order.
  28. @default true
  29. */
  30. readonly preserveOrder?: boolean;
  31. }
  32. }
  33. declare const locatePath: {
  34. /**
  35. Get the first path that exists on disk of multiple paths.
  36. @param paths - Paths to check.
  37. @returns The first path that exists or `undefined` if none exists.
  38. @example
  39. ```
  40. import locatePath = require('locate-path');
  41. const files = [
  42. 'unicorn.png',
  43. 'rainbow.png', // Only this one actually exists on disk
  44. 'pony.png'
  45. ];
  46. (async () => {
  47. console(await locatePath(files));
  48. //=> 'rainbow'
  49. })();
  50. ```
  51. */
  52. (paths: Iterable<string>, options?: locatePath.AsyncOptions): Promise<
  53. string | undefined
  54. >;
  55. /**
  56. Synchronously get the first path that exists on disk of multiple paths.
  57. @param paths - Paths to check.
  58. @returns The first path that exists or `undefined` if none exists.
  59. */
  60. sync(
  61. paths: Iterable<string>,
  62. options?: locatePath.Options
  63. ): string | undefined;
  64. };
  65. export = locatePath;