@drewsonne/maya-dates
Version:
Typescript package to manipulate dates in the Maya Calendar
53 lines • 2.47 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 __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var base_1 = __importDefault(require("./base"));
var long_count_1 = __importDefault(require("../lc/long-count"));
var wildcard_1 = require("../wildcard");
var LongCountFactory = (function (_super) {
__extends(LongCountFactory, _super);
function LongCountFactory() {
return _super.call(this, /(?:(?:\*|(?:[\d]{1,2}))\.){1,}(?:(?:\*)|(?:[\d]{1,2}))/) || this;
}
LongCountFactory.prototype.parse = function (raw) {
var dates = raw.match(this.pattern);
if (dates === null || dates.length !== 1) {
throw new Error("Could not match Long Count");
}
var parts = dates[0].split('.');
return new (long_count_1.default.bind.apply(long_count_1.default, __spreadArray([void 0], new Array(Math.max(5 - parts.length, 0))
.fill('0')
.concat(parts)
.map(function (part) { return ((part === '*') ? new wildcard_1.Wildcard() : parseInt(part, 10)); })
.reverse(), false)))();
};
return LongCountFactory;
}(base_1.default));
exports.default = LongCountFactory;
//# sourceMappingURL=long-count.js.map