@retroachievements/api 2.9.0 → 2.9.1
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/api.cjs +1 -1
- package/dist/api.cjs.map +1 -1
- package/dist/api.modern.js +1 -1
- package/dist/api.modern.js.map +1 -1
- package/dist/api.module.js +1 -1
- package/dist/api.module.js.map +1 -1
- package/dist/api.umd.js +1 -1
- package/dist/api.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/utils/internal/serializeProperties.test.ts +30 -24
- package/src/utils/internal/serializeProperties.ts +5 -1
|
@@ -114,28 +114,34 @@ describe("Util: serializeProperties", () => {
|
|
|
114
114
|
});
|
|
115
115
|
});
|
|
116
116
|
|
|
117
|
-
it(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
117
|
+
it.each([
|
|
118
|
+
{ hardcoreMode: "0", isCoolGuy: "1" },
|
|
119
|
+
{ hardcoreMode: false, isCoolGuy: true },
|
|
120
|
+
])(
|
|
121
|
+
"can be instructed to map values of certain keys to booleans such as the value '$hardcoreMode' and '$isCoolGuy'",
|
|
122
|
+
({ hardcoreMode, isCoolGuy }) => {
|
|
123
|
+
// ARRANGE
|
|
124
|
+
const originalObject = {
|
|
125
|
+
UserName: "xelnia",
|
|
126
|
+
HardcoreMode: hardcoreMode,
|
|
127
|
+
Metadata: {
|
|
128
|
+
IsCoolGuy: isCoolGuy,
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// ACT
|
|
133
|
+
const sanitizedObject = serializeProperties(originalObject, {
|
|
134
|
+
shouldMapToBooleans: ["HardcoreMode", "IsCoolGuy"],
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// ASSERT
|
|
138
|
+
expect(sanitizedObject).toEqual({
|
|
139
|
+
userName: "xelnia",
|
|
140
|
+
hardcoreMode: false,
|
|
141
|
+
metadata: {
|
|
142
|
+
isCoolGuy: true,
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
);
|
|
141
147
|
});
|
|
@@ -33,7 +33,11 @@ export const serializeProperties = (
|
|
|
33
33
|
if (originalValue === null) {
|
|
34
34
|
sanitizedValue = null;
|
|
35
35
|
} else {
|
|
36
|
-
|
|
36
|
+
const originalValueAsString = String(originalValue);
|
|
37
|
+
sanitizedValue =
|
|
38
|
+
originalValueAsString === "1" || originalValueAsString === "true"
|
|
39
|
+
? true
|
|
40
|
+
: false;
|
|
37
41
|
}
|
|
38
42
|
}
|
|
39
43
|
|