date-formatter-utils v1.1.0
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!
š Installation
Install via npm:
npm install date-formatter-utilsOr 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.