{"id":11508,"library":"over","title":"over - Function Overloading","description":"over is a JavaScript library designed to facilitate function overloading, allowing developers to define multiple implementations for a single function based on the arguments provided during invocation. It operates by accepting an array of 'test functions' (such as `over.string`, `over.numberOptionalWithDefault`, `over.callbackOptional`), which are used to match the types and presence of input arguments against predefined patterns. This enables complex argument signature management, default values for optional parameters, and callback handling in a structured way. The package is currently at version `0.0.5`, with its last significant activity in 2013, and the copyright dates back to 2012. This strongly suggests the project is abandoned, with no active development or maintenance. Its core differentiator was providing a declarative approach to function dispatch in a pre-ESM and pre-TypeScript era, often mitigating verbose `if`/`else` or switch statements for argument validation. It primarily targets Node.js environments.","status":"abandoned","version":"0.0.5","language":"javascript","source_language":"en","source_url":"https://github.com/nearinfinity/node-over","tags":["javascript","function","overload"],"install":[{"cmd":"npm install over","lang":"bash","label":"npm"},{"cmd":"yarn add over","lang":"bash","label":"yarn"},{"cmd":"pnpm add over","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package primarily supports CommonJS due to its age (last updated ~2013). Direct ES Module (ESM) import is not supported.","wrong":"import over from 'over';","symbol":"over","correct":"const over = require('over');"},{"note":"Built-in test functions like `over.string` are properties of the default `over` export (a function) and are not individually named exports.","wrong":"import { string } from 'over';","symbol":"over.string","correct":"const over = require('over');\nconst myFn = over([over.string, function (str) { /* ... */ }]);"}],"quickstart":{"code":"const over = require('over');\n\nconst myfn = over([\n  [over.string, function (str) { console.log('Called with a single string:', str); }],\n  [over.string, over.numberOptionalWithDefault(5), over.callbackOptional, function (str, number, callback) {\n    console.log('Called with string, optional number (default 5), and optional callback.');\n    console.log('String:', str, 'Number:', number);\n    if (callback) {\n      console.log('Executing callback...');\n      callback(str, number);\n    }\n  }],\n  function() {\n    console.log('No specific overload matched. Falling back to default.');\n  }\n]);\n\n// Test cases\nmyfn(\"hello\");\nmyfn(\"world\", 10, (s, n) => console.log(`Callback invoked: ${s}, ${n}`));\nmyfn(\"test\", null, (s, n) => console.log(`Callback invoked with null number: ${s}, ${n}`)); // numberOptionalWithDefault should handle null/undefined\nmyfn(\"another test\", undefined, (s, n) => console.log(`Callback invoked with undefined number: ${s}, ${n}`));\nmyfn(); // Should hit default","lang":"javascript","description":"Demonstrates defining multiple function overloads using `over` with various argument matchers, including optional parameters with defaults and callbacks, then calling the overloaded function with different argument sets to show matching behavior."},"warnings":[{"fix":"Evaluate modern alternatives for function overloading or implement pattern matching manually using contemporary JavaScript features. Consider using TypeScript's built-in overloading capabilities for type-safe overloading.","message":"This package appears to be abandoned since 2013 and is no longer maintained. Using an unmaintained library introduces significant security risks, as it will not receive patches for vulnerabilities or updates for compatibility with modern JavaScript runtimes or security standards.","severity":"breaking","affected_versions":">=0.0.5"},{"fix":"If you must use this package in an ESM project, consider dynamic `import()` or wrapper CJS modules, but prefer refactoring to avoid this dependency in modern applications.","message":"The package was developed for CommonJS environments and does not natively support ES Modules (ESM). Attempting to `import over from 'over';` in an ESM context will likely result in errors like `ERR_REQUIRE_ESM` or `over is not defined`.","severity":"gotcha","affected_versions":">=0.0.5"},{"fix":"Thoroughly test the package in your specific Node.js environment. Consider containerizing applications to pin Node.js versions if legacy dependencies are unavoidable, but a full refactor is recommended.","message":"Due to its age, `over` may exhibit compatibility issues with newer Node.js versions, particularly those released after 2013. Behavior might be undefined or lead to runtime errors, especially with changes in core APIs or internal JavaScript engine optimizations.","severity":"gotcha","affected_versions":">=0.0.5"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change your module to CommonJS by ensuring it's a `.js` file and not declared as an ES Module in `package.json`, or use a dynamic `import()` if absolutely necessary: `const over = await import('over');`.","cause":"Attempting to use `require()` in an ES Module context (e.g., in a `.mjs` file or a `.js` file where `\"type\": \"module\"` is set in `package.json`).","error":"ReferenceError: require is not defined"},{"fix":"Ensure you are using the correct CommonJS `require` syntax for importing the package: `const over = require('over');`.","cause":"Incorrectly attempting to use named imports or default ES Module imports (`import over from 'over';`) in an environment where `over` only provides a CommonJS export.","error":"TypeError: over is not a function"}],"ecosystem":"npm"}