You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.2 KiB

4 years ago
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = consoleFunc;
  6. var _arrayEach = require('lodash/_arrayEach');
  7. var _arrayEach2 = _interopRequireDefault(_arrayEach);
  8. var _slice = require('./slice');
  9. var _slice2 = _interopRequireDefault(_slice);
  10. var _wrapAsync = require('./wrapAsync');
  11. var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
  12. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13. function consoleFunc(name) {
  14. return function (fn /*, ...args*/) {
  15. var args = (0, _slice2.default)(arguments, 1);
  16. args.push(function (err /*, ...args*/) {
  17. var args = (0, _slice2.default)(arguments, 1);
  18. if (typeof console === 'object') {
  19. if (err) {
  20. if (console.error) {
  21. console.error(err);
  22. }
  23. } else if (console[name]) {
  24. (0, _arrayEach2.default)(args, function (x) {
  25. console[name](x);
  26. });
  27. }
  28. }
  29. });
  30. (0, _wrapAsync2.default)(fn).apply(null, args);
  31. };
  32. }
  33. module.exports = exports['default'];