# wrangler-object-mapper

> An object mapper for Node.

Latest version **0.1.2** (published 2017-04-25) · ISC license · 0 weekly downloads

## Install

```sh
npm install wrangler-object-mapper
pnpm add wrangler-object-mapper
yarn add wrangler-object-mapper
bun add wrangler-object-mapper
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2017-04-25 |
| First published | 2017-03-06 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jonathan Hart |
| Maintainers | jonathanhart92 |
| Keywords | node, objects, transform, mapping, schema |

## Links

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

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 0.1.2 (latest) — 2017-04-25
- 0.1.1 — 2017-04-25
- 0.1.0 — 2017-03-06

## README

# Wrangler

A simple Javascript object mapper.

## Why?

Sometimes you receive onjects that don't quite conform to your standards. Maybe it's naming conventions, or a lack of nested properties. Or maybe you need to transform the object's values in some way. Perhaps you need to parse JSON from an API into your own schema.

Wrangler helps you with this. By defining a map and passing an object, Wrangler whips your objects into shape.

## Installation

Just install Wrangler from npm...

    npm install wrangler-object-mapper --save

... and import.
    const Wrangler = require('wrangler-object-mapper')

## Getting Started

Wrangler applies tranformations between a *source* object and a *destination* object. To create a transformation, define a *map*:

    let map = [
        ['sourceProp', 'destProp']
    ]

A map is an array of pairs. The left side is the name of a key inside the source object. The right side is the desired name of the source key value will be mapped to in the destination object.

A function may also be passed to either side of the pair. 

The left side function signature:

    function(source) {}

Where source is the source object. *To pass data from the source to the destination object, you must return a value.*

The right side function signature:

    function(dest, val) {}

Where dest is the destination object and val is the value returned from the source object. You must assign the value to the destination object yourself if using a function.

## Example

    // The source object
    let obj = {
        aPropA: true,
        aPropB: false,
        aPropC: 'FALSE',
        nested: {
            prop: 22
        }
    }

    // Define a map
    let map = [
        // Mapping from flat property name to nested.
        ['aPropA': 'aProp.A'],
        ['aPropB: 'aProp.B'],

        // Mapping from nested property to flat.
        ['nested.prop', 'unnestedNum']

        // Transforming a value and mapping to nested.
        [source => { return !(source.aPropC === 'FASLE')}, 'aProp.C']

        // Transforming value in destination
        ['nested.prop', (dest, val) => { dest['transformed'] == val * 2 }]
    ]

    let result = Atlas.parse(obj, map);

Result:

    {
        aProp: {
            A: true,
            B: false,
            C: false
        },
        unnestedNum: 22,
        transformed: 44
    }

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