react-obfuscate
Advanced tools
Comparing version 3.6.8 to 3.6.9
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _typeof3 = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -7,66 +9,39 @@ value: true | ||
exports["default"] = void 0; | ||
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); | ||
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); | ||
var _react = _interopRequireWildcard(require("react")); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } | ||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } | ||
var Obfuscate = function Obfuscate(props) { | ||
var _excluded = ["element", "children", "tel", "sms", "facetime", "email", "href", "headers", "obfuscate", "obfuscateChildren", "linkText", "style", "onClick"]; | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof3(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
function Obfuscate(props) { | ||
var element = props.element, | ||
children = props.children, | ||
tel = props.tel, | ||
sms = props.sms, | ||
facetime = props.facetime, | ||
email = props.email, | ||
href = props.href, | ||
headers = props.headers, | ||
obfuscate = props.obfuscate, | ||
obfuscateChildren = props.obfuscateChildren, | ||
linkText = props.linkText, | ||
style = props.style, | ||
onClick = props.onClick, | ||
others = _objectWithoutProperties(props, ["element", "children", "tel", "sms", "facetime", "email", "href", "headers", "obfuscate", "obfuscateChildren", "linkText", "style", "onClick"]); | ||
children = props.children, | ||
tel = props.tel, | ||
sms = props.sms, | ||
facetime = props.facetime, | ||
email = props.email, | ||
href = props.href, | ||
headers = props.headers, | ||
obfuscate = props.obfuscate, | ||
obfuscateChildren = props.obfuscateChildren, | ||
linkText = props.linkText, | ||
style = props.style, | ||
onClick = props.onClick, | ||
others = (0, _objectWithoutProperties2["default"])(props, _excluded); | ||
var _useState = (0, _react.useState)(false), | ||
_useState2 = _slicedToArray(_useState, 2), | ||
humanInteraction = _useState2[0], | ||
setHumanInteraction = _useState2[1]; | ||
_useState2 = (0, _slicedToArray2["default"])(_useState, 2), | ||
humanInteraction = _useState2[0], | ||
setHumanInteraction = _useState2[1]; | ||
var linkProps = children || tel || sms || facetime || email || href; | ||
var Component = element; | ||
var generateLink = function generateLink() { | ||
var link; // Combine email header parameters for use with email | ||
var link; | ||
// Combine email header parameters for use with email | ||
var combineHeaders = function combineHeaders(params) { | ||
@@ -77,6 +52,4 @@ return Object.keys(params).map(function (key) { | ||
}; | ||
if (email) { | ||
link = "mailto:".concat(email); | ||
if (headers) { | ||
@@ -93,3 +66,3 @@ link += "?".concat(combineHeaders(headers)); | ||
link = href; | ||
} else if (_typeof(children) !== 'object') { | ||
} else if ((0, _typeof2["default"])(children) !== 'object') { | ||
link = children; | ||
@@ -99,6 +72,4 @@ } else { | ||
} | ||
return link; | ||
}; | ||
var handleClick = function handleClick() { | ||
@@ -109,5 +80,5 @@ // Allow instantiator to provide an onClick method to be called | ||
onClick(); | ||
} // If focused or hovered, this js will be skipped with preference for html | ||
} | ||
// If focused or hovered, this js will be skipped with preference for html | ||
if (humanInteraction === false) { | ||
@@ -125,7 +96,5 @@ window.location.href = generateLink({ | ||
}; | ||
var reverse = function reverse(content) { | ||
return typeof content !== 'undefined' && content.split('').reverse().join('').replace('(', ')').replace(')', '('); | ||
}; | ||
var obfuscatedStyle = _objectSpread(_objectSpread({}, style), {}, { | ||
@@ -135,4 +104,3 @@ unicodeBidi: 'bidi-override', | ||
}); | ||
var renderedLink = humanInteraction === true || obfuscate === false || _typeof(children) === 'object' || obfuscateChildren === false // Allow child elements | ||
var renderedLink = humanInteraction === true || obfuscate === false || (0, _typeof2["default"])(children) === 'object' || obfuscateChildren === false // Allow child elements | ||
? linkProps : reverse(linkProps); | ||
@@ -143,3 +111,3 @@ var clickProps = Component === 'a' ? { | ||
} : {}; | ||
return /*#__PURE__*/_react["default"].createElement(Component, _extends({ | ||
return /*#__PURE__*/_react["default"].createElement(Component, (0, _extends2["default"])({ | ||
onFocus: function onFocus() { | ||
@@ -157,4 +125,3 @@ return setHumanInteraction(true); | ||
}), renderedLink); | ||
}; | ||
} | ||
Obfuscate.propTypes = { | ||
@@ -161,0 +128,0 @@ element: _propTypes["default"].string, |
{ | ||
"name": "react-obfuscate", | ||
"version": "3.6.8", | ||
"version": "3.6.9", | ||
"description": "An intelligent React component to obfuscate any contact link", | ||
@@ -27,3 +27,3 @@ "main": "dist/obfuscate.js", | ||
"clean": "rm -rf dist && mkdir dist", | ||
"export": "yarn build-site && next export", | ||
"export": "npm run build-site && next export", | ||
"test": "jest", | ||
@@ -35,37 +35,38 @@ "test:watch": "jest --watch", | ||
"coveralls": "jest --coverage && cat ./coverage/lcov.info | coveralls", | ||
"preversion": "yarn test && yarn lint:fix && yarn clean && yarn build && yarn export", | ||
"preversion": "npm run test && npm run lint:fix && npm run clean && npm run build && npm run export", | ||
"postpublish": "git push && git push --tag" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "7.11.6", | ||
"@babel/core": "7.11.6", | ||
"@babel/plugin-transform-spread": "7.11.0", | ||
"@babel/preset-env": "7.11.5", | ||
"@babel/preset-react": "7.10.4", | ||
"@commitlint/cli": "11.0.0", | ||
"@commitlint/config-conventional": "11.0.0", | ||
"@babel/cli": "7.20.7", | ||
"@babel/core": "7.20.12", | ||
"@babel/plugin-transform-runtime": "7.19.6", | ||
"@babel/plugin-transform-spread": "7.20.7", | ||
"@babel/preset-env": "7.20.2", | ||
"@babel/preset-react": "7.18.6", | ||
"@commitlint/cli": "17.4.4", | ||
"@commitlint/config-conventional": "17.4.4", | ||
"babel-eslint": "10.1.0", | ||
"babel-jest": "26.3.0", | ||
"coveralls": "3.1.0", | ||
"babel-jest": "27.5.1", | ||
"coveralls": "3.1.1", | ||
"enzyme": "3.11.0", | ||
"enzyme-adapter-react-16": "1.15.4", | ||
"enzyme-to-json": "3.5.0", | ||
"eslint": "7.6.0", | ||
"eslint-config-airbnb": "18.2.0", | ||
"eslint-config-prettier": "6.11.0", | ||
"eslint-plugin-import": "2.22.0", | ||
"eslint-plugin-jsx-a11y": "6.3.1", | ||
"eslint-plugin-prettier": "3.1.4", | ||
"eslint-plugin-react": "7.20.5", | ||
"eslint-plugin-react-hooks": "4.0.8", | ||
"husky": "4.3.0", | ||
"jest": "26.4.2", | ||
"lint-staged": "10.2.11", | ||
"next": "9.5.3", | ||
"prettier": "2.0.5", | ||
"prop-types": "15.7.2", | ||
"react": "16.13.1", | ||
"react-dom": "16.13.1", | ||
"react-live": "2.2.2", | ||
"react-test-renderer": "16.13.1", | ||
"enzyme-adapter-react-16": "1.15.7", | ||
"enzyme-to-json": "3.6.2", | ||
"eslint": "8.34.0", | ||
"eslint-config-airbnb": "19.0.4", | ||
"eslint-config-prettier": "8.6.0", | ||
"eslint-plugin-import": "2.27.5", | ||
"eslint-plugin-jsx-a11y": "6.7.1", | ||
"eslint-plugin-prettier": "4.2.1", | ||
"eslint-plugin-react": "7.32.2", | ||
"eslint-plugin-react-hooks": "4.6.0", | ||
"husky": "8.0.3", | ||
"jest": "27.5.1", | ||
"lint-staged": "13.1.2", | ||
"next": "13.1.6", | ||
"prettier": "2.8.4", | ||
"prop-types": "15.8.1", | ||
"react": "18.2.0", | ||
"react-dom": "18.2.0", | ||
"react-live": "3.1.1", | ||
"react-test-renderer": "18.2.0", | ||
"react-window-ui": "2.2.0" | ||
@@ -77,2 +78,3 @@ }, | ||
], | ||
"testEnvironment": "jsdom", | ||
"collectCoverage": true, | ||
@@ -79,0 +81,0 @@ "snapshotSerializers": [ |
# react-obfuscate | ||
[![Coverage Status](https://coveralls.io/repos/github/coston/react-obfuscate/badge.svg?branch=master)](https://coveralls.io/github/coston/react-obfuscate?branch=master) | ||
[![Build Status](https://travis-ci.org/coston/react-obfuscate.svg?branch=master)](https://travis-ci.org/coston/react-obfuscate) | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/coston/react-obfuscate.svg)](https://greenkeeper.io/) | ||
![GitHub last commit](https://img.shields.io/github/last-commit/coston/react-obfuscate) | ||
[![npm version](https://badge.fury.io/js/react-obfuscate.svg)](https://www.npmjs.com/package/react-obfuscate) | ||
[![npm](https://img.shields.io/npm/dm/react-obfuscate.svg)](https://www.npmjs.com/package/react-obfuscate) | ||
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://prettier.io) | ||
![react-obfuscate](https://user-images.githubusercontent.com/7424180/28096225-c2f07142-666c-11e7-96ab-c12f34d1b86f.png) | ||
@@ -135,11 +133,13 @@ | ||
## 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. | ||
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 | ||
```js | ||
<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" | ||
<path | ||
fill="#000" | ||
d="M12 12.713L.0 3h23.97L12 12.713zm0 2.574L0 5.562V21h24V5" | ||
/> | ||
@@ -146,0 +146,0 @@ </svg> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17377
33
150