@airpower/transformer 0.0.3 → 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/dist/main.js +7 -7
- package/dist/{transformer → src/transformer}/Transformer.d.ts +2 -2
- package/dist/vite.config.d.ts +2 -0
- package/package.json +1 -1
- /package/dist/{decorator → src/decorator}/Alias.d.ts +0 -0
- /package/dist/{decorator → src/decorator}/IgnorePrefix.d.ts +0 -0
- /package/dist/{decorator → src/decorator}/Prefix.d.ts +0 -0
- /package/dist/{decorator → src/decorator}/ToClass.d.ts +0 -0
- /package/dist/{decorator → src/decorator}/ToJson.d.ts +0 -0
- /package/dist/{decorator → src/decorator}/Type.d.ts +0 -0
- /package/dist/{decorator → src/decorator}/index.d.ts +0 -0
- /package/dist/{index.d.ts → src/index.d.ts} +0 -0
- /package/dist/{transformer → src/transformer}/DecoratorUtil.d.ts +0 -0
- /package/dist/{transformer → src/transformer}/IJson.d.ts +0 -0
- /package/dist/{transformer → src/transformer}/ITransformerConstructor.d.ts +0 -0
- /package/dist/{transformer → src/transformer}/index.d.ts +0 -0
- /package/dist/{type → src/type}/type.d.ts +0 -0
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(
|
|
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(
|
|
154
|
+
instanceList.push(Transformer.parse(jsonArray[i], instance));
|
|
155
155
|
}
|
|
156
156
|
} else {
|
|
157
157
|
const instance = new this();
|
|
158
|
-
instanceList.push(Transformer.parse(
|
|
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(
|
|
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()
|
|
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()
|
|
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
|
-
|
|
31
|
+
static parse<T extends Transformer>(json: IJson | undefined, instance: T): T;
|
|
32
32
|
/**
|
|
33
33
|
* ### 获取 JSON 的 key
|
|
34
34
|
* @param instance 目标实例
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|