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

parse-dob

v1.1.1

Published

Turn a wide range of freeform inputs describing someone's birth date into `YYYY-MM-DD` using locale to get proper day / month order.

Downloads

3,599

Readme

parse-dob

Turn freeform inputs describing someone's birth date like jan 12, 82, or 1/12/1982 (in UK), or 12-1-1982 (in the US) into 1982-01-12. It will even handle various locale-specific input like: ١٨‏/١‏/١٩ or 5. 7. 1925 or 1924年9月25日 or 25‏/9‏/1924.

It's specific to birth dates because it makes some assumptions that you're < 100 years old when providing a two-digit year.

This is meant for allowing a user to "free form" type a date of birth into in input field, and be able to make it into a format the backend can understand.

It always outputs "YYYY", "YYYY-MM", "YYYY-MM-DD", or null

It's often difficult to deal wth order of month and dates. Different locales will write the same date as either 1/2/2010 or 2/1/2010.

To get around this it uses Date.prototype.toLocaleDateString() on a known date without setting a locale and determine what order it puts the known date numbers in. Then when it's parsing it can default to guessing that same arrangement.

This util is meant to enable instant feedback as a user types into an input field.

There are a lot more examples in the tests.

install

npm install parse-dob

usage

import parseDob from 'parse-dob'

parseDob('sept 29 82') // 1982-09-29

test

npm test

Change log

  • 1.0.3: Added fix for bug with two numbers as input. 12 29 is now 1929-12.
  • 1.0.2: Require 3 letters for written months to minimize false positives.
  • 1.0.1: JS Doc fix.
  • 1.0.0: Considered stable. In use in app.
  • 0.0.4: Prevent future dates of any kind
  • 0.0.3: Better handling of bad input.
  • 0.0.2: Fixed handling of empty input. Improved JS doc for export.
  • 0.0.1: First public release.

credits

If you like this follow @HenrikJoreteg on twitter. This was built for and is in use in: AnesthesiaCharting.com.

license

MIT