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