json2entity.ts 779 B

1234567891011121314151617181920212223242526
  1. // { type: "num", desc: "查询类型 0:查询全部(不传时默认),1:查询充值可用币种,2:查询提现可用币种", required: true, }
  2. import ncp from "copy-paste";
  3. import { IParamsType } from "./base/interface";
  4. import DocUtil from "./utils/docUtill";
  5. let res = ncp.paste();
  6. console.log(JSON, res);
  7. console.log(JSON.parse(res));
  8. let obj = JSON.parse(res);
  9. let result: Record<string, IParamsType> = {};
  10. Object.entries(obj).forEach(p => {
  11. let required = p != null;
  12. let type = !required ? null : typeof (p[1]) as any;
  13. if (type === "string") {
  14. type = DocUtil.firstUpper(type);
  15. }
  16. result[p[0]] = { required, type, desc: "" };
  17. if (required === true) {
  18. delete result[p[0]].required;
  19. }
  20. })
  21. console.log(333, result);