9 Star 70 Fork 12

AirPowerTeam/AirPower-Transformer

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Github / Gitee / NPM

🎉 项目介绍

AirPower-Transformer 是一个基于 TypeScript 的数据转换器,提供了从 JSON 对象到 类实例 对象之间互相转换的系列装饰器和方法。

💻 如何安装

npm install @airpower/transformer
# or
yarn add @airpower/transformer
# or
cnpm install @airpower/transformer
# or ...

📖 使用说明

import { IgnorePrefix, Prefix, Transformer, Type } from '@airpower/transformer'

@Prefix('role____')
class Role extends Transformer {
  id!: number
  name!: string
}

@Prefix('user_')
class User extends Transformer {
  id!: number
  name!: string

  @IgnorePrefix()
  age!: number

  @Type(Role)
  role!: Role

  @Type(Role, true)
  roleList: Role[] = []
}

const user = new User()
user.id = 1
user.name = 'Hamm'
user.age = 18

const role = new Role()
role.name = 'Admin'
user.role = role

const roleItem = new Role()
roleItem.name = 'User'
user.roleList.push(roleItem)

const json = user.copy().toJson()
console.warn('json', JSON.stringify(json))

json.name = '???' // 无效
const user2 = User.fromJson(json)
console.warn('user2', user2)

⏰ 欢迎反馈

如有疑问,可以通过本仓库的 Issues 与我们联系,如果你有一些代码贡献,可以通过 Pull Request 将代码贡献,为这个项目添砖加瓦。

如果有更多的需求和建议,欢迎通过本仓库的 Issues 提出,也欢迎加入 QQ群 555156313 与我们及时反馈。

MIT License Copyright (c) 2025 Hamm and his friends. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

🔥🔥🔥AirPower-Transformer 是一个基于 TypeScript 的数据转换器,提供了从 JSON 对象到 类实例 对象之间互相转换的系列装饰器和方法。 展开 收起
取消

发行版

暂无发行版

AirPower-Transformer 开源评估指数

productivity 生产力
niche_creation 创新力
robustness 稳健性
collaboration 协作
contributor 贡献者
software 软件

贡献者 (1)

全部

近期动态

3个月前强推了提交到 main 分支,69f742d...e4f7d83
4个月前同步了仓库
4个月前同步了仓库
4个月前同步了仓库
4个月前评论了任务 #IAQCBT 打包报错
加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
TypeScript
1
https://gitee.com/air-power/AirPower-Transformer.git
git@gitee.com:air-power/AirPower-Transformer.git
air-power
AirPower-Transformer
AirPower-Transformer
main

搜索帮助