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.

numeric-range-iterator.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. 'use strict';
  2. var InternalStateModule = require('../internals/internal-state');
  3. var createIteratorConstructor = require('../internals/create-iterator-constructor');
  4. var isObject = require('../internals/is-object');
  5. var defineProperties = require('../internals/object-define-properties');
  6. var DESCRIPTORS = require('../internals/descriptors');
  7. var INCORRECT_RANGE = 'Incorrect Number.range arguments';
  8. var NUMERIC_RANGE_ITERATOR = 'NumericRangeIterator';
  9. var setInternalState = InternalStateModule.set;
  10. var getInternalState = InternalStateModule.getterFor(NUMERIC_RANGE_ITERATOR);
  11. var $RangeIterator = createIteratorConstructor(function NumericRangeIterator(start, end, option, type, zero, one) {
  12. if (typeof start != type || (end !== Infinity && end !== -Infinity && typeof end != type)) {
  13. throw new TypeError(INCORRECT_RANGE);
  14. }
  15. if (start === Infinity || start === -Infinity) {
  16. throw new RangeError(INCORRECT_RANGE);
  17. }
  18. var ifIncrease = end > start;
  19. var inclusiveEnd = false;
  20. var step;
  21. if (option === undefined) {
  22. step = undefined;
  23. } else if (isObject(option)) {
  24. step = option.step;
  25. inclusiveEnd = !!option.inclusive;
  26. } else if (typeof option == type) {
  27. step = option;
  28. } else {
  29. throw new TypeError(INCORRECT_RANGE);
  30. }
  31. if (step == null) {
  32. step = ifIncrease ? one : -one;
  33. }
  34. if (typeof step != type) {
  35. throw new TypeError(INCORRECT_RANGE);
  36. }
  37. if (step === Infinity || step === -Infinity || (step === zero && start !== end)) {
  38. throw new RangeError(INCORRECT_RANGE);
  39. }
  40. // eslint-disable-next-line no-self-compare -- NaN check
  41. var hitsEnd = start != start || end != end || step != step || (end > start) !== (step > zero);
  42. setInternalState(this, {
  43. type: NUMERIC_RANGE_ITERATOR,
  44. start: start,
  45. end: end,
  46. step: step,
  47. inclusiveEnd: inclusiveEnd,
  48. hitsEnd: hitsEnd,
  49. currentCount: zero,
  50. zero: zero
  51. });
  52. if (!DESCRIPTORS) {
  53. this.start = start;
  54. this.end = end;
  55. this.step = step;
  56. this.inclusive = inclusiveEnd;
  57. }
  58. }, NUMERIC_RANGE_ITERATOR, function next() {
  59. var state = getInternalState(this);
  60. if (state.hitsEnd) return { value: undefined, done: true };
  61. var start = state.start;
  62. var end = state.end;
  63. var step = state.step;
  64. var currentYieldingValue = start + (step * state.currentCount++);
  65. if (currentYieldingValue === end) state.hitsEnd = true;
  66. var inclusiveEnd = state.inclusiveEnd;
  67. var endCondition;
  68. if (end > start) {
  69. endCondition = inclusiveEnd ? currentYieldingValue > end : currentYieldingValue >= end;
  70. } else {
  71. endCondition = inclusiveEnd ? end > currentYieldingValue : end >= currentYieldingValue;
  72. }
  73. if (endCondition) {
  74. return { value: undefined, done: state.hitsEnd = true };
  75. } return { value: currentYieldingValue, done: false };
  76. });
  77. var getter = function (fn) {
  78. return { get: fn, set: function () { /* empty */ }, configurable: true, enumerable: false };
  79. };
  80. if (DESCRIPTORS) {
  81. defineProperties($RangeIterator.prototype, {
  82. start: getter(function () {
  83. return getInternalState(this).start;
  84. }),
  85. end: getter(function () {
  86. return getInternalState(this).end;
  87. }),
  88. inclusive: getter(function () {
  89. return getInternalState(this).inclusiveEnd;
  90. }),
  91. step: getter(function () {
  92. return getInternalState(this).step;
  93. })
  94. });
  95. }
  96. module.exports = $RangeIterator;