# mapish

> A serializable, string key map

Latest version **1.1.1** (published 2021-05-11) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2021-05-11 |
| First published | 2019-12-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 20.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Sean Wong |
| Maintainers | platokon |
| Keywords | serializable, string-key, map |

## Links

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

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 1.1.1 (latest) — 2021-05-11
- 0.6.0-alpha.0 (rc) — 2020-02-24
- 1.1.0 — 2020-04-27
- 1.0.0 — 2020-04-10
- 0.6.0 — 2020-02-24
- 0.5.0 — 2020-02-19
- 0.4.4 — 2020-02-13
- 0.4.3 — 2020-02-10
- 0.4.2 — 2020-02-06
- 0.4.1 — 2020-02-05
- 0.4.0 — 2020-02-05
- 0.3.0 — 2019-12-23
- 0.2.0 — 2019-12-18
- 0.1.1 — 2019-12-18
- 0.1.0 — 2019-12-18

## README

# mapish

A serializable, string key map

## Usage

```
npm i mapish
```

Extremely like creating a map, and it's serializable.

```typescript
import { Mapish } from "mapish";

const map = new Mapish<string>([
  ["sean", "hello"],
  ["arthur", "bye"]
]);

JSON.stringify(map); // => `{"sean":"hello","arthur":"bye"}`
```

Simple helper static functions `keyBy`, `groupBy` and `fromObject` to create a Mapish instance, works just like lodash.

```typescript
import { Mapish } from "mapish";

/** ===== keyBy ===== */
const users = [
  { id: "1", name: "sean", age: 23 },
  { id: "2", name: "arthur", age: 32 }
];
const userMap = Mapish.keyBy(users, user => user.id);

userMap.has("1"); // => true
userMap.get("1"); // => { id: "1", name: "sean", age: 23 }
JSON.stringify(userMap); // => `{"1":{"id":"1","name":"sean","age":23},"2":{"id":"2","name":"arthur","age":32}}`

/** ===== groupBy ===== */
const lessons = [
  { name: "math", on: "Tuesday" },
  { name: "math", on: "Thursday" },
  { name: "chinese", on: "Friday" }
];
const lessonMap = Mapish.groupBy(lessons, lesson => lesson.name);

lessonMap.has("math"); // => true
lessonMap.get("lessonMap"); // => [{ name: "math", on: "Tuesday" }, { name: "math", on: "Thursday" }]
JSON.stringify(lessonMap); // => `{"math":[{"name":"math","on":"Tuesday"},{"name":"math","on":"Thursday"}],"chinese":[{"name":"chinese","on":"Friday"}]}`

/** ===== fromObject ===== */
const object = { sean: "hello", arthur: "bye" };
const objectMap = Mapish.fromObject(object);

JSON.stringify(map); // => `{"sean":"hello","arthur":"bye"}`
```

And more useful instance functions like `toArray` and advanced `get`

```typescript
const map = new Mapish([
  ["key1", "value1"],
  ["key2", "value2"]
]);

map.toArray((v, k) => v + " " + k); // => ["key1 value1", "key2 value2"]

map.get("key1", "key2"); // => ['value1', 'value2']
```

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