{"library":"sticky-module","title":"Sticky Module Singleton Utility","type":"library","description":"sticky-module is a specialized JavaScript utility designed to guarantee that a given module is instantiated and evaluated only once, even across multiple imports or different bundling contexts within an application. It achieves this by storing and retrieving module instances using a unique, Symbol-based key, effectively creating an application-wide singleton for that module. This mechanism is particularly useful for libraries or components that require strict single-instance behavior to maintain consistent state or prevent redundant setup in complex module graphs, micro-frontends, or scenarios with multiple bundler outputs. The current stable version is 0.1.1. Its release cadence is likely slow, focusing on stability given its niche purpose. A key differentiator is its Symbol-based internal storage, which offers a robust and collision-resistant approach to global module caching compared to string-based keys.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install sticky-module"],"cli":null},"imports":["import stickyModule from 'sticky-module';","let [{ config }, known] = stickyModule('my-config', { config: {} });"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/WebReflection/sticky-module","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/sticky-module","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import stickyModule from 'sticky-module';\n\nconsole.log('--- First attempt to get module ---');\nlet [{a, b}, known] = stickyModule('@custom/my-singleton', {\n  a: Math.random(),\n  b: 'initial value'\n});\n\nconsole.log(`Was module known? ${known}`);    // Expected: false\nconsole.log(`Module values: a=${a}, b='${b}'`); // Shows initial random 'a' and 'b'\n\n// Simulate a delay or another part of the application importing it later\nsetTimeout(() => {\n  console.log('\\n--- Second attempt to get module (after delay) ---');\n  let [{a: a2, b: b2}, known2] = stickyModule('@custom/my-singleton', {\n    a: Math.random(), // This value will be ignored as module is already stored\n    b: 'new value, ignored' // This value will also be ignored\n  });\n\n  console.log(`Was module known? ${known2}`);    // Expected: true\n  console.log(`Module values: a=${a2}, b='${b2}'`); // Shows the *same* initial random 'a' and 'b'\n\n  // Verify they are the same instance/values\n  console.log(`Are 'a' and 'a2' the same? ${a === a2}`); // Expected: true\n  console.log(`Are 'b' and 'b2' the same? ${b === b2}`); // Expected: true\n}, 100);\n","lang":"javascript","description":"Demonstrates how sticky-module ensures a module is initialized only once, returning the original instance on subsequent calls.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}