Skip to content

Commit 8121fdf

Browse files
committed
feat: allow configurable object to pass to opn
1 parent bca6614 commit 8121fdf

File tree

5 files changed

+3059
-2029
lines changed

5 files changed

+3059
-2029
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,16 @@ transport.sendMail(message).then(console.log).catch(console.error);
7272

7373
## Options
7474

75-
Note that you can also pass two additional arguments to `previewEmail` function.
75+
Note that you can also pass three additional arguments to `previewEmail` function.
7676

77-
These arguments are `id` and `open` (e.g. `previewEmail(message, id, open)`).
77+
These arguments are `id`, `open`, and `options` (e.g. `previewEmail(message, id, open, options)`).
7878

7979
By default we automatically set an `id` using `uuid.v4()` (see [uuid][] for more info).
8080

8181
Also, `open` is set to `true` by default - this means that we automatically open the browser for you.
8282

83+
The `options` argument is an Object which defaults to `{ wait: false }`. This object is passed along to [opn][]'s [options][opn-options].
84+
8385

8486
## Contributors
8587

@@ -108,3 +110,7 @@ Also, `open` is set to `true` by default - this means that we automatically open
108110
[uuid]: https://github.com/kelektiv/node-uuid
109111

110112
[lad]: https://lad.js.org
113+
114+
[opn]: https://github.com/sindresorhus/opn
115+
116+
[opn-options]: https://github.com/sindresorhus/opn#options

package.json

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
"Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com/)"
1212
],
1313
"dependencies": {
14-
"bluebird": "^3.5.1",
15-
"moment": "^2.22.2",
16-
"nodemailer": "^4.6.8",
17-
"opn": "^5.3.0",
14+
"bluebird": "^3.5.3",
15+
"moment": "^2.23.0",
16+
"nodemailer": "^5.1.1",
17+
"opn": "^5.4.0",
1818
"pug": "^2.0.3",
1919
"uuid": "^3.3.2"
2020
},
@@ -23,22 +23,22 @@
2323
"verbose": true
2424
},
2525
"devDependencies": {
26-
"auto-bind": "^1.2.1",
27-
"ava": "^0.25.0",
26+
"auto-bind": "^2.0.0",
27+
"ava": "^1.0.1",
2828
"babel-cli": "^6.26.0",
2929
"babel-preset-env": "^1.7.0",
30-
"codecov": "^3.0.4",
30+
"codecov": "^3.1.0",
3131
"cross-env": "^5.2.0",
32-
"eslint": "^5.4.0",
33-
"eslint-config-prettier": "^3.0.1",
34-
"eslint-plugin-prettier": "^2.6.2",
35-
"husky": "^0.14.3",
36-
"lint-staged": "^7.2.2",
37-
"nyc": "^12.0.2",
38-
"prettier": "^1.14.2",
39-
"remark-cli": "^5.0.0",
40-
"remark-preset-github": "^0.0.8",
41-
"xo": "^0.22.0"
32+
"eslint": "^5.12.0",
33+
"eslint-config-prettier": "^3.3.0",
34+
"eslint-plugin-prettier": "^3.0.1",
35+
"husky": "^1.3.1",
36+
"lint-staged": "^8.1.0",
37+
"nyc": "^13.1.0",
38+
"prettier": "^1.15.3",
39+
"remark-cli": "^6.0.1",
40+
"remark-preset-github": "^0.0.13",
41+
"xo": "^0.23.0"
4242
},
4343
"engines": {
4444
"node": ">=6.4.0"

src/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ const templateFilePath = path.join(__dirname, '..', 'template.pug');
1818

1919
const renderFilePromise = Promise.promisify(pug.renderFile);
2020

21-
const previewEmail = async (message, id, open = true) => {
21+
const previewEmail = async (
22+
message,
23+
id,
24+
open = true,
25+
options = { wait: false }
26+
) => {
2227
if (typeof message !== 'object')
2328
throw new Error('Message argument is required');
2429

@@ -40,7 +45,7 @@ const previewEmail = async (message, id, open = true) => {
4045
const filePath = `${os.tmpdir()}/${id}.html`;
4146
await writeFile(filePath, html);
4247

43-
if (open) await opn(filePath, { wait: false });
48+
if (open) await opn(filePath, options);
4449

4550
return `file://${filePath}`;
4651
};

test/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ test('does not open', async t => {
4242
});
4343

4444
test('invalid message', async t => {
45-
const error = await t.throws(previewEmail(false));
45+
const error = await t.throwsAsync(previewEmail(false));
4646
t.is(error.message, 'Message argument is required');
4747
});
4848

0 commit comments

Comments
 (0)