s2cfgtojson 2.0.1 → 2.0.2
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/Struct.mts +10 -7
- package/package.json +1 -1
package/Struct.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export type Value = Omit<Struct, "toTs"> | string | boolean | number;
|
|
2
|
+
const defaultEntries = new Set(["_isArray", "_useAsterisk"]);
|
|
2
3
|
type DefaultEntries = { _isArray?: boolean; _useAsterisk?: boolean };
|
|
3
4
|
export type Entries = Record<string | number, Value> & DefaultEntries;
|
|
4
5
|
|
|
@@ -125,13 +126,15 @@ export abstract class Struct<T extends Entries = {}> {
|
|
|
125
126
|
const collect = (struct: Struct) => {
|
|
126
127
|
const obj = {};
|
|
127
128
|
if (struct.entries) {
|
|
128
|
-
Object.entries(struct.entries)
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
129
|
+
Object.entries(struct.entries)
|
|
130
|
+
.filter(([key]) => !defaultEntries.has(key))
|
|
131
|
+
.forEach(([key, value]) => {
|
|
132
|
+
if (value instanceof Struct) {
|
|
133
|
+
obj[key] = collect(value);
|
|
134
|
+
} else {
|
|
135
|
+
obj[key] = value;
|
|
136
|
+
}
|
|
137
|
+
});
|
|
135
138
|
}
|
|
136
139
|
return obj;
|
|
137
140
|
};
|