# mapping-data

> Mapping data with map or object in the same interface and support types Key and value in typescript

Latest version **1.0.1** (published 2024-04-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install mapping-data
pnpm add mapping-data
yarn add mapping-data
bun add mapping-data
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2024-04-17 |
| First published | 2024-04-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | damartripamungkas |
| Maintainers | damartripamungkas |
| Keywords | state, mapping, map, object, store, store-data, fast-store-data, mapping-data, data-mapping |

## Links

- npm: https://www.npmjs.com/package/mapping-data
- Repository: https://github.com/damartripamungkas/mapping-data
- Issues: https://github.com/damartripamungkas/mapping-data/issues
- npm.io page: https://npm.io/package/mapping-data

## Alternatives

- [@reckona/mreact-store](https://npm.io/package/@reckona/mreact-store.md) — 976 weekly downloads
- [regular-state](https://npm.io/package/regular-state.md) — 410 weekly downloads
- [@pacote/flux-actions](https://npm.io/package/@pacote/flux-actions.md) — 65 weekly downloads
- [@pilotlab/lux-debug](https://npm.io/package/@pilotlab/lux-debug.md) — 39 weekly downloads
- [vue-persist-state](https://npm.io/package/vue-persist-state.md) — 19 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2024-04-17
- 1.0.0 — 2024-04-16

## README

<h1 align="center">
    MAPPING-DATA
</h1>

<p align="center">
  <img alt="GitHub top language" src="https://img.shields.io/github/languages/top/damartripamungkas/mapping-data?color=04D361&labelColor=000000">
  
  <a href="#">
    <img alt="Made by" src="https://img.shields.io/static/v1?label=made%20by&message=damartripamungkas&color=04D361&labelColor=000000">
  </a>
  
  <img alt="Repository size" src="https://img.shields.io/github/repo-size/damartripamungkas/mapping-data?color=04D361&labelColor=000000">
  
  <a href="#">
    <img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/damartripamungkas/mapping-data?color=04D361&labelColor=000000">
  </a>
</p>

### 📖 Description :

This package is made for those of you who want the key and value to have the same type of type, because using `new Map()` and defining the type to the map then only the key works while the value does not, I give an example below:

#### Using Map

```typescript
type TypeStateAs = {
  name: string
  age: number
  human: boolean
}
const state = new Map<keyof TypeStateAs, TypeStateAs[keyof TypeStateAs]>()
state.set(`name`, true) // is not an error, even though the value type is not boolean. expect this to be an error
```

#### Using Package

```typescript
import { MappingMap } from "mapping-data"

type TypeStateAs = {
  name: string
  age: number
  human: boolean
}
const state = new MappingMap<keyof TypeStateAs, TypeStateAs[keyof TypeStateAs], TypeStateAs>()
state.set(`name`, true) // this is will throw error in editor code, because value type `name` is string
```

### 🔮 Cheatsheet

If you only need types for the `.set()` and `.get()` functions without having to use classes from the package you can import and define them as below :

```typescript
import type { MappingMap } from "mapping-data"

type TypeStateAs = {
  name: string
  age: number
  human: boolean
}
const state: MappingMap<keyof TypeStateAs, TypeStateAs[keyof TypeStateAs], TypeStateAs> = new Map() as any
state.set(`name`, true) // this is will throw error in editor code, because value type `name` is string
```

### 💻 Step to install :

```
npm install mapping-data
```

### ✏️ Example :

see full [here](./test/test.js)

```typescript
import { MappingMap, MappingObj } from "mapping-data"

type TypeStateAs = {
  name: string
  age: number
  human: boolean
}
const state = new MappingMap<keyof TypeStateAs, TypeStateAs[keyof TypeStateAs], TypeStateAs>()
state.set(`name`, `damar`)
state.get(`name`) // damar
state.jsonObject() // {name:"damar"}
state.jsonString() // "{"name":"damar"}"
```

### 🧾 Pre-Requisistes :

```
node.js
```

### 📝 License :

Licensed under the [MIT License](./LICENSE).

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