react-obfuscate
Advanced tools
Comparing version 3.6.6 to 3.7.0-0
@@ -10,2 +10,6 @@ "use strict"; | ||
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; } | ||
@@ -15,2 +19,4 @@ | ||
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; } | ||
@@ -22,155 +28,157 @@ | ||
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 _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 _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; } | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } | ||
function _typeof(obj) { 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 _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { 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 _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
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 _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
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; } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
var Obfuscate = 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"]); | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
var _useState = (0, _react.useState)(false), | ||
_useState2 = _slicedToArray(_useState, 2), | ||
humanInteraction = _useState2[0], | ||
setHumanInteraction = _useState2[1]; | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
var linkProps = children || tel || sms || facetime || email || href; | ||
var Component = element; | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
var generateLink = function generateLink() { | ||
var link; // Combine email header parameters for use with email | ||
var Obfuscate = | ||
/*#__PURE__*/ | ||
function (_Component) { | ||
_inherits(Obfuscate, _Component); | ||
function Obfuscate(props) { | ||
var _this; | ||
_classCallCheck(this, Obfuscate); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Obfuscate).call(this, props)); | ||
_this.state = { | ||
humanInteraction: false | ||
var combineHeaders = function combineHeaders(params) { | ||
return Object.keys(params).map(function (key) { | ||
return "".concat(key, "=").concat(encodeURIComponent(params[key])); | ||
}).join('&'); | ||
}; | ||
return _this; | ||
} // Convert contact information to contact URL scheme | ||
if (email) { | ||
link = "mailto:".concat(email); | ||
_createClass(Obfuscate, [{ | ||
key: "createContactLink", | ||
value: function createContactLink(props) { | ||
var link; // Combine email header parameters for use with email | ||
var combineHeaders = function combineHeaders(params) { | ||
return Object.keys(params).map(function (key) { | ||
return "".concat(key, "=").concat(encodeURIComponent(params[key])); | ||
}).join('&'); | ||
}; | ||
if (props.email) { | ||
link = "mailto:".concat(props.email); | ||
if (props.headers) { | ||
link += "?".concat(combineHeaders(props.headers)); | ||
} | ||
} else if (props.tel) { | ||
link = "tel:".concat(props.tel); | ||
} else if (props.sms) { | ||
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 { | ||
return ''; | ||
if (headers) { | ||
link += "?".concat(combineHeaders(headers)); | ||
} | ||
return link; | ||
} else if (tel) { | ||
link = "tel:".concat(tel); | ||
} else if (sms) { | ||
link = "sms:".concat(sms); | ||
} else if (facetime) { | ||
link = "facetime:".concat(facetime); | ||
} else if (href) { | ||
link = href; | ||
} else if (_typeof(children) !== 'object') { | ||
link = children; | ||
} else { | ||
return ''; | ||
} | ||
}, { | ||
key: "handleClick", | ||
value: function handleClick(event) { | ||
var onClick = this.props.onClick; // If focused or hovered, this js will be skipped with preference for html | ||
if (this.state.humanInteraction === false) { | ||
event.preventDefault(); // Allow instantiator to provide an onClick method to be called | ||
// before we change location (e.g. for analytics tracking) | ||
return link; | ||
}; | ||
if (onClick && typeof onClick === 'function') { | ||
onClick(); | ||
} | ||
var handleClick = function handleClick() { | ||
// If focused or hovered, this js will be skipped with preference for html | ||
if (humanInteraction === false) { | ||
// Allow instantiator to provide an onClick method to be called | ||
// before we change location (e.g. for analytics tracking) | ||
if (onClick && typeof onClick === 'function') { | ||
onClick(); | ||
} | ||
window.location.href = this.createContactLink(this.props); | ||
} | ||
} | ||
}, { | ||
key: "handleCopiability", | ||
value: function handleCopiability() { | ||
this.setState({ | ||
humanInteraction: true | ||
window.location.href = generateLink({ | ||
email: email, | ||
headers: headers, | ||
tel: tel, | ||
sms: sms, | ||
facetime: facetime, | ||
href: href, | ||
children: children | ||
}); | ||
} | ||
}, { | ||
key: "reverse", | ||
value: function reverse(string) { | ||
if (typeof string !== 'undefined') { | ||
return string.split('').reverse().join('').replace('(', ')').replace(')', '('); | ||
} | ||
} | ||
}, { | ||
key: "render", | ||
value: function render() { | ||
var humanInteraction = this.state.humanInteraction; | ||
}; | ||
var _this$props = this.props, | ||
_this$props$element = _this$props.element, | ||
Element = _this$props$element === void 0 ? 'a' : _this$props$element, | ||
children = _this$props.children, | ||
tel = _this$props.tel, | ||
sms = _this$props.sms, | ||
facetime = _this$props.facetime, | ||
email = _this$props.email, | ||
href = _this$props.href, | ||
headers = _this$props.headers, | ||
obfuscate = _this$props.obfuscate, | ||
obfuscateChildren = _this$props.obfuscateChildren, | ||
linkText = _this$props.linkText, | ||
style = _this$props.style, | ||
others = _objectWithoutProperties(_this$props, ["element", "children", "tel", "sms", "facetime", "email", "href", "headers", "obfuscate", "obfuscateChildren", "linkText", "style"]); | ||
var reverse = function reverse(content) { | ||
return typeof content !== 'undefined' && content.split('').reverse().join('').replace('(', ')').replace(')', '('); | ||
}; | ||
var propsList = children || tel || sms || facetime || email || href; | ||
var isClearText = humanInteraction === true || obfuscate === false || obfuscateChildren === false; | ||
var obsStyle = _objectSpread({}, style || {}, { | ||
unicodeBidi: 'bidi-override', | ||
direction: humanInteraction === true || obfuscate === false || obfuscateChildren === false ? 'ltr' : 'rtl' | ||
}); | ||
var obfuscatedStyle = _objectSpread({}, style, { | ||
unicodeBidi: 'bidi-override', | ||
writingMode: isClearText ? 'inherit' : 'horizontal-bt', | ||
direction: isClearText ? 'ltr' : 'rtl' | ||
}); | ||
var link = humanInteraction === true || obfuscate === false || _typeof(children) === 'object' || obfuscateChildren === false // Allow child elements | ||
? propsList : this.reverse(propsList); | ||
var clickProps = Element === 'a' ? { | ||
href: humanInteraction === true || obfuscate === false ? this.createContactLink(this.props) : linkText || 'obfuscated', | ||
onClick: this.handleClick.bind(this) | ||
} : {}; | ||
var props = _objectSpread({ | ||
onFocus: this.handleCopiability.bind(this), | ||
onMouseOver: this.handleCopiability.bind(this), | ||
onContextMenu: this.handleCopiability.bind(this) | ||
}, others, {}, clickProps, { | ||
style: obsStyle | ||
}); | ||
return _react["default"].createElement(Element, props, link); | ||
var renderedLink = humanInteraction === true || obfuscate === false || _typeof(children) === 'object' || obfuscateChildren === false // Allow child elements | ||
? linkProps : reverse(linkProps); | ||
var clickProps = Component === 'a' ? { | ||
href: humanInteraction === true || obfuscate === false ? generateLink() : linkText || 'obfuscated', | ||
onClick: handleClick | ||
} : {}; | ||
return _react["default"].createElement(Component, _extends({ | ||
onFocus: function onFocus() { | ||
return setHumanInteraction(true); | ||
}, | ||
onMouseOver: function onMouseOver() { | ||
return setHumanInteraction(true); | ||
}, | ||
onContextMenu: function onContextMenu() { | ||
return setHumanInteraction(true); | ||
} | ||
}]); | ||
}, others, clickProps, { | ||
style: obfuscatedStyle | ||
}), renderedLink); | ||
}; | ||
return Obfuscate; | ||
}(_react.Component); | ||
exports["default"] = Obfuscate; | ||
Obfuscate.propTypes = { | ||
element: _propTypes["default"].string, | ||
children: _propTypes["default"].node, | ||
tel: _propTypes["default"].string, | ||
sms: _propTypes["default"].string, | ||
facetime: _propTypes["default"].string, | ||
email: _propTypes["default"].string, | ||
href: _propTypes["default"].string, | ||
headers: _propTypes["default"].shape({}), | ||
obfuscate: _propTypes["default"].bool, | ||
obfuscateChildren: _propTypes["default"].bool, | ||
linkText: _propTypes["default"].string, | ||
style: _propTypes["default"].shape({}), | ||
onClick: _propTypes["default"].func | ||
}; | ||
Obfuscate.defaultProps = { | ||
element: 'a', | ||
children: undefined, | ||
tel: undefined, | ||
sms: undefined, | ||
facetime: undefined, | ||
email: undefined, | ||
href: undefined, | ||
headers: undefined, | ||
obfuscate: undefined, | ||
obfuscateChildren: undefined, | ||
linkText: undefined, | ||
style: {}, | ||
onClick: undefined | ||
}; | ||
var _default = Obfuscate; | ||
exports["default"] = _default; |
{ | ||
"name": "react-obfuscate", | ||
"version": "3.6.6", | ||
"version": "3.7.0-0", | ||
"description": "An intelligent React component to obfuscate any contact link", | ||
@@ -27,30 +27,45 @@ "main": "dist/obfuscate.js", | ||
"clean": "rm -rf dist && mkdir dist", | ||
"export": "npm run build-site && next export", | ||
"format": "prettier --write src/**/*.{js,jsx}", | ||
"export": "yarn build-site && next export", | ||
"test": "jest", | ||
"test:watch": "jest --watch", | ||
"test:coverage": "jest --coverage", | ||
"lint": "eslint --ext=js --ext=jsx ./src", | ||
"lint:fix": "eslint --ext=js --ext=jsx ./src --fix", | ||
"coveralls": "jest --coverage && cat ./coverage/lcov.info | coveralls", | ||
"preversion": "npm run test && npm run format && npm run clean && npm run build && npm run export", | ||
"preversion": "yarn test && yarn lint:fix && yarn clean && yarn build && yarn export", | ||
"postpublish": "git push && git push --tag" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.8.3", | ||
"@babel/core": "^7.8.0", | ||
"@babel/plugin-transform-spread": "^7.8.3", | ||
"@babel/preset-env": "^7.8.2", | ||
"@babel/preset-react": "^7.8.0", | ||
"babel-jest": "^24.9.0", | ||
"coveralls": "^3.0.6", | ||
"enzyme": "^3.10.0", | ||
"enzyme-adapter-react-16": "^1.14.0", | ||
"enzyme-to-json": "^3.4.0", | ||
"jest": "^24.9.0", | ||
"next": "^9.1.5", | ||
"prettier": "^1.18.2", | ||
"react": "^16.9.0", | ||
"react-dom": "^16.9.0", | ||
"react-live": "^2.2.0", | ||
"react-test-renderer": "^16.9.0", | ||
"react-window-ui": "^2.1.0" | ||
"@babel/cli": "7.8.4", | ||
"@babel/core": "7.8.7", | ||
"@babel/plugin-transform-spread": "7.8.3", | ||
"@babel/preset-env": "7.8.7", | ||
"@babel/preset-react": "7.8.3", | ||
"@commitlint/cli": "8.3.5", | ||
"@commitlint/config-conventional": "8.3.4", | ||
"babel-eslint": "10.1.0", | ||
"babel-jest": "25.2.4", | ||
"coveralls": "3.0.11", | ||
"enzyme": "3.11.0", | ||
"enzyme-adapter-react-16": "1.15.2", | ||
"enzyme-to-json": "3.4.4", | ||
"eslint": "6.8.0", | ||
"eslint-config-airbnb": "18.1.0", | ||
"eslint-config-prettier": "6.10.1", | ||
"eslint-plugin-import": "2.20.2", | ||
"eslint-plugin-jsx-a11y": "6.2.3", | ||
"eslint-plugin-prettier": "3.1.2", | ||
"eslint-plugin-react": "7.19.0", | ||
"eslint-plugin-react-hooks": "3.0.0", | ||
"husky": "4.2.3", | ||
"jest": "25.2.4", | ||
"lint-staged": "10.1.1", | ||
"next": "9.3.2", | ||
"prettier": "2.0.2", | ||
"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", | ||
"react-window-ui": "2.1.0" | ||
}, | ||
@@ -69,3 +84,23 @@ "jest": { | ||
}, | ||
"dependencies": {} | ||
"peerDependencies": { | ||
"prop-types": ">= 15", | ||
"react": ">= 16.8", | ||
"react-dom": ">= 16.8" | ||
}, | ||
"lint-staged": { | ||
"*.{js,jsx}": [ | ||
"eslint --fix" | ||
] | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS", | ||
"pre-commit": "lint-staged" | ||
} | ||
}, | ||
"commitlint": { | ||
"extends": [ | ||
"@commitlint/config-conventional" | ||
] | ||
} | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
18846
157
3
32
1
1