New:Socket for Asana Is Now Available.Learn more
Get Started

@cspell/strong-weak-map

Package Overview
Dependencies
Maintainers
1
Versions
162
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cspell/strong-weak-map

A Map with weakly referenced values.

latest
Source
npmnpm
Version
10.2.1
Version published
Weekly downloads
1.4M
-1.97%
Maintainers
1
Weekly downloads
 
Created
Source

@cspell/strong-weak-map

A Map with weakly referenced values.

JavaScript WeakMap provides weak keys and strong values.

StrongWeakMap allows for strong keys and weak values while providing the same API as Map.

Install

npm install -S @cspell/strong-weak-map

Usage

TypeScript Example: Simple text file reader.

import { StrongWeakMap } from '@cspell/strong-weak-map';
import { promises as fs } from 'fs';

const cache = new StrongWeakMap<string, Promise<string>>();

export function readTextFile(filename: string, encoding: BufferEncoding = 'utf8'): Promise<string> {
  const cached = cache.get(filename);
  if (cached) return cached;

  const content = fs.readFile(filename, encoding);

  cache.set(filename, content);

  return content;
}

The above example will reuse the promise as long as it has not been cleaned up by the Garbage Collector.

API

See: Map


Brought to you byStreet Side Software Logo Street Side Software

Keywords

Map

FAQs

Package last updated on 03 Sep 2026

Related posts