1.1.0 • Published 4 months ago

date-formatter-utils v1.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

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
ParameterTypeDescription
inputstringThe date string (e.g., "Jan six" or "Jan 6")
includeYearbooleanIf 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

ErrorCause
"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.