@drewsonne/maya-dates
Version:
Typescript package to manipulate dates in the Maya Calendar
74 lines • 2.84 kB
JavaScript
;
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 = _super.call(this, (typeof value === 'number') ?
lookup.getValue(value) :
value) || 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