@itrocks/data-to-object 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/cjs/data-to-object.js +11 -4
- package/package.json +2 -1
package/cjs/data-to-object.js
CHANGED
|
@@ -2,17 +2,24 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.dataToObject = dataToObject;
|
|
4
4
|
const reflect_1 = require("@itrocks/reflect");
|
|
5
|
+
const rename_1 = require("@itrocks/rename");
|
|
5
6
|
const transformer_1 = require("@itrocks/transformer");
|
|
6
7
|
const transformer_2 = require("@itrocks/transformer");
|
|
7
8
|
async function dataToObject(object, data) {
|
|
8
9
|
const properties = new reflect_1.ReflectClass(object).propertyNames;
|
|
9
|
-
for (
|
|
10
|
-
if (
|
|
10
|
+
for (let fieldName in data) {
|
|
11
|
+
if (fieldName.endsWith('_id')) {
|
|
12
|
+
fieldName = fieldName.slice(0, -3);
|
|
13
|
+
if (fieldName in data)
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
const propertyName = (0, rename_1.toProperty)(fieldName);
|
|
17
|
+
if (!properties.includes(propertyName))
|
|
11
18
|
continue;
|
|
12
|
-
const value = await (0, transformer_1.applyTransformer)(data[
|
|
19
|
+
const value = await (0, transformer_1.applyTransformer)(data[fieldName], object, propertyName, transformer_2.HTML, transformer_2.INPUT, data);
|
|
13
20
|
if (value === transformer_2.IGNORE)
|
|
14
21
|
continue;
|
|
15
|
-
object[
|
|
22
|
+
object[propertyName] = value;
|
|
16
23
|
}
|
|
17
24
|
}
|
|
18
25
|
//# sourceMappingURL=data-to-object.js.map
|
package/package.json
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
},
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@itrocks/reflect": "latest",
|
|
8
|
+
"@itrocks/rename": "latest",
|
|
8
9
|
"@itrocks/request-response": "latest",
|
|
9
10
|
"@itrocks/transformer": "latest"
|
|
10
11
|
},
|
|
@@ -51,5 +52,5 @@
|
|
|
51
52
|
"build": "tsc"
|
|
52
53
|
},
|
|
53
54
|
"types": "./cjs/data-to-object.d.ts",
|
|
54
|
-
"version": "0.0.
|
|
55
|
+
"version": "0.0.4"
|
|
55
56
|
}
|