UNPKG

chrono-node

Version:

A natural language date parser in Javascript

37 lines 1.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AbstractParserWithWordBoundaryChecking = void 0; class AbstractParserWithWordBoundaryChecking { constructor() { this.cachedInnerPattern = null; this.cachedPattern = null; } innerPatternHasChange(context, currentInnerPattern) { return this.innerPattern(context) !== currentInnerPattern; } patternLeftBoundary() { return `(\\W|^)`; } pattern(context) { if (this.cachedInnerPattern) { if (!this.innerPatternHasChange(context, this.cachedInnerPattern)) { return this.cachedPattern; } } this.cachedInnerPattern = this.innerPattern(context); this.cachedPattern = new RegExp(`${this.patternLeftBoundary()}${this.cachedInnerPattern.source}`, this.cachedInnerPattern.flags); return this.cachedPattern; } extract(context, match) { var _a; const header = (_a = match[1]) !== null && _a !== void 0 ? _a : ""; match.index = match.index + header.length; match[0] = match[0].substring(header.length); for (let i = 2; i < match.length; i++) { match[i - 1] = match[i]; } return this.innerExtract(context, match); } } exports.AbstractParserWithWordBoundaryChecking = AbstractParserWithWordBoundaryChecking; //# sourceMappingURL=AbstractParserWithWordBoundary.js.map