chrono-node
Advanced tools
Comparing version 2.2.3 to 2.2.4
@@ -9,2 +9,4 @@ import { Parser, ParsingContext } from "../../chrono"; | ||
} | null; | ||
private cachedInnerPattern?; | ||
private cachedPattern?; | ||
pattern(context: ParsingContext): RegExp; | ||
@@ -11,0 +13,0 @@ extract(context: ParsingContext, match: RegExpMatchArray): ParsingComponents | ParsingResult | { |
@@ -5,5 +5,14 @@ "use strict"; | ||
class AbstractParserWithWordBoundaryChecking { | ||
constructor() { | ||
this.cachedInnerPattern = null; | ||
this.cachedPattern = null; | ||
} | ||
pattern(context) { | ||
const innerPattern = this.innerPattern(context); | ||
return new RegExp(`(\\W|^)${innerPattern.source}`, innerPattern.flags); | ||
if (innerPattern == this.cachedInnerPattern) { | ||
return this.cachedPattern; | ||
} | ||
this.cachedPattern = new RegExp(`(\\W|^)${innerPattern.source}`, innerPattern.flags); | ||
this.cachedInnerPattern = innerPattern; | ||
return this.cachedPattern; | ||
} | ||
@@ -10,0 +19,0 @@ extract(context, match) { |
@@ -15,2 +15,10 @@ import { Parser, ParsingContext } from "../../chrono"; | ||
private checkAndReturnWithoutFollowingPattern; | ||
private cachedPrimaryPrefix; | ||
private cachedPrimarySuffix; | ||
private cachedPrimaryTimePattern; | ||
getPrimaryTimePatternThroughCache(): any; | ||
private cachedFollowingPhase; | ||
private cachedFollowingSuffix; | ||
private cachedFollowingTimePatten; | ||
getFollowingTimePatternThroughCache(): any; | ||
} |
@@ -25,3 +25,3 @@ "use strict"; | ||
} | ||
function followingTimeExpression(followingPhase, followingSuffix) { | ||
function followingTimePatten(followingPhase, followingSuffix) { | ||
return new RegExp(`^(${followingPhase})` + | ||
@@ -47,2 +47,8 @@ "(\\d{1,4})" + | ||
constructor(strictMode = false) { | ||
this.cachedPrimaryPrefix = null; | ||
this.cachedPrimarySuffix = null; | ||
this.cachedPrimaryTimePattern = null; | ||
this.cachedFollowingPhase = null; | ||
this.cachedFollowingSuffix = null; | ||
this.cachedFollowingTimePatten = null; | ||
this.strictMode = strictMode; | ||
@@ -57,3 +63,3 @@ } | ||
pattern(context) { | ||
return primaryTimePattern(this.primaryPrefix(), this.primarySuffix()); | ||
return this.getPrimaryTimePatternThroughCache(); | ||
} | ||
@@ -72,3 +78,3 @@ extract(context, match) { | ||
const remainingText = context.text.substring(match.index + match[0].length); | ||
const followingPattern = followingTimeExpression(this.followingPhase(), this.followingSuffix()); | ||
const followingPattern = this.getFollowingTimePatternThroughCache(); | ||
match = followingPattern.exec(remainingText); | ||
@@ -268,3 +274,25 @@ if (!match || | ||
} | ||
getPrimaryTimePatternThroughCache() { | ||
const primaryPrefix = this.primaryPrefix(); | ||
const primarySuffix = this.primarySuffix(); | ||
if (this.cachedPrimaryPrefix === primaryPrefix && this.cachedPrimarySuffix === primarySuffix) { | ||
return this.cachedPrimaryTimePattern; | ||
} | ||
this.cachedPrimaryTimePattern = primaryTimePattern(primaryPrefix, primarySuffix); | ||
this.cachedPrimaryPrefix = primaryPrefix; | ||
this.cachedPrimarySuffix = primarySuffix; | ||
return this.cachedPrimaryTimePattern; | ||
} | ||
getFollowingTimePatternThroughCache() { | ||
const followingPhase = this.followingPhase(); | ||
const followingSuffix = this.followingSuffix(); | ||
if (this.cachedFollowingPhase === followingPhase && this.cachedFollowingSuffix === followingSuffix) { | ||
return this.cachedFollowingTimePatten; | ||
} | ||
this.cachedFollowingTimePatten = followingTimePatten(followingPhase, followingSuffix); | ||
this.cachedFollowingPhase = followingPhase; | ||
this.cachedFollowingSuffix = followingSuffix; | ||
return this.cachedFollowingTimePatten; | ||
} | ||
} | ||
exports.AbstractTimeExpressionParser = AbstractTimeExpressionParser; |
@@ -202,4 +202,6 @@ "use strict"; | ||
refine(context, results) { | ||
const timezones = Object.assign(Object.assign({}, this.timezone), context.option.timezones); | ||
var _a; | ||
const timezoneOverrides = (_a = context.option.timezones) !== null && _a !== void 0 ? _a : {}; | ||
results.forEach((result) => { | ||
var _a, _b; | ||
const suffix = context.text.substring(result.index + result.text.length); | ||
@@ -211,6 +213,6 @@ const match = TIMEZONE_NAME_PATTERN.exec(suffix); | ||
const timezoneAbbr = match[1].toUpperCase(); | ||
if (timezones[timezoneAbbr] === undefined) { | ||
const extractedTimezoneOffset = (_b = (_a = timezoneOverrides[timezoneAbbr]) !== null && _a !== void 0 ? _a : this.timezone[timezoneAbbr]) !== null && _b !== void 0 ? _b : null; | ||
if (extractedTimezoneOffset === null) { | ||
return; | ||
} | ||
const extractedTimezoneOffset = timezones[timezoneAbbr]; | ||
context.debug(() => { | ||
@@ -217,0 +219,0 @@ console.log(`Extracting timezone: '${timezoneAbbr}' into : ${extractedTimezoneOffset}`); |
@@ -139,7 +139,5 @@ "use strict"; | ||
exports.parseYear = parseYear; | ||
const SINGLE_TIME_UNIT_PATTERN = `(${exports.NUMBER_PATTERN})\\s*(${pattern_1.matchAnyPattern(exports.TIME_UNIT_DICTIONARY)})\\s*`; | ||
const SINGLE_TIME_UNIT_PATTERN = `(${exports.NUMBER_PATTERN})\\s{0,5}(${pattern_1.matchAnyPattern(exports.TIME_UNIT_DICTIONARY)})\\s{0,5}`; | ||
const SINGLE_TIME_UNIT_REGEX = new RegExp(SINGLE_TIME_UNIT_PATTERN, "i"); | ||
const SINGLE_TIME_UNIT_PATTERN_NO_CAPTURE = SINGLE_TIME_UNIT_PATTERN.replace(/\((?!\?)/g, "(?:"); | ||
exports.TIME_UNITS_PATTERN = `(?:(?:about|around)\\s*)?` + | ||
`${SINGLE_TIME_UNIT_PATTERN_NO_CAPTURE}\\s*(?:,?\\s*${SINGLE_TIME_UNIT_PATTERN_NO_CAPTURE})*`; | ||
exports.TIME_UNITS_PATTERN = pattern_1.repeatedTimeunitPattern("", SINGLE_TIME_UNIT_PATTERN); | ||
function parseTimeUnits(timeunitText) { | ||
@@ -146,0 +144,0 @@ const fragments = {}; |
@@ -181,7 +181,5 @@ "use strict"; | ||
exports.parseYear = parseYear; | ||
const SINGLE_TIME_UNIT_PATTERN = `(${exports.NUMBER_PATTERN})\\s*(${pattern_1.matchAnyPattern(exports.TIME_UNIT_DICTIONARY)})\\s*`; | ||
const SINGLE_TIME_UNIT_PATTERN = `(${exports.NUMBER_PATTERN})\\s{0,5}(${pattern_1.matchAnyPattern(exports.TIME_UNIT_DICTIONARY)})\\s{0,5}`; | ||
const SINGLE_TIME_UNIT_REGEX = new RegExp(SINGLE_TIME_UNIT_PATTERN, "i"); | ||
const SINGLE_TIME_UNIT_PATTERN_NO_CAPTURE = SINGLE_TIME_UNIT_PATTERN.replace(/\((?!\?)/g, "(?:"); | ||
exports.TIME_UNITS_PATTERN = `(?:(?:about|around)\\s*)?` + | ||
`${SINGLE_TIME_UNIT_PATTERN_NO_CAPTURE}\\s*(?:,?\\s*${SINGLE_TIME_UNIT_PATTERN_NO_CAPTURE})*`; | ||
exports.TIME_UNITS_PATTERN = pattern_1.repeatedTimeunitPattern(`(?:(?:about|around)\\s*)?`, SINGLE_TIME_UNIT_PATTERN); | ||
function parseTimeUnits(timeunitText) { | ||
@@ -188,0 +186,0 @@ const fragments = {}; |
@@ -6,11 +6,8 @@ "use strict"; | ||
const AbstractParserWithWordBoundary_1 = require("../../../common/parsers/AbstractParserWithWordBoundary"); | ||
const PATTERN_WITH_PREFIX = new RegExp(`(?:within|in|for)\\s*` + | ||
`(?:(?:about|around|roughly|approximately|just)\\s*(?:~\\s*)?)?(${constants_1.TIME_UNITS_PATTERN})(?=\\W|$)`, "i"); | ||
const PATTERN_WITHOUT_PREFIX = new RegExp(`(?:(?:about|around|roughly|approximately|just)\\s*(?:~\\s*)?)?(${constants_1.TIME_UNITS_PATTERN})(?=\\W|$)`, "i"); | ||
class ENTimeUnitWithinFormatParser extends AbstractParserWithWordBoundary_1.AbstractParserWithWordBoundaryChecking { | ||
innerPattern(context) { | ||
const prefix = context.option.forwardDate ? "" : "(?:within|in|for)\\s*"; | ||
return new RegExp(prefix + | ||
`(?:(?:about|around|roughly|approximately|just)\\s*(?:~\\s*)?)?` + | ||
"(" + | ||
constants_1.TIME_UNITS_PATTERN + | ||
")" + | ||
`(?=\\W|$)`, "i"); | ||
return context.option.forwardDate ? PATTERN_WITHOUT_PREFIX : PATTERN_WITH_PREFIX; | ||
} | ||
@@ -17,0 +14,0 @@ innerExtract(context, match) { |
@@ -148,6 +148,5 @@ "use strict"; | ||
exports.parseYear = parseYear; | ||
const SINGLE_TIME_UNIT_PATTERN = `(${exports.NUMBER_PATTERN})\\s*(${pattern_1.matchAnyPattern(exports.TIME_UNIT_DICTIONARY)})\\s*`; | ||
const SINGLE_TIME_UNIT_PATTERN = `(${exports.NUMBER_PATTERN})\\s{0,5}(${pattern_1.matchAnyPattern(exports.TIME_UNIT_DICTIONARY)})\\s{0,5}`; | ||
const SINGLE_TIME_UNIT_REGEX = new RegExp(SINGLE_TIME_UNIT_PATTERN, "i"); | ||
const SINGLE_TIME_UNIT_PATTERN_NO_CAPTURE = SINGLE_TIME_UNIT_PATTERN.replace(/\((?!\?)/g, "(?:"); | ||
exports.TIME_UNITS_PATTERN = `(?:${SINGLE_TIME_UNIT_PATTERN_NO_CAPTURE})+`; | ||
exports.TIME_UNITS_PATTERN = pattern_1.repeatedTimeunitPattern("", SINGLE_TIME_UNIT_PATTERN); | ||
function parseTimeUnits(timeunitText) { | ||
@@ -154,0 +153,0 @@ const fragments = {}; |
@@ -188,7 +188,5 @@ "use strict"; | ||
exports.parseYear = parseYear; | ||
const SINGLE_TIME_UNIT_PATTERN = `(${exports.NUMBER_PATTERN})\\s*(${pattern_1.matchAnyPattern(exports.TIME_UNIT_DICTIONARY)})\\s*`; | ||
const SINGLE_TIME_UNIT_PATTERN = `(${exports.NUMBER_PATTERN})\\s{0,5}(${pattern_1.matchAnyPattern(exports.TIME_UNIT_DICTIONARY)})\\s{0,5}`; | ||
const SINGLE_TIME_UNIT_REGEX = new RegExp(SINGLE_TIME_UNIT_PATTERN, "i"); | ||
const SINGLE_TIME_UNIT_PATTERN_NO_CAPTURE = SINGLE_TIME_UNIT_PATTERN.replace(/\((?!\?)/g, "(?:"); | ||
exports.TIME_UNITS_PATTERN = `(?:(?:binnen|in)\\s*)?` + | ||
`${SINGLE_TIME_UNIT_PATTERN_NO_CAPTURE}\\s*(?:,?\\s*${SINGLE_TIME_UNIT_PATTERN_NO_CAPTURE})*`; | ||
exports.TIME_UNITS_PATTERN = pattern_1.repeatedTimeunitPattern(`(?:(?:binnen|in)\\s*)?`, SINGLE_TIME_UNIT_PATTERN); | ||
function parseTimeUnits(timeunitText) { | ||
@@ -195,0 +193,0 @@ const fragments = {}; |
declare type DictionaryLike = string[] | { | ||
[word: string]: unknown; | ||
} | Map<string, unknown>; | ||
export declare function patternWithWordBreak(regExp: RegExp): RegExp; | ||
export declare function repeatedTimeunitPattern(prefix: string, singleTimeunitPattern: string): string; | ||
export declare function extractTerms(dictionary: DictionaryLike): string[]; | ||
export declare function matchAnyPattern(dictionary: DictionaryLike): string; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.matchAnyPattern = exports.extractTerms = exports.patternWithWordBreak = void 0; | ||
function patternWithWordBreak(regExp) { | ||
return RegExp("" + regExp.source); | ||
exports.matchAnyPattern = exports.extractTerms = exports.repeatedTimeunitPattern = void 0; | ||
function repeatedTimeunitPattern(prefix, singleTimeunitPattern) { | ||
const singleTimeunitPatternNoCapture = singleTimeunitPattern.replace(/\((?!\?)/g, "(?:"); | ||
return `${prefix}${singleTimeunitPatternNoCapture}\\s*(?:,?\\s{0,5}${singleTimeunitPatternNoCapture}){0,10}`; | ||
} | ||
exports.patternWithWordBreak = patternWithWordBreak; | ||
exports.repeatedTimeunitPattern = repeatedTimeunitPattern; | ||
function extractTerms(dictionary) { | ||
@@ -9,0 +10,0 @@ let keys; |
@@ -18,3 +18,3 @@ { | ||
"license": "MIT", | ||
"version": "2.2.3", | ||
"version": "2.2.4", | ||
"directories": { | ||
@@ -21,0 +21,0 @@ "source": "./src", |
@@ -15,5 +15,14 @@ import { Parser, ParsingContext } from "../../chrono"; | ||
private cachedInnerPattern?: RegExp = null; | ||
private cachedPattern?: RegExp = null; | ||
pattern(context: ParsingContext): RegExp { | ||
const innerPattern = this.innerPattern(context); | ||
return new RegExp(`(\\W|^)${innerPattern.source}`, innerPattern.flags); | ||
if (innerPattern == this.cachedInnerPattern) { | ||
return this.cachedPattern; | ||
} | ||
this.cachedPattern = new RegExp(`(\\W|^)${innerPattern.source}`, innerPattern.flags); | ||
this.cachedInnerPattern = innerPattern; | ||
return this.cachedPattern; | ||
} | ||
@@ -20,0 +29,0 @@ |
@@ -28,3 +28,3 @@ import { Parser, ParsingContext } from "../../chrono"; | ||
// prettier-ignore | ||
function followingTimeExpression(followingPhase: string, followingSuffix: string) { | ||
function followingTimePatten(followingPhase: string, followingSuffix: string) { | ||
return new RegExp( | ||
@@ -71,3 +71,3 @@ `^(${followingPhase})` + | ||
pattern(context: ParsingContext): RegExp { | ||
return primaryTimePattern(this.primaryPrefix(), this.primarySuffix()); | ||
return this.getPrimaryTimePatternThroughCache(); | ||
} | ||
@@ -90,3 +90,3 @@ | ||
const remainingText = context.text.substring(match.index + match[0].length); | ||
const followingPattern = followingTimeExpression(this.followingPhase(), this.followingSuffix()); | ||
const followingPattern = this.getFollowingTimePatternThroughCache(); | ||
match = followingPattern.exec(remainingText); | ||
@@ -341,2 +341,38 @@ if ( | ||
} | ||
private cachedPrimaryPrefix = null; | ||
private cachedPrimarySuffix = null; | ||
private cachedPrimaryTimePattern = null; | ||
getPrimaryTimePatternThroughCache() { | ||
const primaryPrefix = this.primaryPrefix(); | ||
const primarySuffix = this.primarySuffix(); | ||
if (this.cachedPrimaryPrefix === primaryPrefix && this.cachedPrimarySuffix === primarySuffix) { | ||
return this.cachedPrimaryTimePattern; | ||
} | ||
this.cachedPrimaryTimePattern = primaryTimePattern(primaryPrefix, primarySuffix); | ||
this.cachedPrimaryPrefix = primaryPrefix; | ||
this.cachedPrimarySuffix = primarySuffix; | ||
return this.cachedPrimaryTimePattern; | ||
} | ||
private cachedFollowingPhase = null; | ||
private cachedFollowingSuffix = null; | ||
private cachedFollowingTimePatten = null; | ||
getFollowingTimePatternThroughCache() { | ||
const followingPhase = this.followingPhase(); | ||
const followingSuffix = this.followingSuffix(); | ||
if (this.cachedFollowingPhase === followingPhase && this.cachedFollowingSuffix === followingSuffix) { | ||
return this.cachedFollowingTimePatten; | ||
} | ||
this.cachedFollowingTimePatten = followingTimePatten(followingPhase, followingSuffix); | ||
this.cachedFollowingPhase = followingPhase; | ||
this.cachedFollowingSuffix = followingSuffix; | ||
return this.cachedFollowingTimePatten; | ||
} | ||
} |
@@ -208,3 +208,4 @@ // Map ABBR -> Offset in minute | ||
refine(context: ParsingContext, results: ParsingResult[]): ParsingResult[] { | ||
const timezones = { ...this.timezone, ...context.option.timezones }; | ||
const timezoneOverrides = context.option.timezones ?? {}; | ||
results.forEach((result) => { | ||
@@ -218,7 +219,7 @@ const suffix = context.text.substring(result.index + result.text.length); | ||
const timezoneAbbr = match[1].toUpperCase(); | ||
if (timezones[timezoneAbbr] === undefined) { | ||
const extractedTimezoneOffset = timezoneOverrides[timezoneAbbr] ?? this.timezone[timezoneAbbr] ?? null; | ||
if (extractedTimezoneOffset === null) { | ||
return; | ||
} | ||
const extractedTimezoneOffset = timezones[timezoneAbbr]; | ||
context.debug(() => { | ||
@@ -225,0 +226,0 @@ console.log(`Extracting timezone: '${timezoneAbbr}' into : ${extractedTimezoneOffset}`); |
import { OpUnitType } from "dayjs"; | ||
import { matchAnyPattern } from "../../utils/pattern"; | ||
import { matchAnyPattern, repeatedTimeunitPattern } from "../../utils/pattern"; | ||
import { findMostLikelyADYear } from "../../calculation/years"; | ||
@@ -152,11 +152,7 @@ import { TimeUnits } from "../../utils/timeunits"; | ||
const SINGLE_TIME_UNIT_PATTERN = `(${NUMBER_PATTERN})\\s*(${matchAnyPattern(TIME_UNIT_DICTIONARY)})\\s*`; | ||
const SINGLE_TIME_UNIT_PATTERN = `(${NUMBER_PATTERN})\\s{0,5}(${matchAnyPattern(TIME_UNIT_DICTIONARY)})\\s{0,5}`; | ||
const SINGLE_TIME_UNIT_REGEX = new RegExp(SINGLE_TIME_UNIT_PATTERN, "i"); | ||
const SINGLE_TIME_UNIT_PATTERN_NO_CAPTURE = SINGLE_TIME_UNIT_PATTERN.replace(/\((?!\?)/g, "(?:"); | ||
export const TIME_UNITS_PATTERN = repeatedTimeunitPattern("", SINGLE_TIME_UNIT_PATTERN); | ||
export const TIME_UNITS_PATTERN = | ||
`(?:(?:about|around)\\s*)?` + | ||
`${SINGLE_TIME_UNIT_PATTERN_NO_CAPTURE}\\s*(?:,?\\s*${SINGLE_TIME_UNIT_PATTERN_NO_CAPTURE})*`; | ||
export function parseTimeUnits(timeunitText): TimeUnits { | ||
@@ -163,0 +159,0 @@ const fragments = {}; |
import { OpUnitType } from "dayjs"; | ||
import { matchAnyPattern } from "../../utils/pattern"; | ||
import { matchAnyPattern, repeatedTimeunitPattern } from "../../utils/pattern"; | ||
import { findMostLikelyADYear } from "../../calculation/years"; | ||
@@ -226,11 +226,7 @@ import { TimeUnits } from "../../utils/timeunits"; | ||
const SINGLE_TIME_UNIT_PATTERN = `(${NUMBER_PATTERN})\\s*(${matchAnyPattern(TIME_UNIT_DICTIONARY)})\\s*`; | ||
const SINGLE_TIME_UNIT_PATTERN = `(${NUMBER_PATTERN})\\s{0,5}(${matchAnyPattern(TIME_UNIT_DICTIONARY)})\\s{0,5}`; | ||
const SINGLE_TIME_UNIT_REGEX = new RegExp(SINGLE_TIME_UNIT_PATTERN, "i"); | ||
const SINGLE_TIME_UNIT_PATTERN_NO_CAPTURE = SINGLE_TIME_UNIT_PATTERN.replace(/\((?!\?)/g, "(?:"); | ||
export const TIME_UNITS_PATTERN = repeatedTimeunitPattern(`(?:(?:about|around)\\s*)?`, SINGLE_TIME_UNIT_PATTERN); | ||
export const TIME_UNITS_PATTERN = | ||
`(?:(?:about|around)\\s*)?` + | ||
`${SINGLE_TIME_UNIT_PATTERN_NO_CAPTURE}\\s*(?:,?\\s*${SINGLE_TIME_UNIT_PATTERN_NO_CAPTURE})*`; | ||
export function parseTimeUnits(timeunitText): TimeUnits { | ||
@@ -237,0 +233,0 @@ const fragments = {}; |
@@ -6,14 +6,16 @@ import { TIME_UNITS_PATTERN, parseTimeUnits } from "../constants"; | ||
const PATTERN_WITH_PREFIX = new RegExp( | ||
`(?:within|in|for)\\s*` + | ||
`(?:(?:about|around|roughly|approximately|just)\\s*(?:~\\s*)?)?(${TIME_UNITS_PATTERN})(?=\\W|$)`, | ||
"i" | ||
); | ||
const PATTERN_WITHOUT_PREFIX = new RegExp( | ||
`(?:(?:about|around|roughly|approximately|just)\\s*(?:~\\s*)?)?(${TIME_UNITS_PATTERN})(?=\\W|$)`, | ||
"i" | ||
); | ||
export default class ENTimeUnitWithinFormatParser extends AbstractParserWithWordBoundaryChecking { | ||
innerPattern(context: ParsingContext): RegExp { | ||
const prefix = context.option.forwardDate ? "" : "(?:within|in|for)\\s*"; | ||
return new RegExp( | ||
prefix + | ||
`(?:(?:about|around|roughly|approximately|just)\\s*(?:~\\s*)?)?` + | ||
"(" + | ||
TIME_UNITS_PATTERN + | ||
")" + | ||
`(?=\\W|$)`, | ||
"i" | ||
); | ||
return context.option.forwardDate ? PATTERN_WITHOUT_PREFIX : PATTERN_WITH_PREFIX; | ||
} | ||
@@ -20,0 +22,0 @@ |
import { OpUnitType, QUnitType } from "dayjs"; | ||
import { matchAnyPattern } from "../../utils/pattern"; | ||
import { matchAnyPattern, repeatedTimeunitPattern } from "../../utils/pattern"; | ||
@@ -163,9 +163,7 @@ export const WEEKDAY_DICTIONARY: { [word: string]: number } = { | ||
const SINGLE_TIME_UNIT_PATTERN = `(${NUMBER_PATTERN})\\s*(${matchAnyPattern(TIME_UNIT_DICTIONARY)})\\s*`; | ||
const SINGLE_TIME_UNIT_PATTERN = `(${NUMBER_PATTERN})\\s{0,5}(${matchAnyPattern(TIME_UNIT_DICTIONARY)})\\s{0,5}`; | ||
const SINGLE_TIME_UNIT_REGEX = new RegExp(SINGLE_TIME_UNIT_PATTERN, "i"); | ||
const SINGLE_TIME_UNIT_PATTERN_NO_CAPTURE = SINGLE_TIME_UNIT_PATTERN.replace(/\((?!\?)/g, "(?:"); | ||
export const TIME_UNITS_PATTERN = repeatedTimeunitPattern("", SINGLE_TIME_UNIT_PATTERN); | ||
export const TIME_UNITS_PATTERN = `(?:${SINGLE_TIME_UNIT_PATTERN_NO_CAPTURE})+`; | ||
export function parseTimeUnits(timeunitText): { [c in OpUnitType | QUnitType]?: number } { | ||
@@ -172,0 +170,0 @@ const fragments = {}; |
import { OpUnitType } from "dayjs"; | ||
import { matchAnyPattern } from "../../utils/pattern"; | ||
import { matchAnyPattern, repeatedTimeunitPattern } from "../../utils/pattern"; | ||
import { findMostLikelyADYear } from "../../calculation/years"; | ||
@@ -210,11 +210,7 @@ import { TimeUnits } from "../../utils/timeunits"; | ||
const SINGLE_TIME_UNIT_PATTERN = `(${NUMBER_PATTERN})\\s*(${matchAnyPattern(TIME_UNIT_DICTIONARY)})\\s*`; | ||
const SINGLE_TIME_UNIT_PATTERN = `(${NUMBER_PATTERN})\\s{0,5}(${matchAnyPattern(TIME_UNIT_DICTIONARY)})\\s{0,5}`; | ||
const SINGLE_TIME_UNIT_REGEX = new RegExp(SINGLE_TIME_UNIT_PATTERN, "i"); | ||
const SINGLE_TIME_UNIT_PATTERN_NO_CAPTURE = SINGLE_TIME_UNIT_PATTERN.replace(/\((?!\?)/g, "(?:"); | ||
export const TIME_UNITS_PATTERN = repeatedTimeunitPattern(`(?:(?:binnen|in)\\s*)?`, SINGLE_TIME_UNIT_PATTERN); | ||
export const TIME_UNITS_PATTERN = | ||
`(?:(?:binnen|in)\\s*)?` + | ||
`${SINGLE_TIME_UNIT_PATTERN_NO_CAPTURE}\\s*(?:,?\\s*${SINGLE_TIME_UNIT_PATTERN_NO_CAPTURE})*`; | ||
export function parseTimeUnits(timeunitText): TimeUnits { | ||
@@ -221,0 +217,0 @@ const fragments = {}; |
type DictionaryLike = string[] | { [word: string]: unknown } | Map<string, unknown>; | ||
export function patternWithWordBreak(regExp: RegExp): RegExp { | ||
return RegExp("" + regExp.source); | ||
export function repeatedTimeunitPattern(prefix: string, singleTimeunitPattern: string): string { | ||
const singleTimeunitPatternNoCapture = singleTimeunitPattern.replace(/\((?!\?)/g, "(?:"); | ||
return `${prefix}${singleTimeunitPatternNoCapture}\\s*(?:,?\\s{0,5}${singleTimeunitPatternNoCapture}){0,10}`; | ||
} | ||
@@ -6,0 +7,0 @@ |
import { BufferedDebugHandler } from "../src/debugging"; | ||
import { ParsedResult, ParsingOption } from "../src"; | ||
import { en, ParsedResult, ParsingOption } from "../src"; | ||
@@ -76,2 +76,9 @@ interface ChronoLike { | ||
export function measureMilliSec(block: () => void): number { | ||
const startTime = new Date().getMilliseconds(); | ||
block(); | ||
const endTime = new Date().getMilliseconds(); | ||
return endTime - startTime; | ||
} | ||
// -------------------------------------------------- | ||
@@ -78,0 +85,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
799036
338
18080