Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
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.

eachOf.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _isArrayLike = require('./internal/isArrayLike');
  6. var _isArrayLike2 = _interopRequireDefault(_isArrayLike);
  7. var _breakLoop = require('./internal/breakLoop');
  8. var _breakLoop2 = _interopRequireDefault(_breakLoop);
  9. var _eachOfLimit = require('./eachOfLimit');
  10. var _eachOfLimit2 = _interopRequireDefault(_eachOfLimit);
  11. var _once = require('./internal/once');
  12. var _once2 = _interopRequireDefault(_once);
  13. var _onlyOnce = require('./internal/onlyOnce');
  14. var _onlyOnce2 = _interopRequireDefault(_onlyOnce);
  15. var _wrapAsync = require('./internal/wrapAsync');
  16. var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
  17. var _awaitify = require('./internal/awaitify');
  18. var _awaitify2 = _interopRequireDefault(_awaitify);
  19. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  20. // eachOf implementation optimized for array-likes
  21. function eachOfArrayLike(coll, iteratee, callback) {
  22. callback = (0, _once2.default)(callback);
  23. var index = 0,
  24. completed = 0,
  25. { length } = coll,
  26. canceled = false;
  27. if (length === 0) {
  28. callback(null);
  29. }
  30. function iteratorCallback(err, value) {
  31. if (err === false) {
  32. canceled = true;
  33. }
  34. if (canceled === true) return;
  35. if (err) {
  36. callback(err);
  37. } else if (++completed === length || value === _breakLoop2.default) {
  38. callback(null);
  39. }
  40. }
  41. for (; index < length; index++) {
  42. iteratee(coll[index], index, (0, _onlyOnce2.default)(iteratorCallback));
  43. }
  44. }
  45. // a generic version of eachOf which can handle array, object, and iterator cases.
  46. function eachOfGeneric(coll, iteratee, callback) {
  47. return (0, _eachOfLimit2.default)(coll, Infinity, iteratee, callback);
  48. }
  49. /**
  50. * Like [`each`]{@link module:Collections.each}, except that it passes the key (or index) as the second argument
  51. * to the iteratee.
  52. *
  53. * @name eachOf
  54. * @static
  55. * @memberOf module:Collections
  56. * @method
  57. * @alias forEachOf
  58. * @category Collection
  59. * @see [async.each]{@link module:Collections.each}
  60. * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
  61. * @param {AsyncFunction} iteratee - A function to apply to each
  62. * item in `coll`.
  63. * The `key` is the item's key, or index in the case of an array.
  64. * Invoked with (item, key, callback).
  65. * @param {Function} [callback] - A callback which is called when all
  66. * `iteratee` functions have finished, or an error occurs. Invoked with (err).
  67. * @returns {Promise} a promise, if a callback is omitted
  68. * @example
  69. *
  70. * var obj = {dev: "/dev.json", test: "/test.json", prod: "/prod.json"};
  71. * var configs = {};
  72. *
  73. * async.forEachOf(obj, function (value, key, callback) {
  74. * fs.readFile(__dirname + value, "utf8", function (err, data) {
  75. * if (err) return callback(err);
  76. * try {
  77. * configs[key] = JSON.parse(data);
  78. * } catch (e) {
  79. * return callback(e);
  80. * }
  81. * callback();
  82. * });
  83. * }, function (err) {
  84. * if (err) console.error(err.message);
  85. * // configs is now a map of JSON data
  86. * doSomethingWith(configs);
  87. * });
  88. */
  89. function eachOf(coll, iteratee, callback) {
  90. var eachOfImplementation = (0, _isArrayLike2.default)(coll) ? eachOfArrayLike : eachOfGeneric;
  91. return eachOfImplementation(coll, (0, _wrapAsync2.default)(iteratee), callback);
  92. }
  93. exports.default = (0, _awaitify2.default)(eachOf, 3);
  94. module.exports = exports['default'];