@airpower/transformer 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <p align="center">
2
- <img width="300" src="assets/airpower-bg.svg"/>
2
+ <img width="300" src="./assets/airpower-bg.svg"/>
3
3
  </p>
4
4
 
5
5
  <p align="center">
package/dist/main.js CHANGED
@@ -139,7 +139,7 @@ class Transformer {
139
139
  */
140
140
  static fromJson(json = {}) {
141
141
  const instance = new this();
142
- return Transformer.parse(instance, json);
142
+ return Transformer.parse(json, instance);
143
143
  }
144
144
  /**
145
145
  * ### 从 `JSON` 数组转换到当前类的对象数组
@@ -151,11 +151,11 @@ class Transformer {
151
151
  if (Array.isArray(jsonArray)) {
152
152
  for (let i = 0; i < jsonArray.length; i += 1) {
153
153
  const instance = new this();
154
- instanceList.push(Transformer.parse(instance, jsonArray[i]));
154
+ instanceList.push(Transformer.parse(jsonArray[i], instance));
155
155
  }
156
156
  } else {
157
157
  const instance = new this();
158
- instanceList.push(Transformer.parse(instance, jsonArray));
158
+ instanceList.push(Transformer.parse(jsonArray, instance));
159
159
  }
160
160
  return instanceList;
161
161
  }
@@ -173,10 +173,10 @@ class Transformer {
173
173
  /**
174
174
  * ### 转换 `JSON` 为实体
175
175
  * 会自动进行数据别名转换
176
- * @param instance 实体
177
176
  * @param json `JSON`
177
+ * @param instance 实体
178
178
  */
179
- static parse(instance, json = {}) {
179
+ static parse(json = {}, instance) {
180
180
  const fieldList = Object.keys(instance);
181
181
  for (const field of fieldList) {
182
182
  const jsonKey = this.getJsonKey(instance, field);
@@ -199,7 +199,7 @@ class Transformer {
199
199
  if (typeof fieldData === "object" && Array.isArray(fieldData)) {
200
200
  for (let i = 0; i < fieldData.length; i += 1) {
201
201
  if (FieldTypeClass) {
202
- fieldValueList[i] = this.parse(new FieldTypeClass(), fieldData[i]);
202
+ fieldValueList[i] = this.parse(fieldData[i], new FieldTypeClass());
203
203
  }
204
204
  }
205
205
  }
@@ -223,7 +223,7 @@ class Transformer {
223
223
  instance[field] = !!fieldData;
224
224
  break;
225
225
  default:
226
- instance[field] = this.parse(new FieldTypeClass(), fieldData);
226
+ instance[field] = this.parse(fieldData, new FieldTypeClass());
227
227
  }
228
228
  }
229
229
  for (const fieldKey of fieldList) {
@@ -25,10 +25,10 @@ export declare class Transformer {
25
25
  /**
26
26
  * ### 转换 `JSON` 为实体
27
27
  * 会自动进行数据别名转换
28
- * @param instance 实体
29
28
  * @param json `JSON`
29
+ * @param instance 实体
30
30
  */
31
- private static parse;
31
+ static parse<T extends Transformer>(json: IJson | undefined, instance: T): T;
32
32
  /**
33
33
  * ### 获取 JSON 的 key
34
34
  * @param instance 目标实例
@@ -0,0 +1,2 @@
1
+ declare const _default: import('vite').UserConfig;
2
+ export default _default;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@airpower/transformer",
3
3
  "type": "module",
4
- "version": "0.0.2",
4
+ "version": "0.0.4",
5
5
  "description": "AirPower-Transformer 是一个基于 TypeScript 的数据转换器,提供了从 JSON 对象到 类实例 对象之间互相转换的系列装饰器和方法。",
6
6
  "author": {
7
7
  "name": "Hamm",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes