{"_id":"@abuhasanrumi/micro-flow","_rev":"3-c77bbc9691d3c4b6e030a4419b1b7781","name":"@abuhasanrumi/micro-flow","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"@abuhasanrumi/micro-flow","version":"1.0.0","keywords":["debounce","throttle","rate-limit","performance"],"author":{"name":"Your Name","email":"your.email@example.com"},"license":"MIT","_id":"@abuhasanrumi/micro-flow@1.0.0","maintainers":[{"name":"abuhasanrumi","email":"abu.hasan.rumi@gmail.com"}],"dist":{"shasum":"b67f4794749497775b328d647ab2aaf1eedf2628","tarball":"https://registry.npmjs.org/@abuhasanrumi/micro-flow/-/micro-flow-1.0.0.tgz","fileCount":4,"integrity":"sha512-m4hO7SF+L84xB9mIh6Plwp3NTqhsUjCRDZ/x4E8gNgWo1pdTF5LqbxbZZwKZ/c6cAtrlcmj66dVw0KeNG0J1tw==","signatures":[{"sig":"MEQCIDnA+YIS3Hfhl7pCco9UxCQoRo8/0Z0Wp8Or4Oyi89JTAiARZ9eQOYBIZ0xWSkGp6BCSn51YWfpJcnYna5x/hnjyBg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":6944},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","gitHead":"7f6ab1f1fcfe96c017b30c26c25d68aa45056f37","scripts":{"test":"vitest run","build":"tsc && esbuild src/index.js --bundle --minify --format=esm --outfile=dist/index.js"},"_npmUser":{"name":"abuhasanrumi","email":"abu.hasan.rumi@gmail.com"},"_npmVersion":"10.9.2","description":"A tiny utility for debouncing, throttling, and dynamic rate-limiting","directories":{},"_nodeVersion":"22.14.0","_hasShrinkwrap":false,"devDependencies":{"vitest":"^3.1.1","esbuild":"^0.25.2","typescript":"^5.8.3"},"_npmOperationalInternal":{"tmp":"tmp/micro-flow_1.0.0_1744409288819_0.870723412441287","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@abuhasanrumi/micro-flow","version":"1.0.1","keywords":["debounce","throttle","rate-limit","performance"],"author":{"name":"Your Name","email":"your.email@example.com"},"license":"MIT","_id":"@abuhasanrumi/micro-flow@1.0.1","maintainers":[{"name":"abuhasanrumi","email":"abu.hasan.rumi@gmail.com"}],"dist":{"shasum":"7e2f49f6d516dfc5efc8ea2c7467a5df5039cc22","tarball":"https://registry.npmjs.org/@abuhasanrumi/micro-flow/-/micro-flow-1.0.1.tgz","fileCount":4,"integrity":"sha512-EzUQEp0HvQvTRaZ2IR3/5YiZIj+b+7RHsnX6EVaC9sEbHUPbP7WPHSBLR03iQneYcNzBTQKj5QLrX+5P83F5xA==","signatures":[{"sig":"MEQCIGssQElzPoClkqETeBQ9Hgtpb8lG7dQMkkb01z1Za4zaAiAq+EPWHEv8IMkALGFlRWavgcVnZyLeaNecJWYhza7MTg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":7152},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","gitHead":"a34f087d6ef66247465a6e6485008df693c044dd","scripts":{"test":"vitest run","build":"tsc && esbuild src/index.js --bundle --minify --format=esm --outfile=dist/index.js"},"_npmUser":{"name":"abuhasanrumi","email":"abu.hasan.rumi@gmail.com"},"_npmVersion":"10.9.2","description":"A tiny utility for debouncing, throttling, and dynamic rate-limiting","directories":{},"_nodeVersion":"22.14.0","_hasShrinkwrap":false,"devDependencies":{"vitest":"^3.1.1","esbuild":"^0.25.2","typescript":"^5.8.3"},"_npmOperationalInternal":{"tmp":"tmp/micro-flow_1.0.1_1744410090613_0.12132784875849456","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"@abuhasanrumi/micro-flow","version":"1.0.2","description":"A tiny utility for debouncing, throttling, and dynamic rate-limiting","main":"dist/index.js","types":"dist/index.d.ts","type":"module","scripts":{"build":"tsc && esbuild src/index.js --bundle --minify --format=esm --outfile=dist/index.js","test":"vitest run"},"keywords":["debounce","throttle","rate-limit","performance"],"author":{"name":"Your Name","email":"your.email@example.com"},"license":"MIT","devDependencies":{"esbuild":"^0.25.2","typescript":"^5.8.3","vitest":"^3.1.1"},"_id":"@abuhasanrumi/micro-flow@1.0.2","gitHead":"f19d7446cdee9d0c50075fa7cf9d81aa57bdf6d6","_nodeVersion":"22.14.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-GKZVD1/0uQcvXiVUFplNIe8UqXZcsRE4XcFmHDJJTTna1xMqZicnE2mucvcsMN1da7w453/55MPhlqZWmZn8Cg==","shasum":"f5c3d921e058fa9c6d73576cf6bfa68d48eb75a1","tarball":"https://registry.npmjs.org/@abuhasanrumi/micro-flow/-/micro-flow-1.0.2.tgz","fileCount":4,"unpackedSize":7433,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIHDJk+m6YBOvrOQfWp1yRuk/3r5dA04qPxFOGChpwRcFAiB9OeVkNtFXVzEtrqiHUBUv+UYQMH9Zsks2oIyfhGLWLA=="}]},"_npmUser":{"name":"abuhasanrumi","email":"abu.hasan.rumi@gmail.com"},"directories":{},"maintainers":[{"name":"abuhasanrumi","email":"abu.hasan.rumi@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/micro-flow_1.0.2_1744411699583_0.59660857550041"},"_hasShrinkwrap":false}},"time":{"created":"2025-04-11T22:08:08.717Z","modified":"2025-04-11T22:48:19.953Z","1.0.0":"2025-04-11T22:08:09.060Z","1.0.1":"2025-04-11T22:21:30.772Z","1.0.2":"2025-04-11T22:48:19.759Z"},"author":{"name":"Your Name","email":"your.email@example.com"},"license":"MIT","keywords":["debounce","throttle","rate-limit","performance"],"description":"A tiny utility for debouncing, throttling, and dynamic rate-limiting","maintainers":[{"name":"abuhasanrumi","email":"abu.hasan.rumi@gmail.com"}],"readme":"[![npm](https://img.shields.io/npm/v/@abuhasanrumi/micro-flow)](https://www.npmjs.com/package/@abuhasanrumi/micro-flow)\n[![CI](https://github.com/abuhasanrumi/micro-flow/actions/workflows/ci.yml/badge.svg)](https://github.com/abuhasanrumi/micro-flow/actions)\n\nA tiny (364b) JavaScript utility for debouncing, throttling, and dynamic rate-limiting. Built for performance and simplicity, `micro-flow` helps developers optimize event-driven applications with minimal overhead.\n\n## Introduction\n\n`micro-flow` is a lightweight library designed to handle rate-limiting tasks in JavaScript with ease. Whether you're optimizing scroll events, search inputs, or API calls, this package provides three core functions—`debounce`, `throttle`, and `dynamic`—to ensure your code runs efficiently. With a focus on modern JavaScript, TypeScript support, and a tiny footprint, `micro-flow` is perfect for projects where performance and bundle size matter.\n\n## Why I Built This Package\n\nAs a developer, I noticed that many rate-limiting libraries were either bloated with dependencies or lacked flexibility for modern workflows. I wanted to create a solution that was:\n\n- **Ultra-lightweight**: At under 500 bytes, it adds negligible weight to your bundle.\n- **Modern**: Built with ES Modules and TypeScript for seamless integration in contemporary projects.\n- **Unique**: The `dynamic` function adapts wait times based on call frequency, a feature not commonly found in other libraries.\n- **Simple**: Clear APIs and zero dependencies make it easy to adopt and maintain.\n\nThis package was also a way for me to deepen my understanding of JavaScript performance patterns while contributing a practical tool to the open-source community. It’s a showcase of clean code, rigorous testing, and developer-friendly design.\n\n## How It Differs from Other Packages\n\nWhile there are other debounce and throttle libraries like `lodash.debounce`, `throttle-debounce`, or `just-debounce-it`, `@abuhasanrumi/micro-flow` stands out in several ways:\n\n- **Smaller Size**: Most alternatives range from 1-70KB (e.g., Lodash is ~70KB). `micro-flow` is under 364b minified, ideal for performance-critical apps.\n- **Dynamic Mode**: Unlike traditional debounce or throttle, the `dynamic` function adjusts wait times based on how frequently it’s called, offering smarter rate-limiting for variable workloads (e.g., search inputs with bursts of typing).\n- **TypeScript-First**: Built with TypeScript definitions included, ensuring a great developer experience without extra setup.\n- **No Dependencies**: Unlike some libraries that pull in large utilities, `micro-flow` is standalone, reducing bloat and security risks.\n- **Modern JavaScript**: Uses ES Modules and is tree-shakable, unlike older libraries with CommonJS or UMD formats.\n- **Focused Scope**: Instead of being a kitchen-sink utility, it does three things well, keeping your project lean.\n\nIf you need a minimal, flexible, and forward-thinking rate-limiting solution, `micro-flow` is designed for you.\n\n## Installation\n\nInstall via npm:\n\n```bash\nnpm install @abuhasanrumi/micro-flow\n```\n\n## Usage\n\n### Debounce\nPrevents a function from running until a specified delay has passed since its last call. Great for search inputs or resize events.\n\n```javascript\nimport { debounce } from '@abuhasanrumi/micro-flow';\n\nconst log = debounce(() => console.log('Debounced!'), 200);\nwindow.addEventListener('resize', log);\n// Rapid resizes trigger only one console.log after 200ms\n```\n\n### Throttle\nLimits a function to run at most once every specified interval. Perfect for scroll or mouse-move events.\n\n```javascript\nimport { throttle } from '@abuhasanrumi/micro-flow';\n\nconst update = throttle(() => console.log('Throttled!'), 100);\nwindow.addEventListener('scroll', update);\n// Logs at most once every 100ms during scrolling\n```\n\n### Dynamic\nAdapts the wait time based on call frequency, using a base wait and scaling up to a maximum. Ideal for dynamic inputs like typing or IoT events.\n\n```javascript\nimport { dynamic } from '@abuhasanrumi/micro-flow';\n\nconst search = dynamic(() => console.log('Searching...'), { baseWait: 200, maxWait: 1000 });\ndocument.getElementById('search').addEventListener('input', search);\n// Frequent typing uses ~200ms wait; sparse typing extends up to 1000ms\n```\n\n## Features\n\n- **Ultra-Tiny**: 364 bytes minified, ensuring minimal impact on bundle size.\n- **TypeScript Support**: Full type definitions for better IDE integration.\n- **Dynamic Rate-Limiting**: Unique `dynamic` function adjusts wait times for smarter performance.\n- **Zero Dependencies**: No external libraries, reducing complexity and risks.\n- **Tree-Shakable**: ES Modules ensure only used functions are bundled.\n- **100% Test Coverage**: Rigorous tests with Vitest for reliability.\n- **Modern Workflow**: Built for Node.js 18+ and compatible with frameworks like React, Vue, or Svelte.\n\n## Live Demo\n\nTry `@abuhasanrumi/micro-flow` in action:\n\n[Live Demo on CodeSandbox](https://codesandbox.io/p/sandbox/demo-micro-flow-y24tlk)\n\nSee `debounce` on a search input, `throttle` on scroll events, and `dynamic` with adaptive typing—all in a simple, interactive example.\n\n## API Reference\n\n### `debounce(fn, wait)`\n- **fn**: Function to debounce.\n- **wait**: Delay in milliseconds.\n- **Returns**: Debounced function that runs `fn` after `wait` ms of inactivity.\n\n### `throttle(fn, wait)`\n- **fn**: Function to throttle.\n- **wait**: Minimum interval in milliseconds.\n- **Returns**: Throttled function that runs `fn` at most once per `wait` ms.\n\n### `dynamic(fn, options)`\n- **fn**: Function to rate-limit.\n- **options**:\n  - `baseWait`: Minimum wait time in milliseconds (e.g., 200).\n  - `maxWait`: Maximum wait time in milliseconds (e.g., 1000).\n- **Returns**: Function that schedules `fn` with a wait time that adapts based on call frequency.\n\n## Development\n\nTo contribute or run locally:\n\n1. Clone the repo:\n   ```bash\n   git clone https://github.com/abuhasanrumi/micro-flow.git\n   cd micro-flow\n   ```\n\n2. Install dependencies:\n   ```bash\n   npm install\n   ```\n\n3. Run tests:\n   ```bash\n   npm test\n   ```\n\n4. Build the package:\n   ```bash\n   npm run build\n   ```\n\n## License\n\nCopyright (c) 2025 Abu Hasan Rumi\n\n## Acknowledgments\n\nBuilt as a learning project to explore JavaScript performance patterns and contribute to the open-source community. Feedback and contributions are welcome!","readmeFilename":"README.md"}