# reshaper

> Reshape JavaScript data structures to match a schema

Latest version **0.3.1** (published 2016-06-02) · MIT license · 0 weekly downloads

## Install

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

## 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.3.1 |
| Published | 2016-06-02 |
| First published | 2016-04-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 104 |
| Author | Joel Auterson |
| Maintainers | joelotter |

## Links

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

## Recent versions

- 0.3.1 (latest) — 2016-06-02
- 0.3.0 — 2016-05-30
- 0.2.0 — 2016-05-10
- 0.1.0 — 2016-04-29

## README

# Reshaper

[![Build Status](https://travis-ci.org/JoelOtter/reshaper.svg?branch=master)](https://travis-ci.org/JoelOtter/reshaper) [![Coverage Status](https://coveralls.io/repos/github/JoelOtter/reshaper/badge.svg?branch=master)](https://coveralls.io/github/JoelOtter/reshaper?branch=master) [![](https://img.shields.io/npm/v/reshaper.svg)](https://www.npmjs.com/package/reshaper)

Reshaper is a JavaScript library which can automatically restructure JavaScript objects to match a provided schema. It also provides users with some manual control, by way of a 'hint' system.

To see some interactive examples, check out this [Kajero notebook](http://www.joelotter.com/reshaper).

## Installation

`npm install reshaper`

## Usage

#### `reshaper(data, schema, [hint])`

- `data`: The JavaScript data structure to be reshaped.
- `schema`: The structure we want our reshaped data to match.
- `hint`: _(Optional)_ The name of an object key, given as a 'hint'. Keys matching this hint will be preferred. An array of keys can also be provided if desired.

## Examples

```javascript
var reshaper = require('reshaper');

var peopleData = [
    {
        name: 'Joel',
        info: {
            age: 22,
            height: 1.9,
            middleName: 'Robert',
            lastName: 'Auterson'
        }
    },
    {
        name: 'Jake',
        info: {
            age: 24,
            height: 1.85,
            middleName: 'Wild',
            lastName: 'Hall'
        }
    }
];

var schema = ['String'];

reshaper(peopleData, schema);
// => ['Joel', 'Jake']

// We can give a 'hint', to say lastName is what we want.
reshaper(peopleData, schema, 'lastName');
// => ['Auterson', 'Hall']

// Object keys get used as hints
var schema = {
    age: ['Number'],
    height: ['Number']
};

reshaper(peopleData, schema);
/* =>
{
    age: [22, 24],
    height: [1.9, 1.85]
}
*/

```

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