{"id":11301,"library":"metal-debounce","title":"Metal Debounce Utility","description":"metal-debounce is a utility library providing a debounce function, originally part of the deprecated Metal.js framework. It delays the execution of a function until a specified time has elapsed since its last invocation, a common pattern for optimizing event handlers (e.g., input, resize, scroll) by preventing excessive calls. The current stable version is 2.0.2, last published approximately seven years ago. As the Metal.js framework itself is no longer actively maintained for open-source releases, this package should be considered abandoned. It likely targets older JavaScript environments and CommonJS modules, lacking modern features like native ESM support or TypeScript definitions. Alternatives like `lodash.debounce` or `debounce-fn` offer more robust and actively maintained solutions.","status":"abandoned","version":"2.0.2","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","metal"],"install":[{"cmd":"npm install metal-debounce","lang":"bash","label":"npm"},{"cmd":"yarn add metal-debounce","lang":"bash","label":"yarn"},{"cmd":"pnpm add metal-debounce","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CJS-only. ESM imports are not supported.","wrong":"import debounce from 'metal-debounce';","symbol":"debounce","correct":"const debounce = require('metal-debounce');"},{"note":"The `require` call directly provides the debounce function.","symbol":"debounce function","correct":"const debounce = require('metal-debounce');\nconst debouncedFunction = debounce(() => console.log('Action!'), 200);"}],"quickstart":{"code":"const debounce = require('metal-debounce');\n\nfunction logActivity(message) {\n  console.log(`Activity: ${message} at ${new Date().toLocaleTimeString()}`);\n}\n\n// Create a debounced version of logActivity that waits 500ms\nconst debouncedLog = debounce(logActivity, 500);\n\nconsole.log('Simulating rapid events...');\ndebouncedLog('Event 1');\ndebouncedLog('Event 2');\ndebouncedLog('Event 3');\n\nsetTimeout(() => {\n  console.log('Waiting 600ms after last debounced call...');\n  debouncedLog('Event 4 (should trigger)');\n}, 600);\n\nsetTimeout(() => {\n  console.log('Simulating more rapid events after initial trigger...');\n  debouncedLog('Event 5');\n  debouncedLog('Event 6');\n}, 1200);\n\nsetTimeout(() => {\n  console.log('Final wait...');\n}, 2000);","lang":"javascript","description":"Demonstrates basic usage of the `debounce` function to limit repeated calls, such as from rapid user input."},"warnings":[{"fix":"Migrate to a currently maintained debounce utility like `lodash.debounce`, `debounce-fn`, or a modern framework's built-in debounce. These offer better support, performance, and often ESM compatibility.","message":"The `metal-debounce` package, along with its parent Metal.js framework, is officially deprecated and abandoned. No further active development, new features, or maintenance is expected.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Always use `require('metal-debounce')` to import the utility. For modern projects requiring ESM, consider alternative, actively maintained debounce libraries.","message":"This package is designed for CommonJS environments and does not natively support ES Modules (`import`/`export` syntax). Attempting to use ESM imports will result in runtime errors.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"While functional for basic debounce needs in older environments, developers should be aware of potential compatibility issues or the need for manual type declarations in TypeScript projects. Prefer modern alternatives for new development.","message":"The package's age (last updated 7 years ago) means it likely lacks TypeScript definitions, modern JavaScript syntax (ES6+), and might not be optimized for current Node.js or browser environments.","severity":"gotcha","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure you are using `const debounce = require('metal-debounce');` to correctly import the function, as it's a direct export.","cause":"Attempting to destructure a CommonJS module that exports a single function directly, or incorrect import syntax.","error":"TypeError: debounce is not a function"},{"fix":"Change your import statement to `const debounce = require('metal-debounce');`. If your project requires ESM, you must migrate to a different, actively maintained debounce library that explicitly supports ESM.","cause":"Attempting to use ES module `import` syntax in a CommonJS-only environment (e.g., an older Node.js project or without proper transpilation/configuration).","error":"SyntaxError: Cannot use import statement outside a module"}],"ecosystem":"npm"}