Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chrono-node

Package Overview
Dependencies
Maintainers
1
Versions
107
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chrono-node - npm Package Compare versions

Comparing version 2.2.6 to 2.2.7

test/en/en_year.test.ts

3

dist/common/parsers/AbstractTimeExpressionParser.js

@@ -249,2 +249,5 @@ "use strict";

}
if (result.text.match(/\d[apAP]$/)) {
return null;
}
const endingWithNumbers = result.text.match(/[^\d:.](\d[\d.]+)$/);

@@ -251,0 +254,0 @@ if (endingWithNumbers) {

9

dist/common/refiners/ExtractTimezoneAbbrRefiner.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const TIMEZONE_NAME_PATTERN = new RegExp("^\\s*\\(?([A-Z]{2,4})\\)?(?=\\W|$)", "i");
const TIMEZONE_NAME_PATTERN = new RegExp("^\\s*,?\\s*\\(?([A-Z]{2,4})\\)?(?=\\W|$)", "i");
const DEFAULT_TIMEZONE_ABBR_MAP = {

@@ -221,3 +221,8 @@ ACDT: 630,

if (currentTimezoneOffset !== null && extractedTimezoneOffset != currentTimezoneOffset) {
return;
if (result.start.isCertain("timezoneOffset")) {
return;
}
if (timezoneAbbr != match[1]) {
return;
}
}

@@ -224,0 +229,0 @@ result.text += match[0];

@@ -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)|[1-2][0-9]{3}|[5-9][0-9])";
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 function parseYear(match: string): number;
export declare const TIME_UNITS_PATTERN: string;
export declare function parseTimeUnits(timeunitText: any): TimeUnits;

@@ -163,3 +163,3 @@ "use strict";

exports.parseOrdinalNumberPattern = parseOrdinalNumberPattern;
exports.YEAR_PATTERN = `(?:[1-9][0-9]{0,3}\\s*(?:BE|AD|BC)|[1-2][0-9]{3}|[5-9][0-9])`;
exports.YEAR_PATTERN = `(?:[1-9][0-9]{0,3}\\s*(?:BE|AD|BC|BCE|CE)|[1-2][0-9]{3}|[5-9][0-9])`;
function parseYear(match) {

@@ -170,8 +170,8 @@ if (/BE/i.test(match)) {

}
if (/BC/i.test(match)) {
match = match.replace(/BC/i, "");
if (/BCE?/i.test(match)) {
match = match.replace(/BCE?/i, "");
return -parseInt(match);
}
if (/AD/i.test(match)) {
match = match.replace(/AD/i, "");
if (/(AD|CE)/i.test(match)) {
match = match.replace(/(AD|CE)/i, "");
return parseInt(match);

@@ -178,0 +178,0 @@ }

@@ -29,3 +29,3 @@ "use strict";

const references = __importStar(require("../../../common/casualReferences"));
const PATTERN = /(now|today|tonight|tomorrow|tmr|yesterday|last\s*night)(?=\W|$)/i;
const PATTERN = /(now|today|tonight|tomorrow|tmr|tmrw|yesterday|last\s*night)(?=\W|$)/i;
class ENCasualDateParser extends AbstractParserWithWordBoundary_1.AbstractParserWithWordBoundaryChecking {

@@ -48,2 +48,3 @@ innerPattern(context) {

case "tmr":
case "tmrw":
return references.tomorrow(context.refDate);

@@ -50,0 +51,0 @@ case "tonight":

@@ -18,3 +18,3 @@ {

"license": "MIT",
"version": "2.2.6",
"version": "2.2.7",
"directories": {

@@ -21,0 +21,0 @@ "source": "./src",

@@ -313,2 +313,7 @@ import { Parser, ParsingContext } from "../../chrono";

// Instead of "am/pm", it ends with "a" or "p" (e.g "1a", "123p"), this seems unlikely
if (result.text.match(/\d[apAP]$/)) {
return null;
}
// If it ends only with numbers or dots

@@ -315,0 +320,0 @@ const endingWithNumbers = result.text.match(/[^\d:.](\d[\d.]+)$/);

@@ -5,3 +5,3 @@ // Map ABBR -> Offset in minute

const TIMEZONE_NAME_PATTERN = new RegExp("^\\s*\\(?([A-Z]{2,4})\\)?(?=\\W|$)", "i");
const TIMEZONE_NAME_PATTERN = new RegExp("^\\s*,?\\s*\\(?([A-Z]{2,4})\\)?(?=\\W|$)", "i");
const DEFAULT_TIMEZONE_ABBR_MAP = {

@@ -228,8 +228,16 @@ ACDT: 630,

// We may already have extracted the offset e.g. "11 am GMT+0900 (JST)"
// - if they are equal, we also want to take the abbreviation text into result
// - if they are not equal, we trust the offset more
const currentTimezoneOffset = result.start.get("timezoneOffset");
if (currentTimezoneOffset !== null && extractedTimezoneOffset != currentTimezoneOffset) {
return;
// We may already have extracted the timezone offset e.g. "11 am GMT+0900 (JST)"
// - if they are equal, we also want to take the abbreviation text into result
// - if they are not equal, we trust the offset more
if (result.start.isCertain("timezoneOffset")) {
return;
}
// This is often because it's relative time with inferred timezone (e.g. in 1 hour, tomorrow)
// Then, we want to double check the abbr case (e.g. "GET" not "get")
if (timezoneAbbr != match[1]) {
return;
}
}

@@ -236,0 +244,0 @@

@@ -201,3 +201,3 @@ import { OpUnitType } from "dayjs";

export const YEAR_PATTERN = `(?:[1-9][0-9]{0,3}\\s*(?:BE|AD|BC)|[1-2][0-9]{3}|[5-9][0-9])`;
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 function parseYear(match: string): number {

@@ -210,10 +210,11 @@ if (/BE/i.test(match)) {

if (/BC/i.test(match)) {
// Before Christ
match = match.replace(/BC/i, "");
if (/BCE?/i.test(match)) {
// Before Christ, Before Common Era
match = match.replace(/BCE?/i, "");
return -parseInt(match);
}
if (/AD/i.test(match)) {
match = match.replace(/AD/i, "");
if (/(AD|CE)/i.test(match)) {
// Anno Domini, Common Era
match = match.replace(/(AD|CE)/i, "");
return parseInt(match);

@@ -220,0 +221,0 @@ }

@@ -8,3 +8,3 @@ import { ParsingContext } from "../../../chrono";

const PATTERN = /(now|today|tonight|tomorrow|tmr|yesterday|last\s*night)(?=\W|$)/i;
const PATTERN = /(now|today|tonight|tomorrow|tmr|tmrw|yesterday|last\s*night)(?=\W|$)/i;

@@ -33,2 +33,3 @@ export default class ENCasualDateParser extends AbstractParserWithWordBoundaryChecking {

case "tmr":
case "tmrw":
return references.tomorrow(context.refDate);

@@ -35,0 +36,0 @@

@@ -7,3 +7,4 @@ import { Parser, ParsingContext } from "../../../chrono";

const PATTERN = /(?:(?:([同今本])|((昭和|平成|令和)?([0-90-9]{1,4}|元)))年\s*)?([0-90-9]{1,2})月\s*([0-90-9]{1,2})日/i;
const PATTERN =
/(?:(?:([同今本])|((昭和|平成|令和)?([0-90-9]{1,4}|元)))年\s*)?([0-90-9]{1,2})月\s*([0-90-9]{1,2})日/i;
const SPECIAL_YEAR_GROUP = 1;

@@ -10,0 +11,0 @@ const TYPICAL_YEAR_GROUP = 2;

@@ -29,41 +29,2 @@ import * as chrono from "../../src";

testSingleCase(chrono, "10 August 2555 BE", new Date(2012, 7, 10), (result) => {
expect(result.index).toBe(0);
expect(result.text).toBe("10 August 2555 BE");
expect(result.start).not.toBeNull();
expect(result.start.get("year")).toBe(2012);
expect(result.start.get("month")).toBe(8);
expect(result.start.get("day")).toBe(10);
expect(result.start).toBeDate(new Date(2012, 8 - 1, 10, 12));
});
testSingleCase(chrono, "10 August 234 BC", new Date(2012, 7, 10), (result) => {
expect(result.index).toBe(0);
expect(result.text).toBe("10 August 234 BC");
expect(result.start).not.toBeNull();
expect(result.start.get("year")).toBe(-234);
expect(result.start.get("month")).toBe(8);
expect(result.start.get("day")).toBe(10);
expect(result.start).toBeDate(new Date(-234, 8 - 1, 10, 12));
});
testSingleCase(chrono, "10 August 88 AD", new Date(2012, 7, 10), (result) => {
expect(result.index).toBe(0);
expect(result.text).toBe("10 August 88 AD");
expect(result.start).not.toBeNull();
expect(result.start.get("year")).toBe(88);
expect(result.start.get("month")).toBe(8);
expect(result.start.get("day")).toBe(10);
const resultDate = result.start.date();
const expectDate = new Date(88, 8 - 1, 10, 12);
expectDate.setFullYear(88);
expect(expectDate.getTime()).toBeCloseTo(resultDate.getTime());
});
testSingleCase(chrono, "Sun 15Sep", new Date(2013, 7, 10), (result) => {

@@ -70,0 +31,0 @@ expect(result.index).toBe(0);

import * as chrono from "../../src";
import { testSingleCase } from "../test_util";
test("Test - Parsing date with UTC offset", function () {
test("Test - Parsing date/time with UTC offset", function () {
testSingleCase(chrono, "wednesday, september 16, 2020 at 11 am utc+02:45 ", (result, text) => {

@@ -30,3 +30,3 @@ expect(result.text).toBe("wednesday, september 16, 2020 at 11 am utc+02:45");

test("Test - Parsing date with GMT offset", function () {
test("Test - Parsing date/time with GMT offset", function () {
testSingleCase(chrono, "wednesday, september 16, 2020 at 11 am GMT -08:45 ", (result, text) => {

@@ -49,3 +49,3 @@ expect(result.text).toBe("wednesday, september 16, 2020 at 11 am GMT -08:45");

test("Test - Parsing date with timezone abbreviation", function () {
test("Test - Parsing date/time with timezone abbreviation", function () {
testSingleCase(chrono, "wednesday, september 16, 2020 at 11 am", (result, text) => {

@@ -78,3 +78,10 @@ expect(result.text).toBe(text);

test("Test - Not parsing timezone from relative date", function () {
test("Test - Parsing date with timezone abbreviation", function () {
testSingleCase(chrono, "Wednesday, September 16, 2020, EST", (result, text) => {
expect(result.text).toBe(text);
expect(result.start.get("timezoneOffset")).toBe(-300);
});
});
test("Test - Not parsing timezone from relative time", function () {
const refDate = new Date(2020, 11 - 1, 14, 13, 48, 22);

@@ -87,7 +94,11 @@

// testSingleCase(chrono, "in 1 hour GMT", refDate, (result, text) => {
// expect(result.text).toBe("in 1 hour");
// expect(result.start.get("timezoneOffset")).toBe(-refDate.getTimezoneOffset());
// });
testSingleCase(chrono, "in 3 hours GMT", refDate, (result, text) => {
expect(result.text).toBe("in 3 hours");
expect(result.start.get("timezoneOffset")).toBe(-refDate.getTimezoneOffset());
});
});
test("Test - Parsing timezone from relative date when valid", function () {
const refDate = new Date(2020, 11 - 1, 14, 13, 48, 22);
testSingleCase(chrono, "in 1 day get eggs and milk", refDate, (result, text) => {

@@ -97,2 +108,17 @@ expect(result.text).toBe("in 1 day");

});
testSingleCase(chrono, "in 1 day GET", refDate, (result, text) => {
expect(result.text).toBe("in 1 day GET");
expect(result.start.get("timezoneOffset")).toBe(240);
});
testSingleCase(chrono, "today EST", (result, text) => {
expect(result.text).toBe(text);
expect(result.start.get("timezoneOffset")).toBe(-300);
});
testSingleCase(chrono, "next week EST", (result, text) => {
expect(result.text).toBe(text);
expect(result.start.get("timezoneOffset")).toBe(-300);
});
});

@@ -26,2 +26,13 @@ import { testSingleCase, testUnexpectedResult } from "../test_util";

test("Test - URLs % encoded", function () {
testUnexpectedResult(chrono, "%e7%b7%8a");
testUnexpectedResult(
chrono,
"https://tenor.com/view/%e3%83%89%e3%82%ad%e3%83%89%e3%82%ad-" +
"%e7%b7%8a%e5%bc%b5-%e5%a5%bd%e3%81%8d-%e3%83%8f%e3%83%bc%e3%83%88" +
"-%e5%8f%af%e6%84%9b%e3%81%84-gif-15876325"
);
});
test("Test - Skip hyphenated numbers pattern", () => {

@@ -28,0 +39,0 @@ testUnexpectedResult(chrono, "1-2");

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc