{"_id":"@azharfromjaunpur/azhar","name":"@azharfromjaunpur/azhar","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@azharfromjaunpur/azhar","version":"1.0.0","description":"Lightweight, dependency-free debounce and throttle utilities for JavaScript and TypeScript.","type":"module","main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}}},"sideEffects":false,"scripts":{"build":"tsup","dev":"tsup --watch","typecheck":"tsc --noEmit","prepublishOnly":"npm run build"},"keywords":["debounce","throttle","utility","typescript","performance","rate-limit"],"author":{"name":"Azhar"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/azhar/azhar.git"},"devDependencies":{"tsup":"^8.0.0","typescript":"^5.5.0"},"_id":"@azharfromjaunpur/azhar@1.0.0","bugs":{"url":"https://github.com/azhar/azhar/issues"},"homepage":"https://github.com/azhar/azhar#readme","_nodeVersion":"24.16.0","_npmVersion":"11.13.0","dist":{"integrity":"sha512-EC4YZyk8agwvH1gE265PBdjL/XUeXvxIdlfQav/bT/qHSMsrsrP4AY10atv7dTLpKbvcIn489cqxTYxGintG9A==","shasum":"4b8ea2a4dfbfcce0874001fba85373e5181adc9a","tarball":"https://registry.npmjs.org/@azharfromjaunpur/azhar/-/azhar-1.0.0.tgz","fileCount":9,"unpackedSize":37918,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDpju3e51Vkr5kVm/lqLq2kAod25dUvTcy2i4+u2pPCfgIhALzUCEnKnTVc/BhIQ6E6rtq9VGhaoOus1sY/qJa4WCjh"}]},"_npmUser":{"name":"azharfromjaunpur","email":"azhruddin986@gmail.com"},"directories":{},"maintainers":[{"name":"azharfromjaunpur","email":"azhruddin986@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/azhar_1.0.0_1781326404486_0.8262361798325142"},"_hasShrinkwrap":false}},"time":{"created":"2026-06-13T04:53:24.355Z","1.0.0":"2026-06-13T04:53:24.623Z","modified":"2026-06-13T04:53:24.873Z"},"maintainers":[{"name":"azharfromjaunpur","email":"azhruddin986@gmail.com"}],"description":"Lightweight, dependency-free debounce and throttle utilities for JavaScript and TypeScript.","homepage":"https://github.com/azhar/azhar#readme","keywords":["debounce","throttle","utility","typescript","performance","rate-limit"],"repository":{"type":"git","url":"git+https://github.com/azhar/azhar.git"},"author":{"name":"Azhar"},"bugs":{"url":"https://github.com/azhar/azhar/issues"},"license":"MIT","readme":"# azhar\n\n> Lightweight, dependency-free `debounce` and `throttle` utilities for JavaScript & TypeScript.\n\n[![npm version](https://img.shields.io/npm/v/azhar.svg)](https://www.npmjs.com/package/azhar)\n[![bundle size](https://img.shields.io/bundlephobia/minzip/azhar)](https://bundlephobia.com/package/azhar)\n[![license](https://img.shields.io/npm/l/azhar.svg)](./LICENSE)\n\n- ✅ **Zero dependencies**\n- ✅ **Tree-shakeable** ESM + CJS\n- ✅ **Full TypeScript** support with declaration files\n- ✅ **< 1 KB** minified + gzipped\n- ✅ **Preserves `this` context** and arguments\n\n---\n\n## Installation\n\n```bash\nnpm install azhar\n```\n\n```bash\nyarn add azhar\n```\n\n```bash\npnpm add azhar\n```\n\n---\n\n## API\n\n### `debounce(fn, delay, options?)`\n\nCreates a debounced function that delays invocation until `delay` ms have elapsed since the last call.\n\n| Parameter | Type | Description |\n| --------- | ---- | ----------- |\n| `fn` | `(...args) => any` | The function to debounce |\n| `delay` | `number` | Delay in milliseconds |\n| `options.leading` | `boolean` | Invoke on the leading edge instead of trailing *(default: `false`)* |\n\n**Returns** a debounced function with a `.cancel()` method.\n\n#### Basic Usage\n\n```ts\nimport { debounce } from 'azhar';\n\nconst search = debounce((query: string) => {\n  fetch(`/api/search?q=${query}`);\n}, 300);\n\ninput.addEventListener('input', (e) => {\n  search((e.target as HTMLInputElement).value);\n});\n```\n\n#### Leading Edge (Immediate Execution)\n\n```ts\nconst save = debounce(saveDocument, 1000, { leading: true });\n\n// Fires immediately on the first call, then ignores calls for 1000ms.\nsave();\n```\n\n#### Cancelling\n\n```ts\nconst handler = debounce(expensiveOperation, 500);\n\n// Cancel a pending invocation (e.g., on component unmount).\nhandler.cancel();\n```\n\n---\n\n### `throttle(fn, delay, options?)`\n\nCreates a throttled function that invokes at most once per `delay` milliseconds.\n\n| Parameter | Type | Description |\n| --------- | ---- | ----------- |\n| `fn` | `(...args) => any` | The function to throttle |\n| `delay` | `number` | Minimum interval in milliseconds |\n| `options.leading` | `boolean` | Invoke on the leading edge *(default: `true`)* |\n| `options.trailing` | `boolean` | Invoke on the trailing edge *(default: `true`)* |\n\n**Returns** a throttled function with a `.cancel()` method.\n\n#### Basic Usage\n\n```ts\nimport { throttle } from 'azhar';\n\nconst onScroll = throttle(() => {\n  console.log('Scroll position:', window.scrollY);\n}, 200);\n\nwindow.addEventListener('scroll', onScroll);\n```\n\n#### Trailing Only\n\n```ts\n// Fires only after scrolling stops (after the delay).\nconst onScrollEnd = throttle(handleScrollEnd, 300, {\n  leading: false,\n  trailing: true,\n});\n```\n\n#### Cancelling\n\n```ts\nconst handler = throttle(trackPosition, 100);\n\n// Stop any pending trailing invocation.\nhandler.cancel();\n```\n\n---\n\n## Usage in React\n\n### Debounced Search Input\n\n```tsx\nimport { useState, useMemo, useEffect } from 'react';\nimport { debounce } from 'azhar';\n\nfunction SearchInput() {\n  const [query, setQuery] = useState('');\n  const [results, setResults] = useState([]);\n\n  const fetchResults = useMemo(\n    () =>\n      debounce(async (q: string) => {\n        if (!q.trim()) return;\n        const res = await fetch(`/api/search?q=${q}`);\n        const data = await res.json();\n        setResults(data);\n      }, 400),\n    [],\n  );\n\n  // Clean up on unmount.\n  useEffect(() => () => fetchResults.cancel(), [fetchResults]);\n\n  return (\n    <div>\n      <input\n        value={query}\n        onChange={(e) => {\n          setQuery(e.target.value);\n          fetchResults(e.target.value);\n        }}\n        placeholder=\"Search...\"\n      />\n      <ul>\n        {results.map((r: any) => (\n          <li key={r.id}>{r.name}</li>\n        ))}\n      </ul>\n    </div>\n  );\n}\n```\n\n### Throttled Scroll Handler\n\n```tsx\nimport { useEffect, useMemo } from 'react';\nimport { throttle } from 'azhar';\n\nfunction ScrollTracker() {\n  const onScroll = useMemo(\n    () =>\n      throttle(() => {\n        console.log('scrollY:', window.scrollY);\n      }, 200),\n    [],\n  );\n\n  useEffect(() => {\n    window.addEventListener('scroll', onScroll);\n    return () => {\n      onScroll.cancel();\n      window.removeEventListener('scroll', onScroll);\n    };\n  }, [onScroll]);\n\n  return <div style={{ height: '300vh' }}>Scroll me</div>;\n}\n```\n\n---\n\n## Build\n\n```bash\n# Install dependencies\nnpm install\n\n# Build the package\nnpm run build\n\n# Type-check without emitting\nnpm run typecheck\n\n# Watch mode during development\nnpm run dev\n```\n\n---\n\n## Publishing to npm\n\n### First-Time Setup\n\n```bash\n# 1. Create an npm account at https://www.npmjs.com/signup\n\n# 2. Log in from the CLI\nnpm login\n\n# 3. Verify your login\nnpm whoami\n```\n\n### Publish\n\n```bash\n# 1. Make sure the build is clean\nnpm run build\n\n# 2. Preview what will be published\nnpm pack --dry-run\n\n# 3. Publish to npm (public)\nnpm publish --access public\n```\n\n### Updating the Version\n\nFollow [Semantic Versioning](https://semver.org/):\n\n| Change type | Command | Example |\n| ----------- | ------- | ------- |\n| **Patch** — bug fixes, docs | `npm version patch` | `1.0.0` → `1.0.1` |\n| **Minor** — new features, backward-compatible | `npm version minor` | `1.0.0` → `1.1.0` |\n| **Major** — breaking changes | `npm version major` | `1.0.0` → `2.0.0` |\n\n```bash\n# Bump version, commit, and tag\nnpm version patch   # or minor / major\n\n# Then publish\nnpm publish --access public\n```\n\n---\n\n## License\n\n[MIT](./LICENSE) © Azhar\n","readmeFilename":"README.md","_rev":"1-d5d917f62e4248b5c0a3a5258aa03bf2"}