npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@typescript-package/map

v1.0.0

Published

A lightweight TypeScript library for enhanced `map` management.

Readme

typescript-package/map

npm version GitHub issues GitHub license

A lightweight TypeScript library for enhanced map management.

Table of contents

Installation

1. Install peer data dependencies

npm install @typescript-package/data --save-peer

2. Install the map package

npm install @typescript-package/map --save-peer

Api

import {
  // Abstract.
  CoreMap,
  MapOnHook,

  // Class.
  DataMap,
  FactoryMap,
  WeakDataMap,
} from '@typescript-package/map';

CoreMap

The abstract core class is designed for building Map and DataCore related classes.

import { CoreMap } from '@typescript-package/map';

DataMap

The DataMap is a concrete class that extends Map and encapsulates its data within a DataCore store, providing additional data management capabilities.

import { DataMap } from '@typescript-package/map';

// Define a `DataCore` implementation for holding a data in `DataMap`.
export class CustomMapData<Key, Value> extends Data<Map<Key, Value>> {
  constructor(initialValue?: Map<Key, Value>) {
    super(initialValue ?? new Map());
  }
}

// Create a new `DataMap` instance with predefined entries and customized data holder.
export const dataMap = new DataMap
// <string, number, CustomMapData<string, number>> previous approach, now captured.
(
  [
    ["one", 1],
    ["two", 2],
    ["three", 3],
  ],
  // new CustomMapData() // previous approach
  CustomMapData // new approach
); // const dataMap: DataMap<string, number, CustomMapData<string, number>>

// Check the `CustomMapData`.
console.log(`Data holder of \`CustomMapData\`:`, dataMap.data); // Output: CustomMapData {#locked: false, #value: Value}

// Get the `CustomMapData` value.
console.log(`Data holder of \`CustomMapData\` value:`, dataMap.data.value); // Output: Map(3) {'one' => 1, 'two' => 2, 'three' => 3}

// Log the size of the map
console.log("Size:", dataMap.size); // Output: Size: 3

// Get a value from the map
console.log("Value for 'two':", dataMap.get("two")); // Output: Value for 'two': 2

// Check if a key exists
console.log("Has 'three'?", dataMap.has("three")); // Output: Has 'three'? true

// Set a new key-value pair
dataMap.set("four", 4);
console.log("Size after set:", dataMap.size); // Output: Size after set: 4

// Iterate over entries
dataMap.forEach((value, key) => console.log(`${key}: ${value}`));
// Output:
// one: 1
// two: 2
// three: 3
// four: 4

// Delete an entry
dataMap.delete("one");
console.log("Size after delete:", dataMap.size); // Output: Size after delete: 3

// Clear the map
dataMap.clear();
console.log("Size after clear:", dataMap.size); // Output: Size after clear: 0

FactoryMap

import { FactoryMap } from '@typescript-package/map';

// Define custom `Map`.
export class CustomMap<Key, Value> extends Map<Key, Value> {
  public newMethod() {}
  constructor(entries?: [Key, Value][]) {
    super(entries);
  }
}

// Define data storage to store custom map.
export class TestCustomMapData<Key, Value> extends Data<CustomMap<Key, Value>> {
  constructor(initialValue?: CustomMap<Key, Value>) {
    super(initialValue ?? new CustomMap());
  }
}

// Initialize the factory map with custom map and data.
const factoryMap = new FactoryMap(
  [['a', {x: 1}], ['b', {x: 2}]],

  // Use custom `Map`
  CustomMap,

  // Use custom storage for custom map.
  TestCustomMapData,
  {
    // Define function for the default value.
    defaultValue: () => ({x: 0}),

    // Define cloner by using the `structuredClone`.
    cloner: (value) => structuredClone(value),
  }
); // const factoryMap: FactoryMap<string, { x: number; }, CustomMap<string, { x: number }>, TestCustomMapData<string, { x: number; }>>

console.log(factoryMap.get('c')); // { x: 0 }
console.log(factoryMap.get('b')); // { x: 2 }
console.log(factoryMap.get('a')); // { x: 1 }
console.debug(factoryMap.sort()); // sort.

WeakDataMap

The WeakDataMap class is a concrete class that stores data in a static WeakMap.

import { WeakDataMap } from '@typescript-package/map';

// Create an instance of `WeakDataMap`.
const weakDataMap = new WeakDataMap([
  ['one', 1],
  ['two', 2],
  ['three', 3],
]);


// Get the value from `WeakData` static.
console.log(`data: `, WeakData.get(weakDataMap.data)); // Output: Map(3) {'one' => 1, 'two' => 2, 'three' => 3}

// Get a value by key
console.log(weakDataMap.get('two')); // Output: 2

// Add a new key-value pair
weakDataMap.set('four', 4);

// Check if a key exists
console.log(weakDataMap.has('four')); // Output: true

// Delete a key
weakDataMap.delete('one');

// Iterate over entries
for (const [key, value] of weakDataMap.entries()) {
  console.log(key, value);
}

// Output:
// two 2
// three 3
// four 4

Contributing

Your contributions are valued! If you'd like to contribute, please feel free to submit a pull request. Help is always appreciated.

Support

If you find this package useful and would like to support its and general development, you can contribute through one of the following payment methods. Your support helps maintain the packages and continue adding new.

Support via:

Thanks for your support!

Code of Conduct

By participating in this project, you agree to follow Code of Conduct.

GIT

Commit

Versioning

Semantic Versioning 2.0.0

Given a version number MAJOR.MINOR.PATCH, increment the:

  • MAJOR version when you make incompatible API changes,
  • MINOR version when you add functionality in a backwards-compatible manner, and
  • PATCH version when you make backwards-compatible bug fixes.

Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.

FAQ How should I deal with revisions in the 0.y.z initial development phase?

The simplest thing to do is start your initial development release at 0.1.0 and then increment the minor version for each subsequent release.

How do I know when to release 1.0.0?

If your software is being used in production, it should probably already be 1.0.0. If you have a stable API on which users have come to depend, you should be 1.0.0. If you’re worrying a lot about backwards compatibility, you should probably already be 1.0.0.

License

MIT © typescript-package (license)

Packages