@hightall/params-mapper
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

params-mapper

⚠️ 请移步到重构后的 params-mapper

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

Install

npm i params-mapper

Code this:

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

// or

import { autoTransfer, BaseParamObject } from 'params-mapper';

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
    ]
}

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.1.00latest

Version History

VersionDownloads (Last 7 Days)Published
1.1.00

Package Sidebar

Install

npm i @hightall/params-mapper

Weekly Downloads

0

Version

1.1.0

License

ISC

Unpacked Size

5.98 kB

Total Files

6

Last publish

Collaborators

  • hightall