{"id":26804490,"url":"https://github.com/aegisjsproject/tempo","last_synced_at":"2025-04-23T04:51:34.779Z","repository":{"id":283169773,"uuid":"950088031","full_name":"AegisJSProject/tempo","owner":"AegisJSProject","description":"Tempo provides advanced debouncing and throttling utilities for fine-grained execution control.","archived":false,"fork":false,"pushed_at":"2025-04-17T16:23:51.000Z","size":201,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-18T06:55:35.049Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/@aegisjsproject/tempo","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AegisJSProject.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"shgysk8zer0","liberapay":"shgysk8zer0"}},"created_at":"2025-03-17T16:00:30.000Z","updated_at":"2025-04-17T16:23:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"2aaa13dc-925a-46f9-b595-678cb92e003c","html_url":"https://github.com/AegisJSProject/tempo","commit_stats":null,"previous_names":["aegisjsproject/tempo"],"tags_count":1,"template":false,"template_full_name":"shgysk8zer0/npm-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AegisJSProject%2Ftempo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AegisJSProject%2Ftempo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AegisJSProject%2Ftempo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AegisJSProject%2Ftempo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AegisJSProject","download_url":"https://codeload.github.com/AegisJSProject/tempo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250372947,"owners_count":21419722,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-29T22:17:32.529Z","updated_at":"2025-04-23T04:51:34.758Z","avatar_url":"https://github.com/AegisJSProject.png","language":"JavaScript","funding_links":["https://github.com/sponsors/shgysk8zer0","https://liberapay.com/shgysk8zer0","https://liberapay.com/shgysk8zer0/donate"],"categories":[],"sub_categories":[],"readme":"# @aegisjsproject/tempo\n\nTempo provides advanced debouncing and throttling utilities for fine-grained execution control.\n\n[![CodeQL](https://github.com/AegisJSProject/tempo/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/AegisJSProject/tempo/actions/workflows/codeql-analysis.yml)\n![Node CI](https://github.com/AegisJSProject/tempo/workflows/Node%20CI/badge.svg)\n![Lint Code Base](https://github.com/AegisJSProject/tempo/workflows/Lint%20Code%20Base/badge.svg)\n\n[![GitHub license](https://img.shields.io/github/license/AegisJSProject/tempo.svg)](https://github.com/AegisJSProject/tempo/blob/master/LICENSE)\n[![GitHub last commit](https://img.shields.io/github/last-commit/AegisJSProject/tempo.svg)](https://github.com/AegisJSProject/tempo/commits/master)\n[![GitHub release](https://img.shields.io/github/release/AegisJSProject/tempo?logo=github)](https://github.com/AegisJSProject/tempo/releases)\n[![GitHub Sponsors](https://img.shields.io/github/sponsors/shgysk8zer0?logo=github)](https://github.com/sponsors/shgysk8zer0)\n\n[![npm](https://img.shields.io/npm/v/@aegisjsproject/tempo)](https://www.npmjs.com/package/@aegisjsproject/tempo)\n![node-current](https://img.shields.io/node/v/@aegisjsproject/tempo)\n![npm bundle size gzipped](https://img.shields.io/bundlephobia/minzip/@aegisjsproject/tempo)\n[![npm](https://img.shields.io/npm/dw/@aegisjsproject/tempo?logo=npm)](https://www.npmjs.com/package/@aegisjsproject/tempo)\n\n[![GitHub followers](https://img.shields.io/github/followers/AegisJSProject.svg?style=social)](https://github.com/AegisJSProject)\n![GitHub forks](https://img.shields.io/github/forks/AegisJSProject/tempo.svg?style=social)\n![GitHub stars](https://img.shields.io/github/stars/AegisJSProject/tempo.svg?style=social)\n[![Twitter Follow](https://img.shields.io/twitter/follow/shgysk8zer0.svg?style=social)](https://twitter.com/shgysk8zer0)\n\n[![Donate using Liberapay](https://img.shields.io/liberapay/receives/shgysk8zer0.svg?logo=liberapay)](https://liberapay.com/shgysk8zer0/donate \"Donate using Liberapay\")\n- - -\n\n- [Code of Conduct](./.github/CODE_OF_CONDUCT.md)\n- [Contributing](./.github/CONTRIBUTING.md)\n\u003c!-- - [Security Policy](./.github/SECURITY.md) --\u003e\n\n# @aegisjsproject/tempo\n\nA lightweight JavaScript library for debouncing and throttling functions using modern, native web APIs.\n\n---\n\n## Overview\n\n`@aegisjsproject/tempo` provides robust debouncing and throttling utilities by leveraging the browser's latest scheduling and locking APIs. Using methods like `scheduler.postTask` and `navigator.locks.request`, the library offers precise task scheduling with native priority support, efficient cancellation via AbortSignals, and streamlined resource management.\n\n---\n\n## Features\n\n- **Debounce Function**  \n  Debounces a callback function by scheduling it with `scheduler.postTask`. It supports custom delays, task priorities (`user-blocking`, `user-visible`, `background`), and cancellation through AbortSignals.\n\n- **Throttle Function**  \n  Throttles a callback by combining `scheduler.postTask` with `navigator.locks.request` for controlled, queued execution. It provides options for lock naming, immediate failure or lock stealing, and built-in delay management.\n\n---\n\n## Advantages of Modern Methods\n\n- **Native Integration:**  \n  Leverages browser-native APIs for task scheduling and lock management, reducing dependency overhead and resulting in smaller bundle sizes.\n\n- **Improved Performance:**  \n  Native scheduling with `scheduler.postTask` allows tasks to be queued based on system and user priorities, leading to smoother and more responsive applications.\n\n- **Enhanced Control:**  \n  With built-in support for AbortSignals and fine-grained control over task priorities, developers can efficiently manage resource-intensive operations.\n\n- **Optimized Concurrency:**  \n  The use of `navigator.locks.request` ensures that throttled tasks handle concurrent execution gracefully without resorting to heavy third-party libraries.\n\n---\n\n## Installation\n\nInstall the package via npm:\n\n```bash\nnpm install @aegisjsproject/tempo\n```\n\n---\n\n## Usage\n\nImport the desired functions into your project:\n\n```js\nimport { debounce, throttle } from '@aegisjsproject/tempo';\n```\n\n### Usage with a CDN and `\u003cscript type=\"importmap\"\u003e`\n\n```html\n\u003cscript type=\"importmap\"\u003e\n  {\n    \"imports\": {\n      \"@aegisjsproject/tempo\": \"https://unpkg.com/@aegisjsproject[:version]/tempo.js\"\n    }\n  }\n\u003c/script\u003e\n```\n### Debounce Example\n\n```js\nconst debouncedAction = debounce(() =\u003e {\n  // Your callback code here.\n}, {\n  delay: 300,\n  priority: 'user-visible',\n  signal: myAbortSignal, // Optional: provide an AbortSignal for cancellation.\n});\n```\n\n### Throttle Example\n\n```js\nconst throttledAction = throttle(() =\u003e {\n  // Your callback code here.\n}, {\n  lockName: 'uniqueLockName', // Optional: defaults to a random UUID.\n  delay: 200,\n  priority: 'background',\n  ifAvailable: true, // Immediately fail if the lock is unavailable.\n  signal: myAbortSignal, // Optional: provide an AbortSignal for cancellation.\n});\n```\n\n---\n\n## API Documentation\n\n### `debounce(callback, options)`\n\n- **Parameters:**\n  - `callback` *(Function)*: The function to debounce.\n  - `options` *(Object, optional)*:\n    - `delay` *(number)*: The debounce delay in milliseconds.\n    - `priority` *(\"user-blocking\" | \"user-visible\" | \"background\")*: The task priority.\n    - `signal` *(AbortSignal)*: Signal to cancel the debounced call.\n    - `thisArg` *(any, default: null)*: The `this` context for the callback.\n  \n- **Returns:**  \n  A debounced version of the input function.\n\n- **Throws:**  \n  - `TypeError` if the callback is not a function.\n  - `Error` if the provided AbortSignal is already aborted.\n\n### `throttle(callback, options)`\n\n- **Parameters:**\n  - `callback` *(Function)*: The function to throttle.\n  - `options` *(Object, optional)*:\n    - `lockName` *(string, default: crypto.randomUUID())*: Name for the lock.\n    - `delay` *(number)*: Delay in milliseconds after task execution.\n    - `priority` *(\"user-blocking\" | \"user-visible\" | \"background\")*: The task priority.\n    - `ifAvailable` *(boolean, default: true)*: Fail immediately if the lock is not available.\n    - `steal` *(boolean, default: false)*: Allow stealing of the lock.\n    - `mode` *(\"shared\" | \"exclusive\", default: \"exclusive\")*: The lock mode (only 'exclusive' is supported).\n    - `thisArg` *(any, default: null)*: The `this` context for the callback.\n    - `signal` *(AbortSignal)*: Signal to cancel the throttled call.\n  \n- **Returns:**  \n  A throttled version of the input function.\n\n- **Throws:**  \n  - `TypeError` if the callback is not a function or if both `steal` and `ifAvailable` are set to true.\n  - `Error` if the provided AbortSignal is already aborted.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faegisjsproject%2Ftempo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faegisjsproject%2Ftempo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faegisjsproject%2Ftempo/lists"}