UNPKG

datetimes

Version:

Extend class of Date

46 lines (37 loc) 1.3 kB
function Expresion(dateRx, date, language) { this.dateRx = dateRx; this.date = date; this.language = languages[language]; //methods this.interpret = interpret; this.oneDigit = null; this.twoDigit = null; this.threeDigit = null; this.fourDigit = null; this.otherDigit = null; //implementation function interpret(context) { if (!context.input.length) { return; } var sourceLength = this.dateRx.source.replace('\\b', '').length; switch (sourceLength) { case 1: if (this.oneDigit) context.input = this.oneDigit(context.input); break; case 2: if (this.twoDigit) context.input = this.twoDigit(context.input); break; case 3: if (this.threeDigit) context.input = this.threeDigit(context.input); break; case 4: if (this.fourDigit) context.input = this.fourDigit(context.input); break; default: if (this.otherDigit) context.input = this.otherDigit(context.input); break; } context.output = context.input; } }