index.d.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import {MergeExclusive} from 'type-fest';
  2. declare namespace tempy {
  3. type Options = MergeExclusive<
  4. {
  5. /**
  6. _You usually won't need this option. Specify it only when actually needed._
  7. File extension. Mutually exclusive with the `name` option.
  8. */
  9. readonly extension?: string;
  10. },
  11. {
  12. /**
  13. _You usually won't need this option. Specify it only when actually needed._
  14. Filename. Mutually exclusive with the `extension` option.
  15. */
  16. readonly name?: string;
  17. }
  18. >;
  19. }
  20. declare const tempy: {
  21. /**
  22. Get a temporary file path you can write to.
  23. @example
  24. ```
  25. import tempy = require('tempy');
  26. tempy.file();
  27. //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4f504b9edb5ba0e89451617bf9f971dd'
  28. tempy.file({extension: 'png'});
  29. //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/a9fb0decd08179eb6cf4691568aa2018.png'
  30. tempy.file({name: 'unicorn.png'});
  31. //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/f7f62bfd4e2a05f1589947647ed3f9ec/unicorn.png'
  32. tempy.directory();
  33. //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6'
  34. ```
  35. */
  36. file(options?: tempy.Options): string;
  37. /**
  38. Get a temporary directory path. The directory is created for you.
  39. @example
  40. ```
  41. import tempy = require('tempy');
  42. tempy.directory();
  43. //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6'
  44. ```
  45. */
  46. directory(): string;
  47. /**
  48. Get the root temporary directory path. For example: `/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T`.
  49. */
  50. readonly root: string;
  51. };
  52. export = tempy;