@drewsonne/maya-dates
Version:
Typescript package to manipulate dates in the Maya Calendar
105 lines • 3.79 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 });
exports.HaabMonth = exports.getHaabMonth = exports.HaabMonths = void 0;
var hashMap_1 = __importDefault(require("../../structs/hashMap"));
var wildcard_1 = require("../../wildcard");
var cycle_1 = __importDefault(require("./cycle"));
var HaabMonths;
(function (HaabMonths) {
HaabMonths["POP"] = "Pop";
HaabMonths["WO"] = "Wo";
HaabMonths["SIP"] = "Sip";
HaabMonths["SOTZ"] = "Sotz'";
HaabMonths["SEK"] = "Sek";
HaabMonths["XUL"] = "Xul";
HaabMonths["YAXK_IN"] = "Yaxk'in";
HaabMonths["MOL"] = "Mol";
HaabMonths["CH_EN"] = "Ch'en";
HaabMonths["YAX"] = "Yax";
HaabMonths["SAK"] = "Sak";
HaabMonths["KEH"] = "Keh";
HaabMonths["MAK"] = "Mak";
HaabMonths["K_ANK_IN"] = "K'ank'in";
HaabMonths["MUWAN"] = "Muwan";
HaabMonths["PAX"] = "Pax";
HaabMonths["K_AYAB"] = "K'ayab";
HaabMonths["KUMK_U"] = "Kumk'u";
HaabMonths["WAYEB"] = "Wayeb";
})(HaabMonths = exports.HaabMonths || (exports.HaabMonths = {}));
var months = new hashMap_1.default([
undefined,
HaabMonths.POP,
HaabMonths.WO,
HaabMonths.SIP,
HaabMonths.SOTZ,
HaabMonths.SEK,
HaabMonths.XUL,
HaabMonths.YAXK_IN,
HaabMonths.MOL,
HaabMonths.CH_EN,
HaabMonths.YAX,
HaabMonths.SAK,
HaabMonths.KEH,
HaabMonths.MAK,
HaabMonths.K_ANK_IN,
HaabMonths.MUWAN,
HaabMonths.PAX,
HaabMonths.K_AYAB,
HaabMonths.KUMK_U,
HaabMonths.WAYEB
]);
var singleton = {};
function getHaabMonth(newCycleName) {
if (typeof newCycleName === "number" || typeof newCycleName === "string") {
var cycleName = (typeof newCycleName === 'number') ? months.getValue(newCycleName) : newCycleName;
var cycleNameHash = "".concat(cycleName);
if (singleton[cycleNameHash] === undefined) {
singleton[cycleNameHash] = (cycleNameHash == '*') ? new wildcard_1.Wildcard() : new HaabMonth(cycleNameHash);
}
return singleton[cycleNameHash];
}
else {
return newCycleName;
}
}
exports.getHaabMonth = getHaabMonth;
var HaabMonth = (function (_super) {
__extends(HaabMonth, _super);
function HaabMonth(raw) {
var _this = _super.call(this, raw, months, getHaabMonth) || this;
_this.validate();
return _this;
}
HaabMonth.prototype.validate = function () {
if (!(0, wildcard_1.isWildcard)(this.value)) {
if (this.value === undefined) {
throw new Error('Haab\' month name must be provided');
}
if (!months.includes(this.value)) {
throw new Error("Haab' month (".concat(this.value, ") must be in ").concat(months));
}
}
return true;
};
return HaabMonth;
}(cycle_1.default));
exports.HaabMonth = HaabMonth;
//# sourceMappingURL=haabMonth.js.map