UNPKG

@dooboostore/dom-render

Version:
70 lines 2.34 kB
// within rangeResult.ts // @ts-ignore export class RangeResult { constructor(value, done) { this.done = done; this.value = value !== null && value !== void 0 ? value : 0; } } export class RangeIterator { constructor(first, last, step) { this._current = this._first = first; this._last = last; this._step = step; } next(value) { let r; if (this._first < this._last && this._current < this._last) { r = new RangeResult(this._current, false); this._current += this._step; } else if (this._first < this._last && this._current === this._last) { r = new RangeResult(this._current, false); this._current += this._step; } else if (this._first > this._last && this._current > this._last) { r = new RangeResult(this._current, false); this._current -= this._step; } else if (this._first > this._last && this._current === this._last) { r = new RangeResult(this._current, false); this._current -= this._step; } else if (this._current === this._last) { r = new RangeResult(this._current, false); this._current -= this._step; } else { r = new RangeResult(undefined, true); } return r; } } export class Range { constructor(first, last, step = 1) { this.first = first; this.last = last; this.step = step; this.isRange = true; } [Symbol.iterator]() { return new RangeIterator(this.first, this.last, this.step); } map(callbackfn, thisArg) { return Array.from(this).map(callbackfn); } static range(first, last, step = 1) { if (typeof first === 'number' && last === undefined) { return new Range(0, first, step); } else if (typeof first === 'string') { const [_first, _last = '0'] = first.split('..'); const [__last, _step = '1'] = _last.split(','); return new Range(Number(_first.trim()), Number(__last.trim()), Number(_step.trim())); } else { return new Range(first, last !== null && last !== void 0 ? last : 0, step); } } } //# sourceMappingURL=Range.js.map