with-ease-progress
v0.2.1
Published
Smooth progress tracking for async tasks
Maintainers
Readme
with-ease-progress
Smooth progress tracking for async tasks in JavaScript/TypeScript.
This small utility ensures a minimum progress duration and smooth updates, perfect for tracking task progress in a user-friendly way.
Demo
Installation
npm install with-ease-progress
# or
yarn add with-ease-progressUsage
Direct
import { withEaseProgress } from "with-ease-progress";
// Simulate an async task
await withEaseProgress(
async (update) => {
for (let i = 0; i <= 100; i += 10) {
await new Promise(r => setTimeout(r, 100));
update({ loaded: i, total: 100 });
}
},
{
minDuration: 2000,
onProgress: (p) => console.log("Progress:", p + "%"),
}
);
// Output:
// Progress: 10%
// Progress: 25%
// Progress: 40%
// ...updateis a function that accepts an object{ loaded: number, total: number }onProgressis called with the smooth progress percentageminDurationensures the progress bar moves smoothly even if the task finishes quickly
Curryable (functional-friendly)
const uploadWithProgress = withEaseProgress({
minDuration: 1500,
onProgress: p => console.log(p),
});
await uploadWithProgress(update => uploadFile(update));Features
- Works with any async task
- Smooth progress updates, prevents jumps
- Supports TypeScript and provides typings
- Functional-friendly / curryable usage
- ESM + CJS compatible
License
MIT
