Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cspell/strong-weak-map

Package Overview
Dependencies
Maintainers
1
Versions
114
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.

  • 8.16.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
638K
decreased by-9.52%
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

FAQs

Package last updated on 27 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc