Socket
Socket
Sign inDemoInstall

@evo/errcatch

Package Overview
Dependencies
8
Maintainers
14
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.2 to 1.0.1

dist/index.d.ts

4

babel.config.js
module.exports = (api) => {
api.cache(false);
return {
"presets": ["@babel/preset-env", "@babel/preset-react"],
return {
"presets": ["@babel/preset-env", "@babel/preset-react", "@babel/preset-typescript"],
"plugins": ["@babel/plugin-proposal-class-properties"],
}
}
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.setErrCatchLog = setErrCatchLog;
exports.withErrCatch = exports.ErrCatch = void 0;
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
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 _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
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); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
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; }
var logError = function logError(msg, error, info) {
console.error(msg, error, info);
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.withErrCatch = exports.ErrCatch = exports.setErrCatchLog = void 0;
var react_1 = __importDefault(require("react"));
var logError = function (msg, error, info) {
console.error(msg, error, info);
};
function setErrCatchLog(fn) {
logError = fn;
logError = fn;
}
var ErrCatch =
/*#__PURE__*/
function (_React$Component) {
_inherits(ErrCatch, _React$Component);
_createClass(ErrCatch, null, [{
key: "getDerivedStateFromError",
value: function getDerivedStateFromError() {
// Update state so the next render will show the fallback UI.
return {
hasError: true
};
exports.setErrCatchLog = setErrCatchLog;
var ErrCatch = /** @class */ (function (_super) {
__extends(ErrCatch, _super);
function ErrCatch(props) {
var _this = _super.call(this, props) || this;
_this.state = { hasError: false };
return _this;
}
}]);
function ErrCatch(props) {
var _this;
_classCallCheck(this, ErrCatch);
_this = _possibleConstructorReturn(this, _getPrototypeOf(ErrCatch).call(this, props));
_this.state = {
hasError: false
ErrCatch.getDerivedStateFromError = function () {
// Update state so the next render will show the fallback UI.
return { hasError: true };
};
return _this;
}
_createClass(ErrCatch, [{
key: "componentDidCatch",
value: function componentDidCatch(error, info) {
// You can also log the error to an error reporting service
var msg = "".concat(this.props.name, ": ").concat(this.props.message);
logError(msg, error, info);
}
}, {
key: "render",
value: function render() {
if (this.state.hasError) {
if (this.props.errorComponent) return this.props.errorComponent; // You can render any custom fallback UI
if (process.env.NODE_ENV !== 'production') {
// skip error boundary on the server (give a chance on a client)
if (typeof window === 'undefined') return null;
return _react.default.createElement("div", {
style: {
border: '3px solid red',
minHeight: '20px',
minWidth: '20px',
color: 'red',
textAlign: 'center',
fontWeight: 'bold'
},
"data-qaid": "err_catch_trace"
}, "ERR");
ErrCatch.prototype.componentDidCatch = function (error, info) {
// You can also log the error to an error reporting service
var msg = this.props.name + ": " + this.props.message;
logError(msg, error, info);
};
ErrCatch.prototype.render = function () {
if (this.state.hasError) {
if (this.props.errorComponent)
return this.props.errorComponent;
// You can render any custom fallback UI
if (process.env.NODE_ENV !== 'production') {
// skip error boundary on the server (give a chance on a client)
if (typeof window === 'undefined')
return null;
return (react_1.default.createElement("div", { style: {
border: '3px solid red',
minHeight: '20px',
minWidth: '20px',
color: 'red',
textAlign: 'center',
fontWeight: 'bold',
}, "data-qaid": 'err_catch_trace' }, "ERR"));
}
return null;
}
return null;
}
return this.props.children;
}
}]);
return ErrCatch;
}(_react.default.Component);
return this.props.children;
};
ErrCatch.defaultProps = {
message: 'Failed to render component',
name: 'Component render error',
};
return ErrCatch;
}(react_1.default.Component));
exports.ErrCatch = ErrCatch;
_defineProperty(ErrCatch, "propTypes", {
message: _propTypes.default.string,
name: _propTypes.default.string,
errorComponent: _propTypes.default.any
});
_defineProperty(ErrCatch, "defaultProps", {
message: 'Failed to render component',
name: 'Component render error'
});
var withErrCatch = function withErrCatch(Component, name) {
return function (props) {
var displayName = name || "ErrCatch".concat(Component.displayName);
return _react.default.createElement(ErrCatch, {
name: displayName
}, _react.default.createElement(Component, props));
};
};
exports.withErrCatch = withErrCatch;
var withErrCatch = function (Component, name) { return function (props) {
var displayName = name || "ErrCatch" + Component.displayName;
return (react_1.default.createElement(ErrCatch, { name: displayName },
react_1.default.createElement(Component, __assign({}, props))));
}; };
exports.withErrCatch = withErrCatch;
{
"name": "@evo/errcatch",
"version": "0.1.2",
"version": "1.0.1",
"description": "Catch react errors",

@@ -8,3 +8,3 @@ "main": "dist/index.js",

"test": "jest src",
"build": "babel -d dist src"
"build": "tsc"
},

@@ -19,3 +19,2 @@ "repository": {

"react": "^16.8.6",
"prop-types": "^15.7.2",
"react-dom": "^16.8.6"

@@ -29,6 +28,10 @@ },

"@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "7.16.0",
"@types/enzyme": "^3.10.10",
"@types/jest": "26.0.23",
"@types/react": "16.8.6",
"typescript": "4.4.4",
"enzyme": "^3.9.0",
"enzyme-adapter-react-16": "^1.11.2",
"jest": "^24.5.0",
"prop-types": "^15.7.2",
"react": "^16.8.6",

@@ -35,0 +38,0 @@ "react-dom": "^16.8.6"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc