Ohm-Management - Projektarbeit B-ME
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.

createTester.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = _createTester;
  6. var _noop = require('lodash/noop');
  7. var _noop2 = _interopRequireDefault(_noop);
  8. var _breakLoop = require('./breakLoop');
  9. var _breakLoop2 = _interopRequireDefault(_breakLoop);
  10. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11. function _createTester(check, getResult) {
  12. return function (eachfn, arr, iteratee, cb) {
  13. cb = cb || _noop2.default;
  14. var testPassed = false;
  15. var testResult;
  16. eachfn(arr, function (value, _, callback) {
  17. iteratee(value, function (err, result) {
  18. if (err) {
  19. callback(err);
  20. } else if (check(result) && !testResult) {
  21. testPassed = true;
  22. testResult = getResult(true, value);
  23. callback(null, _breakLoop2.default);
  24. } else {
  25. callback();
  26. }
  27. });
  28. }, function (err) {
  29. if (err) {
  30. cb(err);
  31. } else {
  32. cb(null, testPassed ? testResult : getResult(false));
  33. }
  34. });
  35. };
  36. }
  37. module.exports = exports['default'];