source: frontend/node_modules/open/readme.md

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 5.5 KB
Line 
1# open
2
3> Open stuff like URLs, files, executables. Cross-platform.
4
5This is meant to be used in command-line tools and scripts, not in the browser.
6
7If you need this for Electron, use [`shell.openPath()`](https://www.electronjs.org/docs/api/shell#shellopenpathpath) instead.
8
9This package does not make any security guarantees. If you pass in untrusted input, it's up to you to properly sanitize it.
10
11#### Why?
12
13- Actively maintained.
14- Supports app arguments.
15- Safer as it uses `spawn` instead of `exec`.
16- Fixes most of the original `node-open` issues.
17- Includes the latest [`xdg-open` script](https://gitlab.freedesktop.org/xdg/xdg-utils/-/blob/master/scripts/xdg-open.in) for Linux.
18- Supports WSL paths to Windows apps.
19
20## Install
21
22```sh
23npm install open
24```
25
26## Usage
27
28```js
29const open = require('open');
30
31// Opens the image in the default image viewer and waits for the opened app to quit.
32await open('unicorn.png', {wait: true});
33console.log('The image viewer app quit');
34
35// Opens the URL in the default browser.
36await open('https://sindresorhus.com');
37
38// Opens the URL in a specified browser.
39await open('https://sindresorhus.com', {app: {name: 'firefox'}});
40
41// Specify app arguments.
42await open('https://sindresorhus.com', {app: {name: 'google chrome', arguments: ['--incognito']}});
43
44// Open an app
45await open.openApp('xcode');
46
47// Open an app with arguments
48await open.openApp(open.apps.chrome, {arguments: ['--incognito']});
49```
50
51## API
52
53It uses the command `open` on macOS, `start` on Windows and `xdg-open` on other platforms.
54
55### open(target, options?)
56
57Returns a promise for 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.
58
59#### target
60
61Type: `string`
62
63The thing you want to open. Can be a URL, file, or executable.
64
65Opens in the default app for the file type. For example, URLs opens in your default browser.
66
67#### options
68
69Type: `object`
70
71##### wait
72
73Type: `boolean`\
74Default: `false`
75
76Wait for the opened app to exit before fulfilling the promise. If `false` it's fulfilled immediately when opening the app.
77
78Note that it waits for the app to exit, not just for the window to close.
79
80On Windows, you have to explicitly specify an app for it to be able to wait.
81
82##### background <sup>(macOS only)</sup>
83
84Type: `boolean`\
85Default: `false`
86
87Do not bring the app to the foreground.
88
89##### newInstance <sup>(macOS only)</sup>
90
91Type: `boolean`\
92Default: `false`
93
94Open a new instance of the app even it's already running.
95
96A new instance is always opened on other platforms.
97
98##### app
99
100Type: `{name: string | string[], arguments?: string[]} | Array<{name: string | string[], arguments: string[]}>`
101
102Specify the `name` of the app to open the `target` with, and optionally, app `arguments`. `app` can be an array of apps to try to open and `name` can be an array of app names to try. If each app fails, the last error will be thrown.
103
104The 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. If possible, use [`open.apps`](#openapps) which auto-detects the correct binary to use.
105
106You 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.
107
108The app `arguments` are app dependent. Check the app's documentation for what arguments it accepts.
109
110##### allowNonzeroExitCode
111
112Type: `boolean`\
113Default: `false`
114
115Allow the opened app to exit with nonzero exit code when the `wait` option is `true`.
116
117We do not recommend setting this option. The convention for success is exit code zero.
118
119### open.apps
120
121An object containing auto-detected binary names for common apps. Useful to work around [cross-platform differences](#app).
122
123```js
124const open = require('open');
125
126await open('https://google.com', {
127 app: {
128 name: open.apps.chrome
129 }
130});
131```
132
133#### Supported apps
134
135- [`chrome`](https://www.google.com/chrome) - Web browser
136- [`firefox`](https://www.mozilla.org/firefox) - Web browser
137- [`edge`](https://www.microsoft.com/edge) - Web browser
138
139### open.openApp(name, options?)
140
141Open an app.
142
143Returns a promise for 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.
144
145#### name
146
147Type: `string`
148
149The 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. If possible, use [`open.apps`](#openapps) which auto-detects the correct binary to use.
150
151You 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.
152
153#### options
154
155Type: `object`
156
157Same options as [`open`](#options) except `app` and with the following additions:
158
159##### arguments
160
161Type: `string[]`\
162Default: `[]`
163
164Arguments passed to the app.
165
166These arguments are app dependent. Check the app's documentation for what arguments it accepts.
167
168## Related
169
170- [open-cli](https://github.com/sindresorhus/open-cli) - CLI for this module
171- [open-editor](https://github.com/sindresorhus/open-editor) - Open files in your editor at a specific line and column
Note: See TracBrowser for help on using the repository browser.