# params-mapper

> 将前端页面参数映射到返回给服务端的参数

Latest version **1.1.0** (published 2018-12-03) · ISC license · 0 weekly downloads

## Install

```sh
npm install params-mapper
pnpm add params-mapper
yarn add params-mapper
bun add params-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.1.0 |
| Published | 2018-12-03 |
| First published | 2018-12-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | monsoir |
| Maintainers | monsoir |

## Links

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

## Recent versions

- 1.1.0 (latest) — 2018-12-03
- 1.0.0 — 2018-12-02

## README

# params-mapper

将前端页面参数映射到返回给服务端的参数

Code this:

```js
const paramsMapper = require('params-mapper');
const BaseParamObject = paramsMapper.BaseParamObject;
const autoTransfer = paramsMapper.autoTransfer;

const TransformationPayload = {
    emptyObject: {
      paramKey: 'empty_object',
      alwaysKeep: true,
    },
    emptyObjectNotKeep: {
      paramKey: 'empty_object_not_keep',
    },
    notEmptyObject: {
      paramKey: 'not_empty_object',
    },
  
    emptyArray: {
      paramKey: 'empty_array',
      alwaysKeep: true,
    },
    emptyArrayNotKeep: {
      paramKey: 'empty_array_not_keep',
    },
    notEmptyArray: {
      paramKey: 'not_empty_array',
    },
  };
  
  const payload = {
    emptyObject: {},
    emptyObjectNotKeep: {},
    notEmptyObject: { a: 1 },
  
    emptyArray: [],
    emptyArrayNotKeep: [],
    notEmptyArray: [1, 2, 3],
  };
  
  class A extends BaseParamObject {}
  autoTransfer(TransformationPayload)(A);
  
  // 或者
  // or this:
  const A = autoTransfer(TransformationPayload)(class extends BaseParamObject {});
  
  const temp = new A(payload);
  const params = temp.getParams();
  console.log(params);
```

Result in:

```
{
    "empty_object": {},
    "not_empty_object": {
        "a": 1
    },
    "empty_array": [],
    "not_empty_array": [
        1,
        2,
        3
    ]
}
```

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