# re-mapper

> JavaScript object mapper

Latest version **1.0.1** (published 2016-12-27) · MIT license · 0 weekly downloads

## Install

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

## 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.0.1 |
| Published | 2016-12-27 |
| First published | 2016-12-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=6.0.0 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | socsieng@gmail.com |
| Maintainers | socsieng |
| Keywords | map, mapper, json, sql |

## Links

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

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.1 (latest) — 2016-12-27
- 1.0.0 — 2016-12-26
- 0.0.2 — 2016-12-25
- 0.0.1 — 2016-12-24

## README

# ReMapper

[![Build Status](https://travis-ci.org/socsieng/re-mapper.svg?branch=master)](https://travis-ci.org/socsieng/re-mapper)
[![Coverage Status](https://coveralls.io/repos/github/socsieng/re-mapper/badge.svg?branch=master)](https://coveralls.io/github/socsieng/re-mapper?branch=master)

Remapper maps one object into another using a mapping configuration overrides. By default, all properties from the source object will be remapped as-is to the destination object unless, an _override_ is provided.

It was created to help with mapping between JavaScript objects and sql/relation database models.

## Usage

Basic mapping example: 

```js
import ReMapper from 're-mapper';
const mapper = new ReMapper({
  'firstName': 'first_name',
  'lastName': 'last_name',
});

const source = {
  id: 1,
  firstName: 'John',
  lastName: 'Citizen',
  email: 'john@citizen.com'
};

const mapped = mapper.map(source);

// mapped:
// {
//   id: 1,
//   first_name: 'John',
//   last_name: 'Citizen',
//   email: 'john@citizen.com'
// }
```

Array mapping example:

```js
const sourceList = [
  {
    id: 1,
    firstName: 'John',
    lastName: 'Citizen',
    email: 'john@citizen.com'
  },
  {
    id: 2,
    firstName: 'Jane',
    lastName: 'Doe',
    email: 'jane@doe.com'
  }
];

const mappedList = sourceList.map(mapper.map);
```

The reverse mapping is also available with the `reversMap` method which inverts the mapping definition.

Example:

```js
import ReMapper from 're-mapper';
const mapper = new ReMapper({
  'firstName': 'first_name',
  'lastName': 'last_name',
});

const mapped = {
  id: 1,
  first_name: 'John',
  last_name: 'Citizen',
  email: 'john@citizen.com'
};

const unmapped = mapper.reverseMap(source);

// unmapped:
// {
//   id: 1,
//   firstName: 'John',
//   lastName: 'Citizen',
//   email: 'john@citizen.com'
// }
```

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