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 🙏

© 2025 – Pkg Stats / Ryan Hefner

date-formatter-utils

v1.1.0

Published

A simple utility to format dates from user-friendly input

Downloads

14

Readme

date-formatter-utils

A powerful & intelligent date formatter that converts human-friendly date inputs into formatted dates (dd-mm or dd-mm-yyyy). It supports CommonJS (require) and ES Modules (import). Now with smart typo correction & natural language parsing!

npm license downloads


📌 Installation

Install via npm:

npm install date-formatter-utils

Or Yarn:

yarn add date-formatter-utils

🚀 Usage

1️⃣ Using CommonJS (require())

const parseDate = require("date-formatter-utils");

console.log(parseDate("Jan six"));  // "06-01"
console.log(parseDate("Feb 14", true));  // "14-02-2025"

2️⃣ Using ES Modules (import)

import parseDate from "date-formatter-utils";

console.log(parseDate("March 3", true)); // "03-03-2025"
console.log(parseDate("Jul 7"));  // "07-07"

📌 Features

✅ Human-friendly input (e.g., "Jan six" → "06-01")
✅ Supports numbers & words (e.g., "twenty" → "20")
✅ Intelligent typo correction (e.g., "Janary" → "Jan")
✅ Handles numeric & ordinal dates (e.g., "2nd" → "02")
✅ Works with CommonJS (require) & ES Modules (import)
✅ Supports current year inclusion (e.g., "06-01-2025")
✅ Levenshtein distance-based typo correction
✅ Supports mixed numerical and textual inputs (e.g., "twentytwo" → "22")
✅ Handles edge cases and invalid inputs gracefully


🔹 Function Details

parseDate(input: string, includeYear?: boolean): string

| Parameter | Type | Description | |------------|--------|-------------| | input | string | The date string (e.g., "Jan six" or "Jan 6") | | includeYear | boolean | If true, includes the current year (e.g., "06-01-2025"). Default: false |


📌 Examples & Edge Cases

✔️ Standard Inputs

parseDate("Feb twenty");       // "20-02"
parseDate("March 3", true);    // "03-03-2025"
parseDate("Jul 7");            // "07-07"

✔️ Handling Typos

parseDate("Januay six");       // "06-01"
parseDate("Feburary 2");       // "02-02"
parseDate("Marrch 7");         // "07-03"

✔️ Handling Ordinal Numbers

parseDate("Apr 2nd");           // "02-04"
parseDate("July thirtyone");    // "31-07"
parseDate("June twentyfirst");  // "21-06"

✔️ Handling Misspelled Numbers

parseDate("Feb thirteenn"); // "13-02"
parseDate("Septmber 10");   // "10-09"

📌 Common Errors & Edge Cases

| Error | Cause | |--------|-------| | "Invalid date format" | Input doesn't match expected format (e.g., "Jan six" or "Jan 6") | | "Invalid month provided" | Month isn't recognized (e.g., "xyz six") | | "Invalid day provided" | Day isn't valid (e.g., "Jan thirtytwo") |


🚀 Upcoming Features & Improvements

🔹 Time Support: Allow parsing of human-friendly time inputs (e.g., "Jan six at 5pm")
🔹 Custom Date Formats: Users can define their own output formats (e.g., "MM/DD/YYYY")
🔹 Localization Support: Expand to support multiple languages
🔹 Improved Error Handling: More descriptive messages for invalid inputs
🔹 Date Range Support: Ability to parse date ranges like "Feb 1 to Feb 5"
🔹 Better Performance: Optimize the Levenshtein algorithm for faster execution


📌 License

This package is open-source under the MIT License.

Developed by Pritiranjan Swain.