Skip to content

Commit ae3a461

Browse files
committed
feat: add TO support for email sharer
1 parent 1042e92 commit ae3a461

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ email({
230230
})
231231
```
232232

233+
You can use `getEmailUrl(options)` for getting URL.
234+
233235
### `linkedin(options)`
234236

235237
Share on LinkedIn

src/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { fbShare, getFbShareUrl } from './sharers/fbShare';
33
import { fbButton, getFbButtonUrl } from './sharers/fbButton';
44
import gp from './sharers/gp';
55
import mail from './sharers/mail';
6-
import email from './sharers/email';
6+
import { email, getEmailUrl } from './sharers/email';
77
import { ok, getOkUrl } from './sharers/ok';
88
import { telegram, getTelegramUrl } from './sharers/telegram';
99
import { tw, getTwUrl } from './sharers/tw';
@@ -31,7 +31,7 @@ export {
3131
vk, getVkUrl,
3232
ok, getOkUrl,
3333
mail,
34-
email,
34+
email, getEmailUrl,
3535
linkedin,
3636

3737
whatsapp, getWhatsappUrl,

src/sharers/email.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import encodeParams from '../utils/encodeParams';
22

3-
export default function email(options = {}) {
3+
export function getEmailUrl(options = {}) {
44
const {
5-
url, title, description, subject,
5+
to, url, title, description, subject,
66
} = options;
7+
78
const params = encodeParams({
89
subject,
910
body: `${title || ''}\r\n${description || ''}\r\n${url || ''}`,
1011
});
11-
return window.location.assign(`mailto:?${params}`);
12+
13+
return `mailto:${to || ''}?${params}`;
14+
}
15+
16+
export function email(options = {}) {
17+
return window.location.assign(getEmailUrl(options));
1218
}

src/sharers/tests/email.test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import faker from 'faker';
22

3-
import email from '../email';
3+
import { email } from '../email';
44

55
describe('email', () => {
66
beforeEach(() => {
@@ -13,6 +13,12 @@ describe('email', () => {
1313
expect(window.location.assign).toBeCalledWith('mailto:?body=%0D%0A%0D%0A');
1414
});
1515

16+
it('should call with to', () => {
17+
const fixture = faker.internet.email();
18+
email({ to: fixture });
19+
expect(window.location.assign).toBeCalledWith(`mailto:${fixture}?body=%0D%0A%0D%0A`);
20+
});
21+
1622
it('should call with url', () => {
1723
const fixture = faker.internet.url();
1824
email({ url: fixture });

vanilla-sharing.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ export function ok(...args: any[]): any;
3030
export function getOkUrl(...args: any[]): string;
3131

3232
export function mail(...args: any[]): any;
33+
3334
export function email(...args: any[]): any;
35+
export function getEmailUrl(...args: any[]): any;
36+
3437
export function linkedin(...args: any[]): any;
3538

3639
export function whatsapp(...args: any[]): any;

0 commit comments

Comments
 (0)