1.3.0 โข Published 8 months ago
@kermank/nldp v1.3.0
๐ Natural Language Date Parser
A modular, preference-based date/time parser that handles natural language expressions with confidence scoring and debugging capabilities.
โจ Features
- ๐ Parse natural language date/time expressions
- ๐ Timezone-aware with full DST support
- โ๏ธ Configurable preferences (week start, reference date)
- ๐ฏ Confidence scoring for parse results
- ๐ Debug mode with detailed parse traces
- ๐ฆ Modular rule system for easy extension
๐ Quick Start
import { NLDP } from 'natural-language-date-parser';
const parser = new NLDP({
referenceDate: new Date(),
weekStartsOn: 1, // Monday
timeZone: 'America/New_York'
});
const result = parser.parse('next Monday at 3pm');
console.log(result);
๐ Supported Expressions
๐ Absolute Dates
- ISO format: "2024-03-20", "03/20/2024"
- Month names: "January 5, 2025", "Jan 5th, 2025"
- Day first: "5 January 2025", "5th Jan 2025"
- Current year: "January 5", "5th Jan"
โฐ Time
- 12-hour: "3:30 PM", "3pm"
- 24-hour: "15:30"
- Special times: "noon", "midnight"
- With dates: "March 20th at 3:30 PM"
๐ Relative Days
- Simple: "today", "tomorrow", "yesterday"
- Extended: "day after tomorrow", "day before yesterday"
- Offset: "3 days from now", "2 days ago"
- Next weekday: "next Monday", "next Friday"
๐ Ordinal Days
- Month-based: "first Monday in March", "last Friday in March"
- Numeric: "2nd Thursday in March"
- Month end: "last day of month", "penultimate day"
- Position: "third to last day of month"
๐ฆ Week Expressions
- Simple: "this week", "next week", "last week"
- Extended: "week after next"
- Offset: "3 weeks from now"
- With weekday start preference
๐ Month Parts
- Segments: "early March", "mid March", "late March"
- Halves: "first half of April", "second half of April"
- Boundaries: "beginning of April", "end of March"
๐ฏ Fuzzy Ranges
- Weekends: "this weekend", "next weekend"
- Multiple: "next 2 weekends", "following 3 weekends"
- Month parts: "first 3 days of next month", "last 5 days of March"
๐ Combined Expressions
- Date + Time: "tomorrow at 3pm", "next Monday at 3:30pm"
- Relative + Time: "3 days from now at noon"
- Ordinal + Time: "1st of April at midnight"
All expressions support:
- ๐ Timezone awareness
- ๐ Confidence scoring
- ๐ฏ Range or single date output
- ๐ Detailed debug traces
โ๏ธ Configuration
interface DateParsePreferences {
referenceDate?: Date;
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
timeZone?: string;
debug?: boolean;
}
๐ Debug Mode
Enable detailed parsing traces:
const result = parser.parse('next Monday at 3pm', { debug: true });
๐งช Testing
npm test
๐ค Contributing
Contributions are welcome! Please see the CONTRIBUTING.md for details.
๐ License
This project is open-sourced under the MIT License - see the LICENSE file for details.