source: node_modules/open/index.d.ts@ 65b6638

main
Last change on this file since 65b6638 was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/// <reference types="node"/>
2import {ChildProcess} from 'child_process';
3
4declare namespace open {
5 interface Options {
6 /**
7 Wait for the opened app to exit before fulfilling the promise. If `false` it's fulfilled immediately when opening the app.
8
9 Note that it waits for the app to exit, not just for the window to close.
10
11 On Windows, you have to explicitly specify an app for it to be able to wait.
12
13 @default false
14 */
15 readonly wait?: boolean;
16
17 /**
18 __macOS only__
19
20 Do not bring the app to the foreground.
21
22 @default false
23 */
24 readonly background?: boolean;
25
26 /**
27 Specify the app to open the `target` with, or an array with the app and app arguments.
28
29 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.
30
31 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.
32 */
33 readonly app?: string | readonly string[];
34
35 /**
36 __deprecated__
37
38 This option will be removed in the next major release.
39 */
40 readonly url?: boolean;
41
42 /**
43 Allow the opened app to exit with nonzero exit code when the `wait` option is `true`.
44
45 We do not recommend setting this option. The convention for success is exit code zero.
46
47 @default false
48 */
49 readonly allowNonzeroExitCode?: boolean;
50 }
51}
52
53/**
54Open stuff like URLs, files, executables. Cross-platform.
55
56Uses the command `open` on OS X, `start` on Windows and `xdg-open` on other platforms.
57
58There is a caveat for [double-quotes on Windows](https://github.com/sindresorhus/open#double-quotes-on-windows) where all double-quotes are stripped from the `target`.
59
60@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.
61@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.
62
63@example
64```
65import open = require('open');
66
67// Opens the image in the default image viewer
68(async () => {
69 await open('unicorn.png', {wait: true});
70 console.log('The image viewer app closed');
71
72 // Opens the url in the default browser
73 await open('https://sindresorhus.com');
74
75 // Specify the app to open in
76 await open('https://sindresorhus.com', {app: 'firefox'});
77
78 // Specify app arguments
79 await open('https://sindresorhus.com', {app: ['google chrome', '--incognito']});
80})();
81```
82*/
83declare function open(
84 target: string,
85 options?: open.Options
86): Promise<ChildProcess>;
87
88export = open;
Note: See TracBrowser for help on using the repository browser.