index.d.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /// <reference types="node"/>
  2. import {ChildProcess} from 'child_process';
  3. declare namespace open {
  4. interface Options {
  5. /**
  6. Wait for the opened app to exit before fulfilling the promise. If `false` it's fulfilled immediately when opening the app.
  7. Note that it waits for the app to exit, not just for the window to close.
  8. On Windows, you have to explicitly specify an app for it to be able to wait.
  9. @default false
  10. */
  11. readonly wait?: boolean;
  12. /**
  13. __macOS only__
  14. Do not bring the app to the foreground.
  15. @default false
  16. */
  17. readonly background?: boolean;
  18. /**
  19. Specify the app to open the `target` with, or an array with the app and app arguments.
  20. The app name is platform dependent. Don't hard code it in reusable modules. For example, Chrome is `google chrome` on macOS, `google-chrome` on Linux and `chrome` on Windows.
  21. You may also pass in the app's full path. For example on WSL, this can be `/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe` for the Windows installation of Chrome.
  22. */
  23. readonly app?: string | readonly string[];
  24. }
  25. }
  26. /**
  27. Open stuff like URLs, files, executables. Cross-platform.
  28. Uses the command `open` on OS X, `start` on Windows and `xdg-open` on other platforms.
  29. @param target - The thing you want to open. Can be a URL, file, or executable. Opens in the default app for the file type. For example, URLs open in your default browser.
  30. @returns The [spawned child process](https://nodejs.org/api/child_process.html#child_process_class_childprocess). You would normally not need to use this for anything, but it can be useful if you'd like to attach custom event listeners or perform other operations directly on the spawned process.
  31. @example
  32. ```
  33. import open = require('open');
  34. // Opens the image in the default image viewer
  35. (async () => {
  36. await open('unicorn.png', {wait: true});
  37. console.log('The image viewer app closed');
  38. // Opens the url in the default browser
  39. await open('https://sindresorhus.com');
  40. // Specify the app to open in
  41. await open('https://sindresorhus.com', {app: 'firefox'});
  42. // Specify app arguments
  43. await open('https://sindresorhus.com', {app: ['google chrome', '--incognito']});
  44. })();
  45. ```
  46. */
  47. declare function open(
  48. target: string,
  49. options?: open.Options
  50. ): Promise<ChildProcess>;
  51. export = open;