# umap

> The smallest, yet handy, Map and WeakMap utility ever

Latest version **1.0.2** (published 2020-03-13) · ISC license · 0 weekly downloads

## Install

```sh
npm install umap
pnpm add umap
yarn add umap
bun add umap
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2020-03-13 |
| First published | 2020-03-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | Andrea Giammarchi |
| Maintainers | webreflection |
| Keywords | map, weakmap, get, set, shortcut |

## Links

- npm: https://www.npmjs.com/package/umap
- Repository: https://github.com/WebReflection/umap
- Homepage: https://github.com/WebReflection/umap#readme
- Issues: https://github.com/WebReflection/umap/issues
- npm.io page: https://npm.io/package/umap

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2020-03-13
- 1.0.1 — 2020-03-13
- 1.0.0 — 2020-03-13
- 0.0.1 — 2020-03-13
- 0.0.0 — 2020-03-13

## README

# <em>µ</em>map 🗺

[![Build Status](https://travis-ci.com/WebReflection/umap.svg?branch=master)](https://travis-ci.com/WebReflection/umap) [![Coverage Status](https://coveralls.io/repos/github/WebReflection/umap/badge.svg?branch=master)](https://coveralls.io/github/WebReflection/umap?branch=master)

The smallest, yet handy, `Map` and `WeakMap` utility ever.

```js
import umap from 'umap';
// const umap = require('umap');

const map = umap(new Map);
console.assert(
  (map.get(1) || map.set(1, Math.random())) ===
  (map.get(1) || map.set(1, Math.random())),
  'a very common pattern I have with Map instances'
);

const weakMap = umap(new WeakMap);
console.assert(
  (weakMap.get(map) || weakMap.set(map, Math.random())) ===
  (weakMap.get(map) || weakMap.set(map, Math.random())),
  'which I use even more with WeakMap instances'
);
```

### 🤔 Reason

I am super tired of creating workarounds for the fact `map.set(key, value)` doesn't return value but the `map` itself, and so does the _WeakMap_.

This module will help, at least me, dropping all one-off helpers, here and there, to always do the same thing:

```js
// before 😢
const cache = new WeakMap;
const setThing = (key, value) => {
  cache.set(key, value);
  return value;
};
const thing = cache.get(key) || setThing(key, value);

// with umap 🎉
const cache = umap(new WeakMap);
const thing = cache.get(key) || cache.set(key, value);
```

### 🌈 It's Done!

This module is meant to solve one pattern only, and it does exactly that, so that if you store _falsy_ values in _Maps_ or _WeakMaps_, it is not a concern of this module.

---
_Source: https://npm.io/package/umap · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
