Socket
Socket
Sign inDemoInstall

opn

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

opn - npm Package Compare versions

Comparing version 4.0.2 to 5.0.0

31

index.js
'use strict';
var path = require('path');
var childProcess = require('child_process');
var objectAssign = require('object-assign');
var Promise = require('pinkie-promise');
const path = require('path');
const childProcess = require('child_process');
const isWsl = require('is-wsl');
module.exports = function (target, opts) {
module.exports = (target, opts) => {
if (typeof target !== 'string') {

@@ -12,8 +11,8 @@ return Promise.reject(new Error('Expected a `target`'));

opts = objectAssign({wait: true}, opts);
opts = Object.assign({wait: true}, opts);
var cmd;
var appArgs = [];
var args = [];
var cpOpts = {};
let cmd;
let appArgs = [];
let args = [];
const cpOpts = {};

@@ -35,4 +34,4 @@ if (Array.isArray(opts.app)) {

}
} else if (process.platform === 'win32') {
cmd = 'cmd';
} else if (process.platform === 'win32' || isWsl) {
cmd = 'cmd' + (isWsl ? '.exe' : '');
args.push('/c', 'start', '""');

@@ -64,3 +63,3 @@ target = target.replace(/&/g, '^&');

if (!opts.wait) {
// xdg-open will block the process unless
// `xdg-open` will block the process unless
// stdio is ignored even if it's unref'd

@@ -78,9 +77,9 @@ cpOpts.stdio = 'ignore';

var cp = childProcess.spawn(cmd, args, cpOpts);
const cp = childProcess.spawn(cmd, args, cpOpts);
if (opts.wait) {
return new Promise(function (resolve, reject) {
return new Promise((resolve, reject) => {
cp.once('error', reject);
cp.once('close', function (code) {
cp.once('close', code => {
if (code > 0) {

@@ -87,0 +86,0 @@ reject(new Error('Exited with code ' + code));

{
"name": "opn",
"version": "4.0.2",
"version": "5.0.0",
"description": "A better node-open. Opens stuff like websites, files, executables. Cross-platform.",

@@ -13,3 +13,3 @@ "license": "MIT",

"engines": {
"node": ">=0.10.0"
"node": ">=4"
},

@@ -51,4 +51,3 @@ "scripts": {

"dependencies": {
"object-assign": "^4.0.1",
"pinkie-promise": "^2.0.0"
"is-wsl": "^1.1.0"
},

@@ -55,0 +54,0 @@ "devDependencies": {

@@ -27,3 +27,3 @@ # opn

// opens the image in the default image viewer
// Opens the image in the default image viewer
opn('unicorn.png').then(() => {

@@ -33,9 +33,9 @@ // image viewer closed

// opens the url in the default browser
// Opens the url in the default browser
opn('http://sindresorhus.com');
// specify the app to open in
// Specify the app to open in
opn('http://sindresorhus.com', {app: 'firefox'});
// specify app arguments
// Specify app arguments
opn('http://sindresorhus.com', {app: ['google chrome', '--incognito']});

@@ -47,11 +47,10 @@ ```

Uses the command `open` on OS X, `start` on Windows and `xdg-open` on other platforms.
Uses the command `open` on macOS, `start` on Windows and `xdg-open` on other platforms.
### opn(target, [options])
Returns a promise for the [spawned child process](https://nodejs.org/api/child_process.html#child_process_class_childprocess). You'd 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.
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.
#### target
*Required*
Type: `string`

@@ -61,14 +60,14 @@

Opens in the default app for the file type. Eg. URLs opens in your default browser.
Opens in the default app for the file type. For example, URLs opens in your default browser.
#### options
Type: `object`
Type: `Object`
##### wait
Type: `boolean`
Type: `boolean`<br>
Default: `true`
Wait for the opened app to exit before calling the `callback`. If `false` it's called immediately when opening the app.
Wait for the opened app to exit before fulfilling the promise. If `false` it's fulfilled immediately when opening the app.

@@ -79,7 +78,7 @@ On Windows you have to explicitly specify an app for it to be able to wait.

Type: `string`, `array`
Type: `string` `Array`
Specify the app to open the `target` with, or an array with the app and app arguments.
The app name is platform dependent. Don't hard code it in reusable modules. Eg. Chrome is `google chrome` on OS X, `google-chrome` on Linux and `chrome` on Windows.
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.

@@ -94,2 +93,2 @@

MIT © [Sindre Sorhus](http://sindresorhus.com)
MIT © [Sindre Sorhus](https://sindresorhus.com)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc