# schema-exchanger

> Move data schema to another data schema

Latest version **1.4.7** (published 2019-12-29) · SEE LICENSE IN LICENSE license · 0 weekly downloads

## Install

```sh
npm install schema-exchanger
pnpm add schema-exchanger
yarn add schema-exchanger
bun add schema-exchanger
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.4.7 |
| Published | 2019-12-29 |
| First published | 2019-09-08 |
| Weekly downloads | 0 |
| License | SEE LICENSE IN LICENSE |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 31.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Vovstradamus |
| Maintainers | vovastradamus |

## Links

- npm: https://www.npmjs.com/package/schema-exchanger
- Homepage: https://github.com/vovastradamus/schema-exchanger
- npm.io page: https://npm.io/package/schema-exchanger

## Recent versions

- 1.4.7 (latest) — 2019-12-29
- 1.4.6 — 2019-12-04
- 1.4.5 — 2019-12-04
- 1.4.4 — 2019-09-18
- 1.4.3 — 2019-09-18
- 1.4.2 — 2019-09-18
- 1.4.1 — 2019-09-17
- 1.4.0 — 2019-09-17
- 1.3.2 — 2019-09-16
- 1.3.1 — 2019-09-10
- 1.3.0 — 2019-09-10
- 1.2.0 — 2019-09-10
- 1.1.1 — 2019-09-09
- 1.1.0 — 2019-09-09
- 1.0.0 — 2019-09-08

## README

# schema-exchanger

The lib for moving some data scheme to another data scheme

example

```javascript
class LocalPet extends Exchanger {
  static get schema() {
    return {
      name: { key: "name" }
    }
  }
}

class OtherPet extends Exchanger {
  static get schema() {
    return {
      name: { key: "nickname" }
    }
  }
}

class LocalSchema extends Exchanger {
  static get schema() {
    return {
      id: { key: "id" },
      user: { key: "user", type: LocalUser },
      pets: { key: "pets", type: [LocalPet] }
    }
  }
}

class OtherSchema extends Exchanger {
  static get schema() {
    return {
      id: { key: "uuid" },
      user: { key: "userData", type: OtherUser },
      pets: { key: "childs", type: [OtherPet] }
    }
  }
}

const SomeData = {
  id: 123,
  user: { id: 123, name: "name" },
  pets: [{ name: "Sparky" }]
}

const localObj = LocalSchema.fromJson(LocalData)
const otherObj = OtherSchema.fromExchanger(localObj)

otherObj.toJSON()

/* 
expected output object
{
  uuid: 123,
  userData: {
    uuid: 123,
    title: "name"
  },
  childs: [
    {
      nickname: "Sparky"
    }
  ]
} 
*/
```

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