项目原始demo,不改动
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
Questo repository è archiviato. Puoi vedere i file e clonarli, ma non puoi effettuare richieste di pushj o aprire problemi/richieste di pull.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # opn
  2. > A better [node-open](https://github.com/pwnall/node-open). Opens stuff like websites, files, executables. Cross-platform.
  3. #### Why?
  4. - Actively maintained
  5. - Supports app arguments
  6. - Safer as it uses `spawn` instead of `exec`
  7. - Fixes most of the open `node-open` issues
  8. - Includes the latest [`xdg-open` script](http://cgit.freedesktop.org/xdg/xdg-utils/commit/?id=c55122295c2a480fa721a9614f0e2d42b2949c18) for Linux
  9. ## Install
  10. ```
  11. $ npm install opn
  12. ```
  13. ## Usage
  14. ```js
  15. const opn = require('opn');
  16. // Opens the image in the default image viewer
  17. opn('unicorn.png').then(() => {
  18. // image viewer closed
  19. });
  20. // Opens the url in the default browser
  21. opn('http://sindresorhus.com');
  22. // Specify the app to open in
  23. opn('http://sindresorhus.com', {app: 'firefox'});
  24. // Specify app arguments
  25. opn('http://sindresorhus.com', {app: ['google chrome', '--incognito']});
  26. ```
  27. ## API
  28. Uses the command `open` on macOS, `start` on Windows and `xdg-open` on other platforms.
  29. ### opn(target, [options])
  30. Returns 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.
  31. #### target
  32. Type: `string`
  33. The thing you want to open. Can be a URL, file, or executable.
  34. Opens in the default app for the file type. For example, URLs opens in your default browser.
  35. #### options
  36. Type: `Object`
  37. ##### wait
  38. Type: `boolean`<br>
  39. Default: `true`
  40. Wait for the opened app to exit before fulfilling the promise. If `false` it's fulfilled immediately when opening the app.
  41. On Windows you have to explicitly specify an app for it to be able to wait.
  42. ##### app
  43. Type: `string` `Array`
  44. Specify the app to open the `target` with, or an array with the app and app arguments.
  45. 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.
  46. ## Related
  47. - [opn-cli](https://github.com/sindresorhus/opn-cli) - CLI for this module
  48. ## License
  49. MIT © [Sindre Sorhus](https://sindresorhus.com)