3.6.9 • Published 1 year ago

react-obfuscate v3.6.9

Weekly downloads
3,153
License
MIT
Repository
github
Last release
1 year ago

react-obfuscate

Coverage Status GitHub last commit npm version npm

react-obfuscate

Demo & Examples

Live demo: react-obfuscate.coston.io

How it works

The user passes the contact link as an email, tel, sms, facetime, or href prop. The component obfuscates href data until a hover, click, or focus event. Links are given their proper URL schemes (mailto, facetime, etc.) The link is rendered in reverse in the dom, but reversed again with css. This making the link useless for spammers, but user friendly on screen.

Why

The world needs obfuscated links that display the link in a friendly way.

Installation

npm install --save react-obfuscate

Input

import React from 'react';
import Obfuscate from 'react-obfuscate';

export default () => (
  <p>
    Phone: <Obfuscate tel="205-454-1234" />
    <br />
    Email:{' '}
    <Obfuscate
      email="hello@coston.io"
      headers={{
        cc: 'dade@zero-cool.af',
        bcc: 'smith@machina.net',
        subject: 'react-obfuscate',
        body: 'Down with the machines!',
      }}
    />
  </p>
);

Output

Robot Interaction

<p>
  Phone:
  <a href="obfuscated" style="direction: rtl; unicode-bidi: bidi-override;"
    >4321-454-502</a
  ><br />
  Email:
  <a href="obfuscated" style="direction: rtl; unicode-bidi: bidi-override;"
    >oi.notsoc@olleh</a
  >
</p>

Human Interaction

<p>
  Phone: <a href="tel:205-454-1234">205-454-1234</a><br>
  Email: <a href="mailto:hello@coston.io?cc=kate%40acidburn.af&amp;bcc=tanderson%40metacortex.net&amp;subject=react-obfuscate&amp;body=Down%20with%20the%20machines!">hello@coston.io</a>
</p>

Common Options

PropTypeDefaultDescription
emailstringnullemail address of the intended recipient
headersobjectnullsubject, cc, bcc, body, etc
telstringnulltelephone number of the intended recipient
smsstringnullsms number of the intended recipient
facetimestringnullfacetime address of the intended recipient
hrefstringnullObfuscate any other URL type (e.g. WhatsApp)

Uncommon Options

PropTypeDefaultDescription
linkTextstring'obfuscated'add custom pre-interaction href attribute placeholder text
obfuscatebooleantrueset to false to disable obfuscation
obfuscateChildrenbooleantrueset to false to disable obfuscation of children
elementstring'a'use if you want to override the default a tag
onClickfunctionnullcalled prior to setting location (e.g. for analytics tracking)

Development

npm start

Consecutive Obfuscate/inline elements

react-obfuscate is an inline element. Using consecutive inline elements inside a block element causes an issue with the bidi-override reversal on Chrome. To prevent this, add any text between the elements, wrap <Obfuscate/> with another element (like <span>), or add style={{display:'inline-block'}} to prevent any issues.

Example Case:

<address>
  <Obfuscate style={{ display: 'inline-block' }} email="-mail@mailbox.org" />
  <br />
  <Obfuscate style={{ display: 'inline-block' }} tel="+69 111 222 333" />
</address>

Obfuscating custom elements with the element prop

With the element prop, users can obfuscate any element, like paragraphs or headers. Changing the dom element also removes the href and onClick props. Custom styling is required due to handling of right-to-left direction styles. Usually, adding style={{textAlign:'left'}} will suffice.

Example Case:

<Obfuscate element="p" style={{ textAlign: 'left' }}>
  This paragraph is more secret than others.
</Obfuscate>

Children

By default, objects are not reversed in the dom, but other types are. The obfuscateChildren prop set will disabled this functionality when set to false. If the child is an object, like html elements are, it will be rendered normally.

Example Use Case
<Obfuscate email="hello@coston.io" aria-label="Email Me">
  <svg width={24} height={21}>
    <path
      fill="#000"
      d="M12 12.713L.0 3h23.97L12 12.713zm0 2.574L0 5.562V21h24V5"
    />
  </svg>
</Obfuscate>

Contributors

react-obfuscate is awesome thanks to these community members:

Contributing

Please help make this react component better. Feel free to submit an issue, or contribute through a pull request.

License

Licensed under the MIT license.

3.6.9

1 year ago

3.6.8

4 years ago

3.6.7

4 years ago

3.7.2-0

4 years ago

3.7.0-0

4 years ago

3.7.1-0

4 years ago

3.6.6

4 years ago

3.6.5

4 years ago

3.6.4

4 years ago

3.6.2

5 years ago

3.6.1

5 years ago

3.6.0

5 years ago

3.5.0

5 years ago

3.5.0-0

5 years ago

3.4.0

5 years ago

3.4.0-0

5 years ago

3.3.1

5 years ago

3.3.1-0

5 years ago

3.3.0-0

5 years ago

3.2.1

5 years ago

3.2.0

5 years ago

3.1.1

5 years ago

3.1.0

5 years ago

3.0.0

5 years ago

2.2.3

5 years ago

2.2.2

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.10

6 years ago

2.1.9

6 years ago

2.1.8

6 years ago

2.1.7

6 years ago

2.1.6

6 years ago

2.1.5

6 years ago

2.1.4

6 years ago

2.1.3

6 years ago

2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.4.0

6 years ago

1.3.3

6 years ago

1.3.2

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.20

7 years ago

1.0.19

7 years ago

1.0.18

7 years ago

1.0.17

7 years ago

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago