Socket
Socket
Sign inDemoInstall

@cspell/strong-weak-map

Package Overview
Dependencies
0
Maintainers
1
Versions
82
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @cspell/strong-weak-map

A Map with weakly referenced values.


Version published
Weekly downloads
417K
increased by3.09%
Maintainers
1
Install size
10.4 kB
Created
Weekly downloads
 

Changelog

Source

8.7.0 (2024-04-10)

Note: Version bump only for package cspell-monorepo

Readme

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 by Street Side Software Logo Street Side Software

Keywords

FAQs

Last updated on 10 Apr 2024

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc