UNPKG

@drewsonne/maya-dates

Version:

Typescript package to manipulate dates in the Maya Calendar

79 lines 3.04 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var wildcard_1 = require("../../wildcard"); var base_1 = __importDefault(require("./base")); var Cycle = (function (_super) { __extends(Cycle, _super); function Cycle(value, lookup, generator) { var _this = this; var resolvedValue = (typeof value === 'number') ? lookup.getValue(value) : value; if (resolvedValue === undefined) { throw new Error("Value not found in lookup for index ".concat(value)); } _this = _super.call(this, resolvedValue) || this; _this.generator = generator; _this.cycleLength = lookup.length; _this.nextHolder = null; if (typeof _this.value === 'string') { _this.position = lookup.getIndex(_this.value); } else { throw new Error("Position could not be set."); } return _this; } Cycle.prototype.next = function () { return this.shift(1); }; Cycle.prototype.shift = function (incremental) { if (incremental === 0) { return this; } return this.nextCalculator().shift(incremental - 1); }; Cycle.prototype.nextCalculator = function () { if (this.nextHolder === null) { var newPosition = (this.position + 1) % (this.cycleLength - 1); newPosition = (newPosition === 0) ? (this.cycleLength - 1) : newPosition; var potentialPosition = this.generator(newPosition); if ((0, wildcard_1.isWildcard)(potentialPosition)) { throw new Error("Can not cycle with wildcrd"); } else { this.nextHolder = potentialPosition; } } if (this.nextHolder !== null) { return this.nextHolder; } else { throw new Error("Can not cycle with wildcrd"); } }; Cycle.prototype.toString = function () { return "".concat(this.value); }; return Cycle; }(base_1.default)); exports.default = Cycle; //# sourceMappingURL=cycle.js.map