{"id":14616,"library":"hashmap","title":"HashMap Class for JavaScript","description":"The `hashmap` package provides a `HashMap` class for JavaScript, designed to store key/value pairs where keys can be of *any* data type, including objects, numbers, and dates, without the implicit stringification that occurs with plain JavaScript objects. This was a key differentiator before the introduction of native `Map` in ES6. The current stable version is 2.4.0. Given its last update was over eight years ago, the package is effectively abandoned, with no active development or release cadence. It targets both Node.js and browser environments and differentiates itself by allowing complex objects as keys without coercion.","status":"abandoned","version":"2.4.0","language":"javascript","source_language":"en","source_url":"git://github.com/flesler/hashmap","tags":["javascript","hashmap","map","object","array","associative","nodejs","node"],"install":[{"cmd":"npm install hashmap","lang":"bash","label":"npm"},{"cmd":"yarn add hashmap","lang":"bash","label":"yarn"},{"cmd":"pnpm add hashmap","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only. Attempting to use ES Modules `import` syntax directly will likely result in a runtime error or `undefined` in pure ESM environments without a CJS interop layer.","wrong":"import { HashMap } from 'hashmap';","symbol":"HashMap","correct":"const HashMap = require('hashmap');"}],"quickstart":{"code":"const HashMap = require('hashmap');\n\n// Create a new HashMap instance\nconst map = new HashMap();\n\n// Basic key-value pair storage\nmap.set('stringKey', 'Hello World');\nmap.set(123, 'Numeric Key');\n\nconsole.log('Value for \"stringKey\":', map.get('stringKey')); // Expected: Hello World\nconsole.log('Value for 123:', map.get(123)); // Expected: Numeric Key\n\n// Demonstrating non-stringified object keys\nconst objKey1 = { id: 1 };\nconst objKey2 = { id: 2 };\nmap.set(objKey1, 'First object');\nmap.set(objKey2, 'Second object');\n\nconsole.log('Value for objKey1:', map.get(objKey1)); // Expected: First object\nconsole.log('Value for objKey2:', map.get(objKey2)); // Expected: Second object\n\n// Get current size\nconsole.log('Map size:', map.size); // Expected: 4\n\n// Delete a key-value pair\nmap.delete('stringKey');\nconsole.log('Map size after deletion:', map.size); // Expected: 3\n\n// Iterate over key-value pairs\nconsole.log('Map entries:');\nmap.forEach(function(value, key) {\n    console.log(`  Key: ${JSON.stringify(key)}, Value: ${value}`);\n});","lang":"javascript","description":"This example demonstrates how to import `HashMap` using CommonJS, set and retrieve values with various key types (string, number, object), check the map's size, delete entries, and iterate over its contents."},"warnings":[{"fix":"For new projects or if encountering issues, consider using the native JavaScript `Map` object, which provides similar arbitrary key-type functionality and is actively maintained as part of the JavaScript standard library.","message":"The `hashmap` package has not been updated in over eight years (last publish date is 8 years ago as of April 2026). This indicates it is likely abandoned, may not be compatible with newer Node.js versions or browser features, and will not receive security patches or bug fixes.","severity":"gotcha","affected_versions":">=2.4.0"},{"fix":"Use `map.delete(key)` instead of `map.remove(key)` and `map.size` instead of `map.count()` for consistency and to avoid deprecated API usage.","message":"The methods `remove(key)` and `count()` are deprecated aliases. `remove(key)` is an alias for `delete(key)`, and `count()` is an alias for the `size` property.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"For Node.js projects, use `const HashMap = require('hashmap');`. If integrating into a modern frontend build system, ensure your bundler (e.g., Webpack, Rollup) is configured to handle CommonJS modules.","message":"This package is designed for CommonJS (`require`) and does not natively support ES Modules (`import`). Attempting to use `import` syntax directly in a pure ESM environment without a CJS interop layer will fail.","severity":"gotcha","affected_versions":"*"},{"fix":"Create a `declarations.d.ts` file with `declare module 'hashmap';` or more specific types if needed. Alternatively, search for `@types/hashmap` on npm, though it's unlikely to exist for an abandoned package.","message":"The package does not ship with TypeScript type definitions (`.d.ts` files). Users in TypeScript projects will need to provide their own type declarations or install community-maintained types (if available) to avoid type errors.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Use the CommonJS `require` syntax: `const HashMap = require('hashmap');`.","cause":"Attempting to use `import HashMap from 'hashmap';` or `import { HashMap } from 'hashmap';` in a pure ES Modules environment where the package only exports CommonJS.","error":"TypeError: HashMap is not a constructor"},{"fix":"Use `map.delete(key)` instead of `map.remove(key)`.","cause":"Calling the deprecated `remove()` method.","error":"TypeError: map.remove is not a function"},{"fix":"Ensure `const HashMap = require('hashmap');` correctly assigns the constructor and that `new HashMap()` is called to instantiate the map before attempting to use its methods.","cause":"Incorrect import or `require` leading to `map` being `undefined`.","error":"TypeError: Cannot read properties of undefined (reading 'set')"}],"ecosystem":"npm"}