MCPcopy Create free account
hub / github.com/mikro-orm/mikro-orm / dropUndefinedProperties

Method dropUndefinedProperties

packages/core/src/utils/Utils.ts:204–227  ·  view source on GitHub ↗

* Removes `undefined` properties (recursively) so they are not saved as nulls

(o: any, value?: null, visited: Set<unknown> = new Set())

Source from the content-addressed store, hash-verified

202 * Removes `undefined` properties (recursively) so they are not saved as nulls
203 */
204 static dropUndefinedProperties(o: any, value?: null, visited: Set<unknown> = new Set()): void {
205 if (Array.isArray(o)) {
206 for (const item of o) {
207 Utils.dropUndefinedProperties(item, value, visited);
208 }
209
210 return;
211 }
212
213 if (!Utils.isPlainObject(o) || visited.has(o)) {
214 return;
215 }
216
217 visited.add(o);
218
219 for (const key of Object.keys(o)) {
220 if (o[key] === value) {
221 delete o[key];
222 continue;
223 }
224
225 Utils.dropUndefinedProperties(o[key], value, visited);
226 }
227 }
228
229 /**
230 * Returns the number of properties on `obj`. This is 20x faster than Object.keys(obj).length.

Callers 8

executeQueryMethod · 0.80
cloneEmbeddableMethod · 0.80
logMethod · 0.80
serializeMethod · 0.80
processWhereMethod · 0.80
createMethod · 0.80
mergePrimaryConditionMethod · 0.80
GH4428.test.tsFile · 0.80

Calls 4

isPlainObjectMethod · 0.80
addMethod · 0.80
hasMethod · 0.65
keysMethod · 0.45

Tested by

no test coverage detected