the-recurring-dates
v1.0.9
Published
Vanilla JS and React hook for generating recurring dates
Readme
the-recurring-dates
This package provides:
- ✅ A vanilla JS function
getRecurringDates - ⚛️ A React hook
useRecurringDates
Supports flexible recurring patterns like daily, weekly, monthly, and yearly.
Tags:
nodejs,npm-package,utility,javascript,open-source
📦 Install
npm install the-recurring-dates📦 Module Formats
This package supports both ES Modules and UMD formats:
ES Modules (Recommended)
// Modern bundlers (Webpack, Vite, Rollup, etc.)
import {
generateRecurringDates,
useRecurringDates,
getRecurringDates,
} from "the-recurring-dates";UMD (Universal Module Definition)
// Browser (via CDN) or older bundlers
<script src="https://cdn.jsdelivr.net/npm/the-recurring-dates/dist/index.umd.js"></script>
<script>
const { generateRecurringDates, useRecurringDates, getRecurringDates } = TheRecurringDates;
</script>Direct Import (ES Modules)
// Direct import from specific format
import { generateRecurringDates } from "the-recurring-dates/dist/index.es.js";📁 Available Files
| File | Format | Use Case |
| ----------------------- | ---------- | ----------------------------- |
| dist/index.es.js | ES Module | Modern bundlers, tree-shaking |
| dist/index.umd.js | UMD | Browser CDN, older bundlers |
| dist/index.es.js.map | Source Map | Debugging ES module |
| dist/index.umd.js.map | Source Map | Debugging UMD |
🔧 Build Tools Integration
Webpack/Vite/Rollup (ES Modules):
import { generateRecurringDates } from "the-recurring-dates";Browserify (UMD):
const { generateRecurringDates } = require("the-recurring-dates");Parcel (Auto-detection):
import { generateRecurringDates } from "the-recurring-dates";🌐 Browser Compatibility
| Format | Browser Support | Use Case | | ---------- | ------------------------- | ------------------------- | | ES Modules | Modern browsers (ES2015+) | Modern web apps, bundlers | | UMD | All browsers (ES5+) | Legacy support, CDN usage |
📦 Bundle Size
- ES Module: ~45KB (gzipped: ~15KB)
- UMD: ~50KB (gzipped: ~17KB)
Note: Bundle size includes moment.js dependency
🔧 Troubleshooting
Common Issues
1. Import/Export Errors
// ❌ Wrong - old format
import { generateRecurringDates } from "the-recurring-dates/dist/index.js";
// ✅ Correct - new format
import { generateRecurringDates } from "the-recurring-dates";2. CDN Usage
// ❌ Wrong - old CDN path
<script src="https://cdn.jsdelivr.net/npm/the-recurring-dates/dist/index.js"></script>
// ✅ Correct - new CDN path
<script src="https://cdn.jsdelivr.net/npm/the-recurring-dates/dist/index.umd.js"></script>3. React Hook in UMD
// ❌ Wrong - React hook doesn't work in UMD
const { useRecurringDates } = TheRecurringDates;
// ✅ Correct - Use ES modules for React
import { useRecurringDates } from "the-recurring-dates";⚙️ Configuration Options
| Option | Type | Description |
| --------------- | ---------- | ------------------------------------------------------------------------------- |
| STARTS_ON | string | Start date of the recurrence (DD-MM-YYYY) |
| ENDS_ON | string | End date of the recurrence (DD-MM-YYYY) |
| FREQUENCY | string | Recurrence type: "D" (daily), "W" (weekly), "M" (monthly), "Y" (yearly) |
| INTERVAL | number | Every X units of the frequency (e.g., every 2 weeks) |
| MONTH_DATES | number[] | Dates of the month to include (for monthly/yearly) |
| WEEK_DAYS | string[] | Days of the week: "MON", "TUE", "WED", etc. |
| WEEK_ORDINALS | string[] | Week ordinals: "FIRST", "SECOND", "THIRD", "FOURTH", "LAST" |
| EXCLUDE_DATES | string[] | Dates to exclude from the result |
| FORMAT | string | Input Date format |
🚀 Usage
⚛️ React Hook
import { useRecurringDates } from "the-recurring-dates";
function MyComponent() {
const dates = useRecurringDates({
STARTS_ON: "01-06-2025",
ENDS_ON: "31-06-2025",
FREQUENCY: "M",
INTERVAL: 1,
MONTH_DATES: [1, 15],
EXCLUDE_DATES: ["15-08-2025"],
});
return (
<ul>
{dates.map((date, i) => (
<li key={i}>{date}</li>
))}
</ul>
);
}🌐 Use via CDN (UMD)
<script src="https://cdn.jsdelivr.net/npm/the-recurring-dates/dist/index.umd.js"></script>
<script>
const { generateRecurringDates, useRecurringDates, getRecurringDates } =
TheRecurringDates;
const dates = getRecurringDates({
STARTS_ON: "01-06-2025",
ENDS_ON: "31-06-2025",
FREQUENCY: "M",
MONTH_DATES: [1, 15],
});
console.log(dates);
</script>📦 ES Modules via CDN
<script type="module">
import { generateRecurringDates } from "https://cdn.jsdelivr.net/npm/the-recurring-dates/dist/index.es.js";
const dates = generateRecurringDates({
STARTS_ON: "01-06-2025",
ENDS_ON: "31-06-2025",
FREQUENCY: "M",
MONTH_DATES: [1, 15],
});
console.log(dates);
</script>🤝 Contributing
We welcome contributions to the-recurring-dates! Here's how you can help:
🐛 Bug Reports
If you find a bug, please create an issue with:
- A clear description of the problem
- Steps to reproduce
- Expected vs actual behavior
- Your environment details
💡 Feature Requests
We love new ideas! For feature requests:
- Explain the feature and its use case
- Describe any alternatives you've considered
- Include any relevant examples
🛠️ Development
- Fork the repository
- Create a new branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests (
npm test) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
📝 Code Style
- Follow the existing code style
- Write clear commit messages
- Add tests for new features
- Update documentation as needed
🧪 Testing
Before submitting a PR:
- Run all tests (
npm test) - Ensure code coverage is maintained
- Test in different environments if applicable
📘 License
This project is licensed under the MIT License - see the LICENSE file for details.
