chrono-node
Advanced tools
Comparing version 2.3.0 to 2.3.1
@@ -15,2 +15,6 @@ const chrono = require(".."); | ||
b.add("Parsing a long repeated space", () => { | ||
chrono.parse(`second ${" ".repeat(1000)} fourth ${" ".repeat(1000)} jum`); | ||
}), | ||
b.cycle(), | ||
@@ -17,0 +21,0 @@ b.complete(), |
@@ -25,5 +25,5 @@ import { OpUnitType } from "dayjs"; | ||
export declare function parseOrdinalNumberPattern(match: string): number; | ||
export declare const YEAR_PATTERN = "(?:[1-9][0-9]{0,3}\\s*(?:BE|AD|BC|BCE|CE)|[1-2][0-9]{3}|[5-9][0-9])"; | ||
export declare const YEAR_PATTERN = "(?:[1-9][0-9]{0,3}\\s{0,2}(?:BE|AD|BC|BCE|CE)|[1-2][0-9]{3}|[5-9][0-9])"; | ||
export declare function parseYear(match: string): number; | ||
export declare const TIME_UNITS_PATTERN: string; | ||
export declare function parseTimeUnits(timeunitText: any): TimeUnits; |
@@ -129,3 +129,3 @@ "use strict"; | ||
}; | ||
exports.NUMBER_PATTERN = `(?:${pattern_1.matchAnyPattern(exports.INTEGER_WORD_DICTIONARY)}|[0-9]+|[0-9]+\\.[0-9]+|half(?:\\s*an?)?|an?(?:\\s*few)?|few|several|a?\\s*couple\\s*(?:of)?)`; | ||
exports.NUMBER_PATTERN = `(?:${pattern_1.matchAnyPattern(exports.INTEGER_WORD_DICTIONARY)}|[0-9]+|[0-9]+\\.[0-9]+|half(?:\\s{0,2}an?)?|an?(?:\\s{0,2}few)?|few|several|a?\\s{0,2}couple\\s{0,2}(?:of)?)`; | ||
function parseNumberPattern(match) { | ||
@@ -164,3 +164,3 @@ const num = match.toLowerCase(); | ||
exports.parseOrdinalNumberPattern = parseOrdinalNumberPattern; | ||
exports.YEAR_PATTERN = `(?:[1-9][0-9]{0,3}\\s*(?:BE|AD|BC|BCE|CE)|[1-2][0-9]{3}|[5-9][0-9])`; | ||
exports.YEAR_PATTERN = `(?:[1-9][0-9]{0,3}\\s{0,2}(?:BE|AD|BC|BCE|CE)|[1-2][0-9]{3}|[5-9][0-9])`; | ||
function parseYear(match) { | ||
@@ -183,5 +183,5 @@ if (/BE/i.test(match)) { | ||
exports.parseYear = parseYear; | ||
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_PATTERN = `(${exports.NUMBER_PATTERN})\\s{0,3}(${pattern_1.matchAnyPattern(exports.TIME_UNIT_DICTIONARY)})`; | ||
const SINGLE_TIME_UNIT_REGEX = new RegExp(SINGLE_TIME_UNIT_PATTERN, "i"); | ||
exports.TIME_UNITS_PATTERN = pattern_1.repeatedTimeunitPattern(`(?:(?:about|around)\\s*)?`, SINGLE_TIME_UNIT_PATTERN); | ||
exports.TIME_UNITS_PATTERN = pattern_1.repeatedTimeunitPattern(`(?:(?:about|around)\\s{0,3})?`, SINGLE_TIME_UNIT_PATTERN); | ||
function parseTimeUnits(timeunitText) { | ||
@@ -193,3 +193,3 @@ const fragments = {}; | ||
collectDateTimeFragment(fragments, match); | ||
remainingText = remainingText.substring(match[0].length); | ||
remainingText = remainingText.substring(match[0].length).trim(); | ||
match = SINGLE_TIME_UNIT_REGEX.exec(remainingText); | ||
@@ -196,0 +196,0 @@ } |
@@ -10,3 +10,3 @@ "use strict"; | ||
const dayjs_2 = require("../../../utils/dayjs"); | ||
const PATTERN = /(?:this)?\s*(morning|afternoon|evening|night|midnight|noon)(?=\W|$)/i; | ||
const PATTERN = /(?:this)?\s{0,3}(morning|afternoon|evening|night|midnight|noon)(?=\W|$)/i; | ||
class ENCasualTimeParser extends AbstractParserWithWordBoundary_1.AbstractParserWithWordBoundaryChecking { | ||
@@ -13,0 +13,0 @@ innerPattern() { |
@@ -9,14 +9,12 @@ "use strict"; | ||
const AbstractParserWithWordBoundary_1 = require("../../../common/parsers/AbstractParserWithWordBoundary"); | ||
const PATTERN = new RegExp("(?:on\\s*?)?" + | ||
const PATTERN = new RegExp(`(?:on\\s{0,3})?` + | ||
`(${constants_3.ORDINAL_NUMBER_PATTERN})` + | ||
"(?:\\s*" + | ||
"(?:to|\\-|\\–|until|through|till|\\s)\\s*" + | ||
`(?:` + | ||
`\\s{0,3}(?:to|\\-|\\–|until|through|till)?\\s{0,3}` + | ||
`(${constants_3.ORDINAL_NUMBER_PATTERN})` + | ||
")?" + | ||
"(?:-|/|\\s*(?:of)?\\s*)" + | ||
"(" + | ||
pattern_1.matchAnyPattern(constants_1.MONTH_DICTIONARY) + | ||
")" + | ||
`(?:-|/|\\s{0,3}(?:of)?\\s{0,3})` + | ||
`(${pattern_1.matchAnyPattern(constants_1.MONTH_DICTIONARY)})` + | ||
"(?:" + | ||
"(?:-|/|,?\\s*)" + | ||
`(?:-|/|,?\\s{0,3})` + | ||
`(${constants_2.YEAR_PATTERN}(?![^\\s]\\d))` + | ||
@@ -23,0 +21,0 @@ ")?" + |
@@ -7,4 +7,4 @@ "use strict"; | ||
const timeunits_1 = require("../../../utils/timeunits"); | ||
const PATTERN = new RegExp("" + "(" + constants_1.TIME_UNITS_PATTERN + ")" + "(?:ago|before|earlier)(?=(?:\\W|$))", "i"); | ||
const STRICT_PATTERN = new RegExp("" + "(" + constants_1.TIME_UNITS_PATTERN + ")" + "ago(?=(?:\\W|$))", "i"); | ||
const PATTERN = new RegExp(`(${constants_1.TIME_UNITS_PATTERN})\\s{0,5}(?:ago|before|earlier)(?=(?:\\W|$))`, "i"); | ||
const STRICT_PATTERN = new RegExp(`(${constants_1.TIME_UNITS_PATTERN})\\s{0,5}ago(?=(?:\\W|$))`, "i"); | ||
class ENTimeUnitAgoFormatParser extends AbstractParserWithWordBoundary_1.AbstractParserWithWordBoundaryChecking { | ||
@@ -11,0 +11,0 @@ constructor(strictMode) { |
@@ -6,3 +6,3 @@ "use strict"; | ||
const AbstractParserWithWordBoundary_1 = require("../../../common/parsers/AbstractParserWithWordBoundary"); | ||
const PATTERN = new RegExp("" + "(" + constants_1.TIME_UNITS_PATTERN + ")" + "(later|after|from now|henceforth|forward|out)" + "(?=(?:\\W|$))", "i"); | ||
const PATTERN = new RegExp(`(${constants_1.TIME_UNITS_PATTERN})\\s{0,5}(?:later|after|from now|henceforth|forward|out)` + "(?=(?:\\W|$))", "i"); | ||
const STRICT_PATTERN = new RegExp("" + "(" + constants_1.TIME_UNITS_PATTERN + ")" + "(later|from now)" + "(?=(?:\\W|$))", "i"); | ||
@@ -9,0 +9,0 @@ const GROUP_NUM_TIMEUNITS = 1; |
@@ -133,3 +133,5 @@ "use strict"; | ||
minute: "minute", | ||
minuut: "minute", | ||
minuten: "minute", | ||
minuutje: "minute", | ||
h: "hour", | ||
@@ -139,2 +141,3 @@ hr: "hour", | ||
uur: "hour", | ||
u: "hour", | ||
uren: "hour", | ||
@@ -151,3 +154,3 @@ dag: "d", | ||
}; | ||
exports.NUMBER_PATTERN = `(?:${pattern_1.matchAnyPattern(exports.INTEGER_WORD_DICTIONARY)}|[0-9]+|[0-9]+\\.[0-9]+|een?|halve?)`; | ||
exports.NUMBER_PATTERN = `(?:${pattern_1.matchAnyPattern(exports.INTEGER_WORD_DICTIONARY)}|[0-9]+|[0-9]+[\\.,][0-9]+|halve?|half|paar)`; | ||
function parseNumberPattern(match) { | ||
@@ -158,9 +161,9 @@ const num = match.toLowerCase(); | ||
} | ||
else if (num === "een") { | ||
return 1; | ||
else if (num === "paar") { | ||
return 2; | ||
} | ||
else if (num.match(/halve?/)) { | ||
else if (num === "half" || num.match(/halve?/)) { | ||
return 0.5; | ||
} | ||
return parseFloat(num); | ||
return parseFloat(num.replace(",", ".")); | ||
} | ||
@@ -167,0 +170,0 @@ exports.parseNumberPattern = parseNumberPattern; |
@@ -22,2 +22,6 @@ "use strict"; | ||
const NLCasualDateTimeParser_1 = __importDefault(require("./parsers/NLCasualDateTimeParser")); | ||
const NLTimeUnitCasualRelativeFormatParser_1 = __importDefault(require("./parsers/NLTimeUnitCasualRelativeFormatParser")); | ||
const NLRelativeDateFormatParser_1 = __importDefault(require("./parsers/NLRelativeDateFormatParser")); | ||
const NLTimeUnitAgoFormatParser_1 = __importDefault(require("./parsers/NLTimeUnitAgoFormatParser")); | ||
const NLTimeUnitLaterFormatParser_1 = __importDefault(require("./parsers/NLTimeUnitLaterFormatParser")); | ||
exports.casual = new chrono_1.Chrono(createCasualConfiguration()); | ||
@@ -38,2 +42,5 @@ exports.strict = new chrono_1.Chrono(createConfiguration(true)); | ||
option.parsers.unshift(new NLCasualDateTimeParser_1.default()); | ||
option.parsers.unshift(new NLMonthNameParser_1.default()); | ||
option.parsers.unshift(new NLRelativeDateFormatParser_1.default()); | ||
option.parsers.unshift(new NLTimeUnitCasualRelativeFormatParser_1.default()); | ||
return option; | ||
@@ -46,9 +53,11 @@ } | ||
new SlashDateFormatParser_1.default(littleEndian), | ||
new NLTimeUnitWithinFormatParser_1.default(), | ||
new NLMonthNameMiddleEndianParser_1.default(), | ||
new NLMonthNameParser_1.default(), | ||
new NLTimeExpressionParser_1.default(), | ||
new NLTimeUnitWithinFormatParser_1.default(), | ||
new NLSlashMonthFormatParser_1.default(), | ||
new NLWeekdayParser_1.default(), | ||
new NLCasualYearMonthDayParser_1.default(), | ||
new NLSlashMonthFormatParser_1.default(), | ||
new NLTimeExpressionParser_1.default(strictMode), | ||
new NLTimeUnitAgoFormatParser_1.default(strictMode), | ||
new NLTimeUnitLaterFormatParser_1.default(strictMode), | ||
], | ||
@@ -55,0 +64,0 @@ refiners: [new NLMergeDateTimeRefiner_1.default(), new NLMergeDateRangeRefiner_1.default()], |
@@ -7,3 +7,4 @@ import { AbstractTimeExpressionParser } from "../../../common/parsers/AbstractTimeExpressionParser"; | ||
followingPhase(): string; | ||
primarySuffix(): string; | ||
extractPrimaryTimeComponents(context: ParsingContext, match: RegExpMatchArray): ParsingComponents | null; | ||
} |
@@ -11,2 +11,5 @@ "use strict"; | ||
} | ||
primarySuffix() { | ||
return "(?:\\s*(?:uur))?(?!/)(?=\\W|$)"; | ||
} | ||
extractPrimaryTimeComponents(context, match) { | ||
@@ -13,0 +16,0 @@ if (match[0].match(/^\s*\d{4}\s*$/)) { |
@@ -6,3 +6,3 @@ "use strict"; | ||
const singleTimeunitPatternNoCapture = singleTimeunitPattern.replace(/\((?!\?)/g, "(?:"); | ||
return `${prefix}${singleTimeunitPatternNoCapture}\\s*(?:,?\\s{0,5}${singleTimeunitPatternNoCapture}){0,10}`; | ||
return `${prefix}${singleTimeunitPatternNoCapture}\\s{0,5}(?:,?\\s{0,5}${singleTimeunitPatternNoCapture}){0,10}`; | ||
} | ||
@@ -9,0 +9,0 @@ exports.repeatedTimeunitPattern = repeatedTimeunitPattern; |
@@ -18,3 +18,3 @@ { | ||
"license": "MIT", | ||
"version": "2.3.0", | ||
"version": "2.3.1", | ||
"directories": { | ||
@@ -21,0 +21,0 @@ "source": "./src", |
@@ -165,3 +165,3 @@ import { OpUnitType } from "dayjs"; | ||
INTEGER_WORD_DICTIONARY | ||
)}|[0-9]+|[0-9]+\\.[0-9]+|half(?:\\s*an?)?|an?(?:\\s*few)?|few|several|a?\\s*couple\\s*(?:of)?)`; | ||
)}|[0-9]+|[0-9]+\\.[0-9]+|half(?:\\s{0,2}an?)?|an?(?:\\s{0,2}few)?|few|several|a?\\s{0,2}couple\\s{0,2}(?:of)?)`; | ||
@@ -202,3 +202,3 @@ export function parseNumberPattern(match: string): number { | ||
export const YEAR_PATTERN = `(?:[1-9][0-9]{0,3}\\s*(?:BE|AD|BC|BCE|CE)|[1-2][0-9]{3}|[5-9][0-9])`; | ||
export const YEAR_PATTERN = `(?:[1-9][0-9]{0,3}\\s{0,2}(?:BE|AD|BC|BCE|CE)|[1-2][0-9]{3}|[5-9][0-9])`; | ||
export function parseYear(match: string): number { | ||
@@ -229,6 +229,6 @@ if (/BE/i.test(match)) { | ||
const SINGLE_TIME_UNIT_PATTERN = `(${NUMBER_PATTERN})\\s{0,5}(${matchAnyPattern(TIME_UNIT_DICTIONARY)})\\s{0,5}`; | ||
const SINGLE_TIME_UNIT_PATTERN = `(${NUMBER_PATTERN})\\s{0,3}(${matchAnyPattern(TIME_UNIT_DICTIONARY)})`; | ||
const SINGLE_TIME_UNIT_REGEX = new RegExp(SINGLE_TIME_UNIT_PATTERN, "i"); | ||
export const TIME_UNITS_PATTERN = repeatedTimeunitPattern(`(?:(?:about|around)\\s*)?`, SINGLE_TIME_UNIT_PATTERN); | ||
export const TIME_UNITS_PATTERN = repeatedTimeunitPattern(`(?:(?:about|around)\\s{0,3})?`, SINGLE_TIME_UNIT_PATTERN); | ||
@@ -241,3 +241,3 @@ export function parseTimeUnits(timeunitText): TimeUnits { | ||
collectDateTimeFragment(fragments, match); | ||
remainingText = remainingText.substring(match[0].length); | ||
remainingText = remainingText.substring(match[0].length).trim(); | ||
match = SINGLE_TIME_UNIT_REGEX.exec(remainingText); | ||
@@ -244,0 +244,0 @@ } |
@@ -7,3 +7,3 @@ import { ParsingContext } from "../../../chrono"; | ||
const PATTERN = /(?:this)?\s*(morning|afternoon|evening|night|midnight|noon)(?=\W|$)/i; | ||
const PATTERN = /(?:this)?\s{0,3}(morning|afternoon|evening|night|midnight|noon)(?=\W|$)/i; | ||
@@ -10,0 +10,0 @@ export default class ENCasualTimeParser extends AbstractParserWithWordBoundaryChecking { |
@@ -10,16 +10,15 @@ import { ParsingContext } from "../../../chrono"; | ||
// prettier-ignore | ||
const PATTERN = new RegExp( | ||
"(?:on\\s*?)?" + | ||
`(?:on\\s{0,3})?` + | ||
`(${ORDINAL_NUMBER_PATTERN})` + | ||
"(?:\\s*" + | ||
"(?:to|\\-|\\–|until|through|till|\\s)\\s*" + | ||
`(${ORDINAL_NUMBER_PATTERN})` + | ||
`(?:` + | ||
`\\s{0,3}(?:to|\\-|\\–|until|through|till)?\\s{0,3}` + | ||
`(${ORDINAL_NUMBER_PATTERN})` + | ||
")?" + | ||
"(?:-|/|\\s*(?:of)?\\s*)" + | ||
"(" + | ||
matchAnyPattern(MONTH_DICTIONARY) + | ||
")" + | ||
`(?:-|/|\\s{0,3}(?:of)?\\s{0,3})` + | ||
`(${matchAnyPattern(MONTH_DICTIONARY)})` + | ||
"(?:" + | ||
"(?:-|/|,?\\s*)" + | ||
`(${YEAR_PATTERN}(?![^\\s]\\d))` + | ||
`(?:-|/|,?\\s{0,3})` + | ||
`(${YEAR_PATTERN}(?![^\\s]\\d))` + | ||
")?" + | ||
@@ -26,0 +25,0 @@ "(?=\\W|$)", |
@@ -7,6 +7,5 @@ import { ParsingContext } from "../../../chrono"; | ||
const PATTERN = new RegExp("" + "(" + TIME_UNITS_PATTERN + ")" + "(?:ago|before|earlier)(?=(?:\\W|$))", "i"); | ||
const PATTERN = new RegExp(`(${TIME_UNITS_PATTERN})\\s{0,5}(?:ago|before|earlier)(?=(?:\\W|$))`, "i"); | ||
const STRICT_PATTERN = new RegExp(`(${TIME_UNITS_PATTERN})\\s{0,5}ago(?=(?:\\W|$))`, "i"); | ||
const STRICT_PATTERN = new RegExp("" + "(" + TIME_UNITS_PATTERN + ")" + "ago(?=(?:\\W|$))", "i"); | ||
export default class ENTimeUnitAgoFormatParser extends AbstractParserWithWordBoundaryChecking { | ||
@@ -13,0 +12,0 @@ constructor(private strictMode: boolean) { |
@@ -7,3 +7,3 @@ import { ParsingContext } from "../../../chrono"; | ||
const PATTERN = new RegExp( | ||
"" + "(" + TIME_UNITS_PATTERN + ")" + "(later|after|from now|henceforth|forward|out)" + "(?=(?:\\W|$))", | ||
`(${TIME_UNITS_PATTERN})\\s{0,5}(?:later|after|from now|henceforth|forward|out)` + "(?=(?:\\W|$))", | ||
"i" | ||
@@ -10,0 +10,0 @@ ); |
@@ -144,3 +144,5 @@ import { OpUnitType } from "dayjs"; | ||
minute: "minute", | ||
minuut: "minute", | ||
minuten: "minute", | ||
minuutje: "minute", | ||
h: "hour", | ||
@@ -150,2 +152,3 @@ hr: "hour", | ||
uur: "hour", | ||
u: "hour", | ||
uren: "hour", | ||
@@ -165,3 +168,5 @@ dag: "d", | ||
export const NUMBER_PATTERN = `(?:${matchAnyPattern(INTEGER_WORD_DICTIONARY)}|[0-9]+|[0-9]+\\.[0-9]+|een?|halve?)`; | ||
export const NUMBER_PATTERN = `(?:${matchAnyPattern( | ||
INTEGER_WORD_DICTIONARY | ||
)}|[0-9]+|[0-9]+[\\.,][0-9]+|halve?|half|paar)`; | ||
@@ -172,8 +177,9 @@ export function parseNumberPattern(match: string): number { | ||
return INTEGER_WORD_DICTIONARY[num]; | ||
} else if (num === "een") { | ||
return 1; | ||
} else if (num.match(/halve?/)) { | ||
} else if (num === "paar") { | ||
return 2; | ||
} else if (num === "half" || num.match(/halve?/)) { | ||
return 0.5; | ||
} | ||
return parseFloat(num); | ||
// Replace "," with "." to support some European languages | ||
return parseFloat(num.replace(",", ".")); | ||
} | ||
@@ -180,0 +186,0 @@ |
@@ -23,2 +23,6 @@ /** | ||
import NLCasualDateTimeParser from "./parsers/NLCasualDateTimeParser"; | ||
import NLTimeUnitCasualRelativeFormatParser from "./parsers/NLTimeUnitCasualRelativeFormatParser"; | ||
import NLRelativeDateFormatParser from "./parsers/NLRelativeDateFormatParser"; | ||
import NLTimeUnitAgoFormatParser from "./parsers/NLTimeUnitAgoFormatParser"; | ||
import NLTimeUnitLaterFormatParser from "./parsers/NLTimeUnitLaterFormatParser"; | ||
@@ -42,2 +46,5 @@ // Shortcuts | ||
option.parsers.unshift(new NLCasualDateTimeParser()); | ||
option.parsers.unshift(new NLMonthNameParser()); | ||
option.parsers.unshift(new NLRelativeDateFormatParser()); | ||
option.parsers.unshift(new NLTimeUnitCasualRelativeFormatParser()); | ||
return option; | ||
@@ -54,9 +61,11 @@ } | ||
new SlashDateFormatParser(littleEndian), | ||
new NLTimeUnitWithinFormatParser(), | ||
new NLMonthNameMiddleEndianParser(), | ||
new NLMonthNameParser(), | ||
new NLTimeExpressionParser(), | ||
new NLTimeUnitWithinFormatParser(), | ||
new NLSlashMonthFormatParser(), | ||
new NLWeekdayParser(), | ||
new NLCasualYearMonthDayParser(), | ||
new NLSlashMonthFormatParser(), | ||
new NLTimeExpressionParser(strictMode), | ||
new NLTimeUnitAgoFormatParser(strictMode), | ||
new NLTimeUnitLaterFormatParser(strictMode), | ||
], | ||
@@ -63,0 +72,0 @@ refiners: [new NLMergeDateTimeRefiner(), new NLMergeDateRangeRefiner()], |
@@ -14,2 +14,6 @@ import { AbstractTimeExpressionParser } from "../../../common/parsers/AbstractTimeExpressionParser"; | ||
primarySuffix(): string { | ||
return "(?:\\s*(?:uur))?(?!/)(?=\\W|$)"; | ||
} | ||
extractPrimaryTimeComponents(context: ParsingContext, match: RegExpMatchArray): ParsingComponents | null { | ||
@@ -16,0 +20,0 @@ // This looks more like a year e.g. 2020 |
@@ -5,3 +5,3 @@ type DictionaryLike = string[] | { [word: string]: unknown } | Map<string, unknown>; | ||
const singleTimeunitPatternNoCapture = singleTimeunitPattern.replace(/\((?!\?)/g, "(?:"); | ||
return `${prefix}${singleTimeunitPatternNoCapture}\\s*(?:,?\\s{0,5}${singleTimeunitPatternNoCapture}){0,10}`; | ||
return `${prefix}${singleTimeunitPatternNoCapture}\\s{0,5}(?:,?\\s{0,5}${singleTimeunitPatternNoCapture}){0,10}`; | ||
} | ||
@@ -8,0 +8,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
1344998
358
26441