* 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)
| 168 | * @param obj The object in which to strip null valued properties. |
| 169 | */ |
| 170 | function 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 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…