consoleFunc.js 922 B

12345678910111213141516171819202122232425262728293031
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = consoleFunc;
  6. var _wrapAsync = require('./wrapAsync.js');
  7. var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. function consoleFunc(name) {
  10. return (fn, ...args) => (0, _wrapAsync2.default)(fn)(...args, (err, ...resultArgs) => {
  11. /* istanbul ignore else */
  12. if (typeof console === 'object') {
  13. /* istanbul ignore else */
  14. if (err) {
  15. /* istanbul ignore else */
  16. if (console.error) {
  17. console.error(err);
  18. }
  19. } else if (console[name]) {
  20. /* istanbul ignore else */
  21. resultArgs.forEach(x => console[name](x));
  22. }
  23. }
  24. });
  25. }
  26. module.exports = exports['default'];