MCPcopy Create free account
hub / github.com/microsoft/TypeChat / stripNulls

Function stripNulls

typescript/src/typechat.ts:170–193  ·  view source on GitHub ↗

* Recursively delete properties with null values from the given object. This function assumes there are no * circular references in the object. * @param obj The object in which to strip null valued properties.

(obj: any)

Source from the content-addressed store, hash-verified

168 * @param obj The object in which to strip null valued properties.
169 */
170function stripNulls(obj: any) {
171 let keysToDelete: string[] | undefined;
172 for (const k in obj) {
173 const value = obj[k];
174 if (value === null) {
175 (keysToDelete ??= []).push(k);
176 }
177 else {
178 if (Array.isArray(value)) {
179 if (value.some(x => x === null)) {
180 obj[k] = value.filter(x => x !== null);
181 }
182 }
183 if (typeof value === "object") {
184 stripNulls(value);
185 }
186 }
187 }
188 if (keysToDelete) {
189 for (const k of keysToDelete) {
190 delete obj[k];
191 }
192 }
193}

Callers 1

translateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…