# mapper-utils

> Object mapper

Latest version **0.0.3** (published 2025-01-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install mapper-utils
pnpm add mapper-utils
yarn add mapper-utils
bun add mapper-utils
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2025-01-12 |
| First published | 2022-03-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 13 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Lucas Marrane Siler |
| Maintainers | lucasmarranesiler |
| Keywords | object2object, mapper, ts, object-mapper, mapper-utils |

## Links

- npm: https://www.npmjs.com/package/mapper-utils
- Repository: https://github.com/LucasMarrane/ObjectMapper
- Homepage: https://github.com/LucasMarrane/ObjectMapper#readme
- Issues: https://github.com/LucasMarrane/ObjectMapper/issues
- npm.io page: https://npm.io/package/mapper-utils

## Dependencies (1)

- [typescript](https://npm.io/package/typescript.md) ^5.7.3

## Alternatives

- [csv-to-markdown-table](https://npm.io/package/csv-to-markdown-table.md) — 47.0K weekly downloads
- [@sapphire/ratelimits](https://npm.io/package/@sapphire/ratelimits.md) — 4.4K weekly downloads
- [js-csvparser](https://npm.io/package/js-csvparser.md) — 2.0K weekly downloads
- [@adadapted/js-sdk](https://npm.io/package/@adadapted/js-sdk.md) — 251 weekly downloads
- [@grapecity/spread-sheets-sparklines](https://npm.io/package/@grapecity/spread-sheets-sparklines.md) — 103 weekly downloads

## Recent versions

- 0.0.3 (latest) — 2025-01-12
- 0.0.2 — 2023-03-26
- 0.0.1 — 2022-03-12

## README

# mapper-utils

# Deprecated package ❌

This package is being deprecated, please use: 

```shell
$ npm i @marrsys/utils
```

A comprehensive utility library providing various helper functions, decorators, and services for JavaScript/TypeScript applications.  

It has compatibility with **mapper-utils@0.0.2**, only needs to call **MapperUtils.Mapper**.

## About

Utility class to transform an object into another.

## Installation

```shell
$ npm i mapper-utils
```

## Usage

It has two way to map an object, first one (`Mapper.createMap<IUser, IData>()`) is appending map item into a array and after all done its returns a mapped object, and second one is (`Mapper.createMap<IUser, IData>(param)`) thats changes an object by a key.

#### TSource & TDestination

`TSource` object that values will be transformed;
`TDestination` object that will receive all transformed values;

### Base for examples

```javascript
import { Mapper } from "mapper-utils";

interface IUser {
  name: string;
  surname: string;
  age: number;
}

interface IData {
  fullname: string;
  isUnderEigthteen: boolean;
}

const user: IUser = {
  age: 24,
  name: "Lucas",
  surname: "Marrane Siler",
};
```

#### CreateMap

```typescript
...

//this way is slow, because iterations for dynamic map
const UserSlow = Mapper.createMap<IUser, IData>()
    .forField('fullname', (from) => `${from?.name} ${from?.surname}`)
    .forField('isUnderEigthteen', (from) => <number>from?.age < 18)
    .map(user);

console.log(UserSlow); //{ fullname: 'Lucas Marrane Siler', isUnderEigthteen: false }

//this way is more faster
const User = MapperGenerator.createStaticMap<IUser, IData>(user)
    .forField('fullname', (from) => `${from?.name} ${from?.surname}`)
    .forField('isUnderEigthteen', (from) => <number>from?.age < 18)
    .map();

console.log(User); //{ fullname: 'Lucas Marrane Siler', isUnderEigthteen: false }

```

#### CreateMap for complex objects

```typescript
...

interface IComplex {
    user: IUser
}

const ComplexObject = Mapper.createMap<IUser, IComplex>()
    .forField<IUser>('user', (from) => ({age: from?.age, name:from?.name , surname: from?.surname}))
    .map(user);

//or
const ComplexObject = Mapper.createMap<IUser, IComplex>()
    .forField('user.age', (from) =>  from?.age)
    .forField('user.name', (from) =>  from?.name)
    .forField('user.surname', (from) =>  from?.surname)
    .map(user);


```

## Other features

It has some utils functions to manipulate objects.

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