From 0e0d5d35c053a64bc7c5a130f46acc0232e67279 Mon Sep 17 00:00:00 2001 From: Coston Perkins Date: Thu, 11 Apr 2019 08:18:49 -0500 Subject: [PATCH 1/4] Add href prop --- dist/obfuscate.js | 7 +++++-- pages/index.js | 6 ++++++ src/obfuscate.js | 5 ++++- test/obfuscate.test.js | 30 ++++++++++++++++++++---------- 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/dist/obfuscate.js b/dist/obfuscate.js index a3bd7b6e..8328ea74 100644 --- a/dist/obfuscate.js +++ b/dist/obfuscate.js @@ -76,6 +76,8 @@ function (_Component) { link = "sms:".concat(props.sms); } else if (props.facetime) { link = "facetime:".concat(props.facetime); + } else if (props.href) { + link = props.href; } else if (_typeof(props.children) !== 'object') { link = props.children; } else { @@ -124,13 +126,14 @@ function (_Component) { sms = _this$props.sms, facetime = _this$props.facetime, email = _this$props.email, + href = _this$props.href, headers = _this$props.headers, obfuscate = _this$props.obfuscate, linkText = _this$props.linkText, style = _this$props.style, - others = _objectWithoutProperties(_this$props, ["element", "children", "tel", "sms", "facetime", "email", "headers", "obfuscate", "linkText", "style"]); + others = _objectWithoutProperties(_this$props, ["element", "children", "tel", "sms", "facetime", "email", "href", "headers", "obfuscate", "linkText", "style"]); - var propsList = children || tel || sms || facetime || email; + var propsList = children || tel || sms || facetime || email || href; var obsStyle = _objectSpread({}, style || {}, { unicodeBidi: 'bidi-override', diff --git a/pages/index.js b/pages/index.js index 68087a1a..9b53a8fb 100644 --- a/pages/index.js +++ b/pages/index.js @@ -157,6 +157,12 @@ const headerCode = `
➡️ Facetime: +
+ ➡️ href: + Chat On WhatsApp +
+ ➡️ href: + Skype Me
➡️ Child Elements: diff --git a/src/obfuscate.js b/src/obfuscate.js index 3f04728e..2fb87c8f 100644 --- a/src/obfuscate.js +++ b/src/obfuscate.js @@ -32,6 +32,8 @@ export default class Obfuscate extends Component { link = `sms:${props.sms}` } else if (props.facetime) { link = `facetime:${props.facetime}` + } else if (props.href) { + link = props.href } else if (typeof props.children !== 'object') { link = props.children } else { @@ -81,6 +83,7 @@ export default class Obfuscate extends Component { sms, facetime, email, + href, headers, obfuscate, linkText, @@ -88,7 +91,7 @@ export default class Obfuscate extends Component { ...others } = this.props - const propsList = children || tel || sms || facetime || email + const propsList = children || tel || sms || facetime || email || href const obsStyle = { ...(style || {}), diff --git a/test/obfuscate.test.js b/test/obfuscate.test.js index b406fb13..9f3eb279 100755 --- a/test/obfuscate.test.js +++ b/test/obfuscate.test.js @@ -15,7 +15,7 @@ describe('obfuscate', () => { } }) - test('renders an ofuscated href', () => { + test('renders an obfuscated href', () => { const wrapper = shallow( ) @@ -23,7 +23,7 @@ describe('obfuscate', () => { expect(wrapper.prop('href')).toEqual('obfuscated') }) - test('properly sets location.href when ofuscated email is clicked', () => { + test('properly sets location.href when obfuscated email is clicked', () => { const wrapper = shallow( ) @@ -32,7 +32,7 @@ describe('obfuscate', () => { expect(global.window.location.href).toEqual(`mailto:${testEmail}`) }) - test('properly sets location.href when ofuscated email with headers is clicked', () => { + test('properly sets location.href when obfuscated email with headers is clicked', () => { const headers = { cc: 'dade@zero-cool.af', bcc: 'smith@machina.net', @@ -49,7 +49,7 @@ describe('obfuscate', () => { .join('&')}`) }) - test('properly sets location.href when ofuscated tel is clicked', () => { + test('properly sets location.href when obfuscated tel is clicked', () => { const wrapper = shallow( ) @@ -58,7 +58,17 @@ describe('obfuscate', () => { expect(global.window.location.href).toEqual(`tel:${testTel}`) }) - test('properly sets location.href when ofuscated sms is clicked', () => { + test('properly sets location.href when obfuscated href is clicked', () => { + const wrapper = shallow( + + ) + + wrapper.simulate('click', { preventDefault: () => {} }) + expect(global.window.location.href).toEqual(testTel) + }) + + + test('properly sets location.href when obfuscated sms is clicked', () => { const wrapper = shallow( ) @@ -67,7 +77,7 @@ describe('obfuscate', () => { expect(global.window.location.href).toEqual(`sms:${testTel}`) }) - test('properly sets location.href when ofuscated facetime is clicked', () => { + test('properly sets location.href when obfuscated facetime is clicked', () => { const wrapper = shallow( ) @@ -76,7 +86,7 @@ describe('obfuscate', () => { expect(global.window.location.href).toEqual(`facetime:${testTel}`) }) - test('properly sets location.href when ofuscated without type is clicked', () => { + test('properly sets location.href when obfuscated without type is clicked', () => { const wrapper = shallow( test ) @@ -85,7 +95,7 @@ describe('obfuscate', () => { expect(global.window.location.href).toEqual('test') }) - test('renders an unofuscated href when obfuscate prop equals false', () => { + test('renders an unobfuscated href when obfuscate prop equals false', () => { const wrapper = shallow( ) @@ -94,7 +104,7 @@ describe('obfuscate', () => { expect(wrapper.prop('href')).toEqual(`sms:${testTel}`) }) - test('renders an unofuscated child element left to right when obfuscate prop equals false', () => { + test('renders an unobfuscated child element left to right when obfuscate prop equals false', () => { const wrapper = shallow( ) @@ -103,7 +113,7 @@ describe('obfuscate', () => { expect(wrapper.prop('href')).toEqual(`facetime:${testTel}`) }) - test('renders an unofuscated child element right to left when obfuscated', () => { + test('renders an unobfuscated child element right to left when obfuscated', () => { const wrapper = shallow( ) From 7c413821c4d3b30801ae08d36ab74607aef27ebd Mon Sep 17 00:00:00 2001 From: Coston Perkins Date: Thu, 11 Apr 2019 08:23:25 -0500 Subject: [PATCH 2/4] 3.4.0-0 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 39f8674a..abf9b05d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "react-obfuscate", - "version": "3.3.1", + "version": "3.4.0-0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 50dc0b52..83144030 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-obfuscate", - "version": "3.3.1", + "version": "3.4.0-0", "description": "An intelligent React component to obfuscate any contact link", "main": "dist/obfuscate.js", "files": [ From 7048262925e2a50d3a52ae9ccb7de8a072121c50 Mon Sep 17 00:00:00 2001 From: Coston Perkins Date: Thu, 11 Apr 2019 08:44:39 -0500 Subject: [PATCH 3/4] Add href prop --- readme.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 71844fcd..0a536263 100644 --- a/readme.md +++ b/readme.md @@ -78,9 +78,10 @@ export default () => ( | tel | `string` | `` | `null` | telephone number of the intended recipient | | sms | `string` | `` | `null` | sms number of the intended recipient | | facetime | `string` | `` | `null` | facetime address of the intended recipient | +| href | `string` | `` | `null` | Obfuscate any other URL type | | headers | `object` | `` | `null` | subject, cc, bcc, body, etc | | obfuscate | `boolean` | `` | `true` | set to false to disable obfuscation | -| linkText | `string` | `` | `obfuscated` | add custom pre-interaction href attribute placeholder text | +| linkText | `string` | `` | `obfuscated` | add custom pre-interaction href attribute placeholder text | | element | `string` | `` | `'a'` | custom element to render instead of an `a` tag | | onClick | `function` | `` | `null` | called prior to setting location (e.g. for analytics tracking) | From fa2f6d5312e98ea230d3f6388eb2bd09ceb6f683 Mon Sep 17 00:00:00 2001 From: Coston Perkins Date: Thu, 11 Apr 2019 08:55:52 -0500 Subject: [PATCH 4/4] Update href demo --- pages/index.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pages/index.js b/pages/index.js index 9b53a8fb..92726bfc 100644 --- a/pages/index.js +++ b/pages/index.js @@ -158,11 +158,8 @@ const headerCode = ` ➡️ Facetime:
- ➡️ href: + ➡️ Any other URL: Chat On WhatsApp -
- ➡️ href: - Skype Me
➡️ Child Elements: