I wrote the first commit back in 2012 (think of jQuery and Bootstrap v1). It was also around the time I was moving to Tokyo for graduate school and before I started working as a professional software developer. Since then, there have been a lot of changes in both JavaScript (ES6, TypeScript, React, …) and my programming experience. This summer, I finally have time to stay home and work on redesigning the library.

Chrono, v2, is the project’s rewrite almost from scratch in TypeScript with the following goals in mind.

  • Keeping the familiar APIs
  • Reduce duplicate code and boilerplate

Keeping the familiar APIs

Chrono does only one thing — parsing date from the text. Thus, it should be as easy and straight-forward for people who want to use it for that. While hiding a deep layer of parsing complexity underneath, Chrono has always maintained minimal interface namely its parse() function.

Aside from a few important differences (most importantly locales handling), Chrono v2 has the same minimalist APIs.

import * as chrono from ‘chrono-node’;

chrono.parseDate(‘Today at 5 PM’) // Return a javascript Date object
chrono.parse(’Today at 5 PM’)     // Return more detailed results

You can customize Chrono by cloning the base setup and add/remove parsers or refiners:

import * as chrono from ‘chrono-node’;

const customChrono = new chrono.Chrono();
// or const customChrono = chrono.en.clone();
customChrono.parsers.push(...)

If you have been using Chrono, the change should be straightforward. If you are not, it should not be difficult to get started.

At the same time, for TypeScript projects, you get the free advantages for Chrono’s newly refined type system.

#typescript #datetime #javascript #web-development #programming

Chrono’s Typescript Rewrite
1.75 GEEK