A TypeScript task scheduler with persistence and conditional execution.
npm install @nexim/task-scheduler!NPM Version
!npm bundle size
!Build & Lint & Test
!NPM Downloads
!NPM License
@nexim/task-scheduler provides a TypeScript task scheduler with persistence and conditional execution. It allows you to schedule recurring tasks with localStorage persistence, conditional execution, and duration-based intervals.
Install the package using npm or yarn:
``sh
npm install @nexim/task-scheduler
Usage
`typescript
import { taskScheduler } from '@nexim/task-scheduler';// Add a task that runs every 5 minutes
taskScheduler.addTask(
'data-sync',
async () => {
console.log('Syncing data...');
// Your task logic here
},
'5m',
{
shouldRun: () => navigator.onLine, // Only run when online
},
);
// Update last run timestamp
taskScheduler.updateLastRun('data-sync');
// Remove a task
taskScheduler.removeTask('data-sync');
``- Duration-based intervals: Use human-readable durations like '5m', '1h', '2d'
- Persistence: Task states are persisted in localStorage
- Conditional execution: Optional conditions to check before running tasks
- Error handling: Graceful error handling with logging
- TypeScript support: Full TypeScript support with type safety
Read full documentation here.