index.d.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. export interface Options {
  2. /**
  3. The current working directory.
  4. @default process.cwd()
  5. */
  6. readonly cwd?: URL | string;
  7. /**
  8. The type of path to match.
  9. @default 'file'
  10. */
  11. readonly type?: 'file' | 'directory';
  12. /**
  13. Allow symbolic links to match if they point to the requested path type.
  14. @default true
  15. */
  16. readonly allowSymlinks?: boolean;
  17. }
  18. export interface AsyncOptions extends Options {
  19. /**
  20. The number of concurrently pending promises.
  21. 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. Get the first path that exists on disk of multiple paths.
  34. @param paths - The paths to check.
  35. @returns The first path that exists or `undefined` if none exists.
  36. @example
  37. ```
  38. import {locatePath} from 'locate-path';
  39. const files = [
  40. 'unicorn.png',
  41. 'rainbow.png', // Only this one actually exists on disk
  42. 'pony.png'
  43. ];
  44. console(await locatePath(files));
  45. //=> 'rainbow'
  46. ```
  47. */
  48. export function locatePath(
  49. paths: Iterable<string>,
  50. options?: AsyncOptions
  51. ): Promise<string | undefined>;
  52. /**
  53. Synchronously get the first path that exists on disk of multiple paths.
  54. @param paths - The paths to check.
  55. @returns The first path that exists or `undefined` if none exists.
  56. @example
  57. ```
  58. import {locatePathSync} from 'locate-path';
  59. const files = [
  60. 'unicorn.png',
  61. 'rainbow.png', // Only this one actually exists on disk
  62. 'pony.png'
  63. ];
  64. console(locatePathSync(files));
  65. //=> 'rainbow'
  66. ```
  67. */
  68. export function locatePathSync(
  69. paths: Iterable<string>,
  70. options?: Options
  71. ): string | undefined;