npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@area17/parse-numeric-date

v0.0.9

Published

Parse numeric based date inputs

Downloads

15

Readme

parse-numeric-date

Micro library to parse numeric based date inputs ~4kb minified/~1kb gzip

Mission Statement

Date entry is hard for users. Date pickers, including the native one, aren't always the best for accessibility.

In his article "Maybe You Don't Need a Date Picker", Adrian Roselli proposes using a text field which users enter a date into, some client side does some parsing and then some feedback is presented to the user.

It is fairly straight forward to parse a known date format and convert to ISO format. But, what if users don't enter the date in your known format?

Well, that is what parse-numeric-date attempts to solve.

Demo

https://area17.github.io/parse-numeric-date/

Usage

Firstly, install via npm:

$ npm install @area17/parse-numeric-date

Import into your JavaScript by:

import parseNumericDate from '@area17/parse-numeric-date'

And then in your JavaScript:

let isoString = parseNumericDate('29/12/25'); // 2025-12-29

If you want to have manual control over the locale:

let isoString = parseNumericDate('29/12/25', {
    locale: 'en-GB' // will favor d/m/y over m/d/y
}); // 2025-12-29

Examples of what parse-numeric-date can parse

  • 2022-02-10
  • 2022.02.10
  • 2022/02/10
  • 2022-2-10
  • 2022-2-2
  • 10 02 2022
  • 1 12 2022
  • 122922
  • 090322
  • 9322
  • 29122022
  • 010122
  • 12/29/2022
  • 12/29/22
  • 01-01-2022
  • 01-01-22
  • 1-1-22
  • 1-1-2022
  • ۱۴۰۰/۱۱/۲۱
  • 2022年12月13日
  • 13. 12. 2022
  • 13‏/12‏/2022.

Notes

This parse-numeric-date works with a big assumption:

Dates closer to today are better than dates years into the future

Date pickers for hotels, restaurants or events tend to be for things happening this year or next year. Dates of birth tend to happen from now to 100 years in the past. Retirement ages, mortgage completions tend to happen from now to 100 years in the future.

If the year difference is larger than 100, its probably useless. eg: a 29 in the string appear as 2922 rather than 29th of a month, 2022

Limitations

parse-numeric-date can't take natural input such as "December 12, 2022" - it is purely for parsing numeric inputs. Another assumption here is that such date entry, although natural in speech, isn't so natural to type - especially if the keyboard has been switched to a numeric keyboard on the users device.

If you want such parsing, perhaps you need:

Both are excellent, but can't parse numeric dates quite as fully as parse-numeric-date.

Comparison with other libraries

You can see a comparison between parse-numeric-date, anyDateParser, parse-dob and chrono-node over on Codepen: Date parse testing

parse-dob by @HenrikJoreteg was a great inspiration, we think that forking parse-dob and removing the previous date restriction would be very interesting.

Tests

Written using Jest with tests in /test/. To run:

$ npm run test

Credits

Thanks to @Mohsen Alyafei for his Persian to Gregorian conversion function on Stackoverflow.

Code of Conduct

AREA 17 is dedicated to building a welcoming, diverse, safe community. We expect everyone participating in the AREA 17 community to abide by our Code of Conduct. Please read it. Please follow it.