Registry / serialization / typescript-map

typescript-map

JSON →
library0.1.0jsnpmunverified

This library, `typescript-map`, provides a lightweight, TypeScript-first implementation of an ES6 Map-like data structure. Currently at version 0.1.0, it is designed for scenarios where a full ES6 Map polyfill is not desired or where bundle size is a critical concern, weighing in at just over 1 kilobyte gzipped. A key differentiator is its deliberate simplicity: it does not employ a hashing function. While this keeps the implementation small and straightforward, it means the library is explicitly *not* recommended for use with more than a few hundred keys or in performance-critical "hot path" operations, where native `Map` or more robust alternatives like `es6-map` would be superior. The release cadence appears to be slow or inactive given the low version number and its niche purpose. It is primarily intended for TypeScript projects needing a basic, type-safe map collection without significant overhead.

npm install typescript-map
INSTALL
IMPORT
SIG · TYPESCRIPT-MAP
T
typescript-map
serializationjavascriptv0.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TSMap
import { TSMap } from 'typescript-map'
import TSMap from 'typescript-map'
The primary class is a named export, not a default export. For TypeScript and modern JavaScript (ESM).
TSMap
const TSMap = require('typescript-map').TSMap;
const { TSMap } = require('typescript-map');
For CommonJS environments, access the `TSMap` class from the module's property.
TSMap
<script src="tsmap.min.js"></script> // Then use global TSMap
When used directly in a browser without a module loader, the library exposes `TSMap` as a global variable. Be mindful of global scope pollution.

Demonstrates basic instantiation, setting and getting values, type-safe usage with generics, initialization with an array, and a custom `fromJSON` method.

import { TSMap } from 'typescript-map'; // Basic usage, similar to native Map const myMap = new TSMap(); myMap.set('foo', 'bar'); console.log(myMap.get('foo')); // Prints: bar // With TypeScript generics for type safety const typedMap = new TSMap<string, number>(); typedMap.set('apple', 1); typedMap.set('banana', 2); console.log(typedMap.get('apple')); // Prints: 1 // Initialize with an array of key-value pairs const initMap = new TSMap<string, string>([ ['key1', 'valueA'], ['key2', 'valueB'] ]); console.log(initMap.size); // Prints: 2 // Example of a custom function: fromJSON const jsonMap = new TSMap().fromJSON({ name: 'Alice', age: 30, city: 'New York' }, false); console.log(jsonMap.get('name')); // Prints: Alice
Debug
Known issues
gotchaThis library is not an ES6 Map polyfill. It provides a similar interface but is a separate implementation. Do not expect it to patch `Map` or behave identically to the native `Map` specification in every edge case.
fix
If a full ES6 Map polyfill is required, use `es6-map` or a similar solution. This library is an alternative for specific use cases.
affects: >=0.1.0
gotchaPerformance will degrade significantly for maps containing hundreds or thousands of keys, or when used in performance-critical code paths. The implementation does not use a hashing function to keep it small and simple.
fix
For large datasets or 'hot path' scenarios, use the native `Map` object or a robust polyfill/library that employs hashing (e.g., `es6-map`).
affects: >=0.1.0
gotchaWhen included directly in a browser via a `<script>` tag, the `TSMap` class is exposed as a global variable. This can lead to global namespace pollution or conflicts with other libraries.
fix
Prefer using module bundlers (like Webpack or Rollup) with ES modules or CommonJS imports to encapsulate the library's scope and avoid global variable conflicts.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: TSMap is not a constructor
Attempting to call `TSMap` directly without the `new` keyword, or incorrect CommonJS import.
fix
Ensure you are instantiating the class with `new TSMap()` and that your CommonJS import is `const TSMap = require('typescript-map').TSMap;`.
Error: Cannot read properties of undefined (reading 'set')
Trying to call methods on an uninitialized or incorrectly imported `TSMap` instance.
fix
Verify that `TSMap` has been correctly imported and instantiated (e.g., `const myMap = new TSMap();`).
Argument of type 'TSMap<string, number>' is not assignable to parameter of type 'Map<string, number>'
Passing a `TSMap` instance to a function or API that specifically expects a native `Map` object.
fix
This library is not a polyfill for the native `Map`. If native `Map` compatibility is required, consider using `es6-map` or adapting your code to accept `TSMap` where appropriate, or converting `TSMap` to a standard object if only basic iteration is needed.
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
12
Amazon
1
OpenAI (training)
1
Resources
typescript-map — npm install typescript-map · libregistry